projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
9745: Load API host and token from crunch-dispatch-slurm config file.
[arvados.git]
/
lib
/
crunchstat
/
crunchstat.go
diff --git
a/lib/crunchstat/crunchstat.go
b/lib/crunchstat/crunchstat.go
index e0ef058835ad6652009e5b2dbb40dbbf7a63da58..fa3cd2c2d273fac1be25302a0bcce21af5a07ee9 100644
(file)
--- a/
lib/crunchstat/crunchstat.go
+++ b/
lib/crunchstat/crunchstat.go
@@
-40,7
+40,7
@@
type Reporter struct {
// Where cgroup accounting files live on this system, e.g.,
// "/sys/fs/cgroup".
// Where cgroup accounting files live on this system, e.g.,
// "/sys/fs/cgroup".
- CgroupRoot
string
+ CgroupRoot string
// Parent cgroup, e.g., "docker".
CgroupParent string
// Parent cgroup, e.g., "docker".
CgroupParent string
@@
-56,7
+56,8
@@
type Reporter struct {
lastDiskSample map[string]ioSample
lastCPUSample cpuSample
lastDiskSample map[string]ioSample
lastCPUSample cpuSample
- done chan struct{}
+ done chan struct{} // closed when we should stop reporting
+ flushed chan struct{} // closed when we have made our last report
}
// Start starts monitoring in a new goroutine, and returns
}
// Start starts monitoring in a new goroutine, and returns
@@
-72,6
+73,7
@@
type Reporter struct {
// Callers should not modify public data fields after calling Start.
func (r *Reporter) Start() {
r.done = make(chan struct{})
// Callers should not modify public data fields after calling Start.
func (r *Reporter) Start() {
r.done = make(chan struct{})
+ r.flushed = make(chan struct{})
go r.run()
}
go r.run()
}
@@
-81,6
+83,7
@@
func (r *Reporter) Start() {
// Nothing will be logged after Stop returns.
func (r *Reporter) Stop() {
close(r.done)
// Nothing will be logged after Stop returns.
func (r *Reporter) Stop() {
close(r.done)
+ <-r.flushed
}
func (r *Reporter) readAllOrWarn(in io.Reader) ([]byte, error) {
}
func (r *Reporter) readAllOrWarn(in io.Reader) ([]byte, error) {
@@
-312,6
+315,9
@@
func (r *Reporter) getCPUCount() int64 {
}
defer cpusetFile.Close()
b, err := r.readAllOrWarn(cpusetFile)
}
defer cpusetFile.Close()
b, err := r.readAllOrWarn(cpusetFile)
+ if err != nil {
+ return 0
+ }
sp := strings.Split(string(b), ",")
cpus := int64(0)
for _, v := range sp {
sp := strings.Split(string(b), ",")
cpus := int64(0)
for _, v := range sp {
@@
-337,12
+343,16
@@
func (r *Reporter) doCPUStats() {
return
}
return
}
- nextSample := cpuSample{true, time.Now(), 0, 0, r.getCPUCount()}
var userTicks, sysTicks int64
fmt.Sscanf(string(b), "user %d\nsystem %d", &userTicks, &sysTicks)
userHz := float64(C.sysconf(C._SC_CLK_TCK))
var userTicks, sysTicks int64
fmt.Sscanf(string(b), "user %d\nsystem %d", &userTicks, &sysTicks)
userHz := float64(C.sysconf(C._SC_CLK_TCK))
- nextSample.user = float64(userTicks) / userHz
- nextSample.sys = float64(sysTicks) / userHz
+ nextSample := cpuSample{
+ hasData: true,
+ sampleTime: time.Now(),
+ user: float64(userTicks) / userHz,
+ sys: float64(sysTicks) / userHz,
+ cpus: r.getCPUCount(),
+ }
delta := ""
if r.lastCPUSample.hasData {
delta := ""
if r.lastCPUSample.hasData {
@@
-356,9
+366,11
@@
func (r *Reporter) doCPUStats() {
r.lastCPUSample = nextSample
}
r.lastCPUSample = nextSample
}
-// Report stats periodically until
r.done indicates someone called
-// Stop.
+// Report stats periodically until
we learn (via r.done) that someone
+//
called
Stop.
func (r *Reporter) run() {
func (r *Reporter) run() {
+ defer close(r.flushed)
+
r.reportedStatFile = make(map[string]string)
if !r.waitForCIDFile() || !r.waitForCgroup() {
r.reportedStatFile = make(map[string]string)
if !r.waitForCIDFile() || !r.waitForCgroup() {
@@
-383,7
+395,7
@@
func (r *Reporter) run() {
}
// If CID is empty, wait for it to appear in CIDFile. Return true if
}
// If CID is empty, wait for it to appear in CIDFile. Return true if
-// we get it before
r.done indicates
someone called Stop.
+// we get it before
we learn (via r.done) that
someone called Stop.
func (r *Reporter) waitForCIDFile() bool {
if r.CID != "" || r.CIDFile == "" {
return true
func (r *Reporter) waitForCIDFile() bool {
if r.CID != "" || r.CIDFile == "" {
return true