cmd/stress: print elapsed time, percentage failure
Add more information to the output of stress.
Prior to this change, stress printed lines like:
8288 runs so far, 2 failures
After this change, stress prints lines like:
1m5s: 8288 runs so far, 2 failures (0.02%)
I've found the timing information to be helpful in that it helps
me anticipate how long a new stress run might take to reach some
number of iterations I've deemed necessary to convince myself
that a bug has been fixed.
I've found the % failure to be helpful when there are multiple failures;
I can use them to gauge whether I've made the test more reliable.
I've been using this patch for a while and found it helpful
on numerous occasions, so I figured I should upstream it.
Change-Id: If0c9b74c30353898bacb38a81f27796f74eb4064
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258299
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/cmd/stress/stress.go b/cmd/stress/stress.go
index afcfa10..e127735 100644
--- a/cmd/stress/stress.go
+++ b/cmd/stress/stress.go
@@ -113,6 +113,7 @@
}()
}
runs, fails := 0, 0
+ start := time.Now()
ticker := time.NewTicker(5 * time.Second).C
for {
select {
@@ -137,7 +138,12 @@
fmt.Printf("\n%s\n%s\n", f.Name(), out)
}
case <-ticker:
- fmt.Printf("%v runs so far, %v failures\n", runs, fails)
+ elapsed := time.Since(start).Truncate(time.Second)
+ var pct string
+ if fails > 0 {
+ pct = fmt.Sprintf(" (%0.2f%%)", 100.0*float64(fails)/float64(runs))
+ }
+ fmt.Printf("%v: %v runs so far, %v failures%s\n", elapsed, runs, fails, pct)
}
}
}