Skip to content

Commit 5831832

Browse files
committed
sweet/benchmarks/go-build: build runtime before running benchmark
So we don't consider time building runtime when comparing go build time. Instead of using go build -a to rebuild everything, we'll use a new temporary build cache directory so that nothing is cached. Then we'll build the runtime using that cache directory to make sure that it is cached. Then the benchmark run build, without -a will build everything except for the runtime and its dependencies, which have already been cached, and that time will be used in the benchmark result. Change-Id: I2753fc8d8438be1d437f7c65077ea22760a34b54 Reviewed-on: https://go-review.googlesource.com/c/benchmarks/+/688915 Reviewed-by: Michael Matloob <matloob@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
1 parent 5aff100 commit 5831832

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

sweet/benchmarks/go-build/main.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,15 @@ func run(pkgPath string) error {
5858
if err := os.MkdirAll(tmpResultsDir(), 0777); err != nil {
5959
return err
6060
}
61+
tmpCacheDir, err := os.MkdirTemp(tmpDir, "cache")
62+
if err != nil {
63+
return err
64+
}
65+
defer os.RemoveAll(tmpCacheDir)
6166

6267
name := "GoBuild" + strings.Title(filepath.Base(pkgPath))
6368

64-
cmdArgs := []string{goTool, "build", "-a"}
69+
cmdArgs := []string{goTool, "build"}
6570

6671
// Build a command comprised of this binary to pass to -toolexec.
6772
selfPath, err := filepath.Abs(os.Args[0])
@@ -103,9 +108,19 @@ func run(pkgPath string) error {
103108

104109
baseCmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
105110
baseCmd.Dir = pkgPath
106-
baseCmd.Env = common.NewEnvFromEnviron().MustSet("GOROOT=" + filepath.Dir(filepath.Dir(goTool))).Collapse()
111+
baseCmd.Env = common.NewEnvFromEnviron().MustSet("GOCACHE="+tmpCacheDir, "GOROOT="+filepath.Dir(filepath.Dir(goTool))).Collapse()
107112
baseCmd.Stdout = os.Stderr // Redirect all tool output to stderr.
108113
baseCmd.Stderr = os.Stderr
114+
115+
buildRuntime := exec.Command(goTool, "build", "runtime")
116+
buildRuntime.Dir = pkgPath
117+
buildRuntime.Env = baseCmd.Env
118+
buildRuntime.Stdout = os.Stderr
119+
buildRuntime.Stderr = os.Stderr
120+
if err := buildRuntime.Run(); err != nil {
121+
return err
122+
}
123+
109124
cmd, err := cgroups.WrapCommand(baseCmd, "test.scope")
110125
if err != nil {
111126
return err

0 commit comments

Comments
 (0)