sweet: add GOMAXPROCS suffix to benchmark names

This change adds the GOMAXPROCS suffix to benchmark names the same way
that `go test` does.

Change-Id: I3ae168620de716c0aa8b642d099ba5308c54f48b
Reviewed-on: https://go-review.googlesource.com/c/benchmarks/+/580837
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
diff --git a/sweet/benchmarks/etcd/main.go b/sweet/benchmarks/etcd/main.go
index 2625440..a20a0b4 100644
--- a/sweet/benchmarks/etcd/main.go
+++ b/sweet/benchmarks/etcd/main.go
@@ -45,6 +45,7 @@
 	isProfiling  bool
 	short        bool
 	procsPerInst int
+	gomaxprocs   int
 	bench        *benchmark
 }
 
@@ -68,6 +69,7 @@
 	}
 	runtime.GOMAXPROCS(procsPerInst)
 	cliCfg.procsPerInst = procsPerInst
+	cliCfg.gomaxprocs = procs
 }
 
 type etcdInstance struct {
@@ -357,6 +359,7 @@
 		driver.DoCoreDump(true),
 		driver.BenchmarkPID(instances[0].cmd.Process.Pid),
 		driver.DoPerf(true),
+		driver.WithGOMAXPROCS(cfg.gomaxprocs),
 	}
 	return driver.RunBenchmark(cfg.bench.reportName, func(d *driver.B) error {
 		// Set up diagnostics.
diff --git a/sweet/benchmarks/gvisor/http_server.go b/sweet/benchmarks/gvisor/http_server.go
index 1c9b91e..1115237 100644
--- a/sweet/benchmarks/gvisor/http_server.go
+++ b/sweet/benchmarks/gvisor/http_server.go
@@ -159,7 +159,7 @@
 			return fmt.Errorf("server startup timed out")
 		}
 		return nil
-	}, driver.DoTime(true))
+	}, driver.DoTime(true), driver.WithGOMAXPROCS(procs))
 
 	workers := make([]pool.Worker, 0, clients)
 	for i := 0; i < clients; i++ {
@@ -202,5 +202,5 @@
 		d.Ops(len(latencies))
 		d.Report(driver.StatTime, uint64((int(b.duration)*clients)/len(latencies)))
 		return nil
-	}, driver.DoTime(true), driver.DoAvgRSS(srvCmd.RSSFunc()))
+	}, driver.DoTime(true), driver.DoAvgRSS(srvCmd.RSSFunc()), driver.WithGOMAXPROCS(procs))
 }
diff --git a/sweet/benchmarks/internal/driver/driver.go b/sweet/benchmarks/internal/driver/driver.go
index 36d3ed7..9a7d1b4 100644
--- a/sweet/benchmarks/internal/driver/driver.go
+++ b/sweet/benchmarks/internal/driver/driver.go
@@ -12,6 +12,7 @@
 	"os"
 	"os/exec"
 	"path/filepath"
+	"runtime"
 	"runtime/pprof"
 	"runtime/trace"
 	"sort"
@@ -129,6 +130,12 @@
 	}
 }
 
+func WithGOMAXPROCS(procs int) RunOption {
+	return func(b *B) {
+		b.gomaxprocs = procs
+	}
+}
+
 var InProcessMeasurementOptions = []RunOption{
 	DoTime(true),
 	DoPeakRSS(true),
@@ -151,6 +158,7 @@
 	doPeakRSS     bool
 	doPeakVM      bool
 	doCoreDump    bool
+	gomaxprocs    int
 	collectDiag   map[diagnostics.Type]bool
 	rssFunc       func() (uint64, error)
 	statsMu       sync.Mutex
@@ -372,7 +380,11 @@
 	if b.resultsWriter != nil {
 		out = b.resultsWriter
 	}
-	fmt.Fprintf(out, "Benchmark%s %d", b.name, b.ops)
+	suffix := ""
+	if b.gomaxprocs > 1 {
+		suffix = fmt.Sprintf("-%d", b.gomaxprocs)
+	}
+	fmt.Fprintf(out, "Benchmark%s%s %d", b.name, suffix, b.ops)
 	for _, name := range names {
 		value := b.stats[name]
 		if value != 0 {
@@ -442,6 +454,11 @@
 		opt(b)
 	}
 
+	// Make sure gomaxprocs is set.
+	if b.gomaxprocs == 0 {
+		b.gomaxprocs = runtime.GOMAXPROCS(-1)
+	}
+
 	// Start the RSS sampler and start the timer.
 	stop := b.startRSSSampler()
 
diff --git a/sweet/benchmarks/tile38/main.go b/sweet/benchmarks/tile38/main.go
index f65870c..3719d75 100644
--- a/sweet/benchmarks/tile38/main.go
+++ b/sweet/benchmarks/tile38/main.go
@@ -37,6 +37,7 @@
 	dataPath    string
 	tmpDir      string
 	serverProcs int
+	gomaxprocs  int
 	isProfiling bool
 	short       bool
 }
@@ -82,6 +83,7 @@
 	}
 	runtime.GOMAXPROCS(clientProcs)
 	cliCfg.serverProcs = serverProcs
+	cliCfg.gomaxprocs = procs
 }
 
 func doWithinCircle(c redis.Conn, lat, lon float64) error {
@@ -328,6 +330,7 @@
 		driver.DoCoreDump(true),
 		driver.BenchmarkPID(srvCmd.Process.Pid),
 		driver.DoPerf(true),
+		driver.WithGOMAXPROCS(cfg.gomaxprocs),
 	}
 	iters := 40 * 50000
 	if cfg.short {