X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/3a0aa1db801154916f50b1b299d5100945a3e1df..142a3c236c911731c337e1f9ee06038e6388e87b:/lib/crunchstat/crunchstat.go diff --git a/lib/crunchstat/crunchstat.go b/lib/crunchstat/crunchstat.go index 03cfa7d3ef..fa3cd2c2d2 100644 --- a/lib/crunchstat/crunchstat.go +++ b/lib/crunchstat/crunchstat.go @@ -56,7 +56,8 @@ type Reporter struct { 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 @@ -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{}) + r.flushed = make(chan struct{}) 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) + <-r.flushed } func (r *Reporter) readAllOrWarn(in io.Reader) ([]byte, error) { @@ -366,6 +369,8 @@ func (r *Reporter) doCPUStats() { // Report stats periodically until we learn (via r.done) that someone // called Stop. func (r *Reporter) run() { + defer close(r.flushed) + r.reportedStatFile = make(map[string]string) if !r.waitForCIDFile() || !r.waitForCgroup() {