Update prebuilts to go1.8rc1 ab/3640477
Bug: 32982374
Test: m -j blueprint_tools
Change-Id: Ife36ed9cf5b2617ccc8fdf0fdd178d19378546cd
diff --git a/src/testing/benchmark.go b/src/testing/benchmark.go
index 5d58b85..c033ce5 100644
--- a/src/testing/benchmark.go
+++ b/src/testing/benchmark.go
@@ -7,6 +7,7 @@
import (
"flag"
"fmt"
+ "internal/race"
"os"
"runtime"
"sync"
@@ -14,8 +15,8 @@
"time"
)
-var matchBenchmarks = flag.String("test.bench", "", "regular expression per path component to select benchmarks to run")
-var benchTime = flag.Duration("test.benchtime", 1*time.Second, "approximate run time for each benchmark")
+var matchBenchmarks = flag.String("test.bench", "", "run only benchmarks matching `regexp`")
+var benchTime = flag.Duration("test.benchtime", 1*time.Second, "run each benchmark for duration `d`")
var benchmarkMemory = flag.Bool("test.benchmem", false, "print memory allocations for benchmarks")
// Global lock to ensure only one benchmark runs at a time.
@@ -56,7 +57,6 @@
missingBytes bool // one of the subbenchmarks does not have bytes set.
timerOn bool
showAllocResult bool
- hasSub bool
result BenchmarkResult
parallelism int // RunParallel creates parallelism*GOMAXPROCS goroutines
// The initial states of memStats.Mallocs and memStats.TotalAlloc.
@@ -132,6 +132,7 @@
// Try to get a comparable environment for each run
// by clearing garbage from previous runs.
runtime.GC()
+ b.raceErrors = -race.Errors()
b.N = n
b.parallelism = 1
b.ResetTimer()
@@ -140,6 +141,10 @@
b.StopTimer()
b.previousN = n
b.previousDuration = b.duration
+ b.raceErrors += race.Errors()
+ if b.raceErrors > 0 {
+ b.Errorf("race detected during execution of benchmark")
+ }
}
func min(x, y int) int {
@@ -263,10 +268,9 @@
for n := 1; !b.failed && b.duration < d && n < 1e9; {
last := n
// Predict required iterations.
- if b.nsPerOp() == 0 {
- n = 1e9
- } else {
- n = int(d.Nanoseconds() / b.nsPerOp())
+ n = int(d.Nanoseconds())
+ if nsop := b.nsPerOp(); nsop != 0 {
+ n /= int(nsop)
}
// Run more iterations than we think we'll need (1.2x).
// Don't grow too fast in case we had timing errors previously.
@@ -359,10 +363,10 @@
// An internal function but exported because it is cross-package; part of the implementation
// of the "go test" command.
func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark) {
- runBenchmarksInternal(matchString, benchmarks)
+ runBenchmarks(matchString, benchmarks)
}
-func runBenchmarksInternal(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark) bool {
+func runBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark) bool {
// If no flag was specified, don't run benchmarks.
if len(*matchBenchmarks) == 0 {
return true