Skip to content

Commit 1d23d6b

Browse files
committed
sweet: save build logs to .build.logs in result dir
This CL saves stdout and stderr during build to *.build.logs in the result dir. Change-Id: Ieb8c310a7cc62bb7210e2b8f5c9c29d561b8d401 Reviewed-on: https://go-review.googlesource.com/c/benchmarks/+/709815 Reviewed-by: Michael Knyszek <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 042410d commit 1d23d6b

File tree

11 files changed

+44
-21
lines changed

11 files changed

+44
-21
lines changed

sweet/cmd/sweet/benchmark.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,26 @@ func (b *benchmark) execute(cfgs []*common.Config, r *runCfg) error {
319319
goflags += fmt.Sprintf("-pgo=%s", pgo)
320320
cfg.BuildEnv.Env = cfg.BuildEnv.MustSet("GOFLAGS=" + goflags)
321321

322+
// Create a build log file.
323+
buildLogPath := filepath.Join(resultsDir, fmt.Sprintf("%s.build.log", cfg.Name))
324+
buildLog, err := os.Create(buildLogPath)
325+
if err != nil {
326+
return fmt.Errorf("create %s build log file for %s: %v", b.name, cfg.Name, err)
327+
}
328+
322329
// Build the benchmark (application and any other necessary components).
323330
bcfg := common.BuildConfig{
324331
BinDir: binDir,
325332
SrcDir: srcDir,
326333
BenchDir: benchDir,
327334
Short: r.short,
335+
BuildLog: buildLog,
328336
}
329337
if err := b.harness.Build(cfg, &bcfg); err != nil {
338+
buildLog.Close()
330339
return fmt.Errorf("build %s for %s: %v", b.name, cfg.Name, err)
331340
}
341+
buildLog.Close()
332342

333343
// Generate any args to funnel through to benchmarks.
334344
args := []string{}

sweet/common/config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package common
77
import (
88
"bytes"
99
"fmt"
10+
"io"
1011
"path/filepath"
1112

1213
"github.com/BurntSushi/toml"
@@ -81,12 +82,13 @@ type PGOConfig struct {
8182
BuildEnv ConfigEnv `toml:"envbuild"`
8283
}
8384

84-
func (c *Config) GoTool() *Go {
85+
func (c *Config) GoTool(buildLog io.Writer) *Go {
8586
return &Go{
8687
Tool: filepath.Join(c.GoRoot, "bin", "go"),
8788
// Update the GOROOT so the wrong one doesn't propagate from
8889
// the environment.
89-
Env: c.BuildEnv.Env.MustSet("GOROOT=" + c.GoRoot),
90+
Env: c.BuildEnv.Env.MustSet("GOROOT=" + c.GoRoot),
91+
BuildLog: buildLog,
9092
}
9193
}
9294

sweet/common/gotool.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package common
66

77
import (
88
"fmt"
9+
"io"
910
"os"
1011
"os/exec"
1112
"path/filepath"
@@ -17,6 +18,7 @@ type Go struct {
1718
Tool string
1819
Env *Env
1920
PassOutput bool
21+
BuildLog io.Writer
2022
}
2123

2224
func SystemGoTool() (*Go, error) {
@@ -39,9 +41,12 @@ func (g *Go) Do(dir string, args ...string) error {
3941
if g.PassOutput {
4042
cmd.Stdout = os.Stdout
4143
cmd.Stderr = os.Stderr
44+
} else if g.BuildLog != nil {
45+
cmd.Stderr = g.BuildLog
46+
cmd.Stdout = g.BuildLog
4247
}
4348
log.TraceCommand(cmd, false)
44-
if g.PassOutput {
49+
if g.PassOutput || g.BuildLog != nil {
4550
return cmd.Run()
4651
}
4752
// Use cmd.Output to get an ExitError with Stderr populated.

sweet/common/harness.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
package common
66

7-
import "os"
7+
import (
8+
"io"
9+
"os"
10+
)
811

912
type GetConfig struct {
1013
// SrcDir is the path to the directory that the harness should write
@@ -40,6 +43,9 @@ type BuildConfig struct {
4043
// for testing. Guaranteed to be the same as GetConfig.Short and
4144
// RunConfig.Short.
4245
Short bool
46+
47+
// BuildLog is used to pass the build log to a file.
48+
BuildLog io.Writer
4349
}
4450

4551
type RunConfig struct {

sweet/harnesses/cockroachdb.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (h CockroachDB) Build(cfg *common.Config, bcfg *common.BuildConfig) error {
4747
// Install bazel via bazelisk which is used by `dev`. Install it in the
4848
// BinDir to ensure we get a new copy every run and avoid reuse. This is
4949
// done by setting the `GOBIN` env var for the `go install` cmd.
50-
goInstall := cfg.GoTool()
50+
goInstall := cfg.GoTool(bcfg.BuildLog)
5151
goInstall.Env = goInstall.Env.MustSet(fmt.Sprintf("GOBIN=%s", bcfg.BinDir))
5252
if err := goInstall.Do(bcfg.BinDir, "install", "github.com/bazelbuild/bazelisk@latest"); err != nil {
5353
return fmt.Errorf("error building bazelisk: %v", err)
@@ -115,7 +115,7 @@ func (h CockroachDB) Build(cfg *common.Config, bcfg *common.BuildConfig) error {
115115
// Note that since the version of CockroachDB is pinned, we can generally rely on
116116
// the checking below. However as CockroachDB and Go evolve, the logic below may need
117117
// to change.
118-
ver, err := cfg.GoTool().Version()
118+
ver, err := cfg.GoTool(bcfg.BuildLog).Version()
119119
if err != nil {
120120
return fmt.Errorf("getting go version for toolchain: %v", err)
121121
}
@@ -126,7 +126,7 @@ func (h CockroachDB) Build(cfg *common.Config, bcfg *common.BuildConfig) error {
126126
if v := strings.TrimPrefix(ver, "go version "); strings.HasPrefix(v, "devel ") || v >= "go1.24" {
127127
goBuildArgs = append(goBuildArgs, "-tags=untested_go_version")
128128
}
129-
if err := cfg.GoTool().BuildPath(filepath.Join(bcfg.SrcDir, "pkg/cmd/cockroach-short"), bcfg.BinDir, goBuildArgs...); err != nil {
129+
if err := cfg.GoTool(bcfg.BuildLog).BuildPath(filepath.Join(bcfg.SrcDir, "pkg/cmd/cockroach-short"), bcfg.BinDir, goBuildArgs...); err != nil {
130130
return err
131131
}
132132

@@ -137,7 +137,7 @@ func (h CockroachDB) Build(cfg *common.Config, bcfg *common.BuildConfig) error {
137137
}
138138

139139
// Build the benchmark wrapper.
140-
if err := cfg.GoTool().BuildPath(bcfg.BenchDir, filepath.Join(bcfg.BinDir, "cockroachdb-bench")); err != nil {
140+
if err := cfg.GoTool(bcfg.BuildLog).BuildPath(bcfg.BenchDir, filepath.Join(bcfg.BinDir, "cockroachdb-bench")); err != nil {
141141
return err
142142
}
143143
return nil

sweet/harnesses/esbuild.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ func (h *ESBuild) Build(cfg *common.Config, bcfg *common.BuildConfig) error {
7171
return err
7272
}
7373
// Build driver.
74-
if err := cfg.GoTool().BuildPath(bcfg.BenchDir, filepath.Join(bcfg.BinDir, "esbuild-bench")); err != nil {
74+
if err := cfg.GoTool(bcfg.BuildLog).BuildPath(bcfg.BenchDir, filepath.Join(bcfg.BinDir, "esbuild-bench")); err != nil {
7575
return err
7676
}
7777
// Build esbuild.
78-
return cfg.GoTool().BuildPath(filepath.Join(bcfg.SrcDir, "cmd", "esbuild"), filepath.Join(bcfg.BinDir, "esbuild"))
78+
return cfg.GoTool(bcfg.BuildLog).BuildPath(filepath.Join(bcfg.SrcDir, "cmd", "esbuild"), filepath.Join(bcfg.BinDir, "esbuild"))
7979
}
8080

8181
func (h *ESBuild) Run(cfg *common.Config, rcfg *common.RunConfig) error {

sweet/harnesses/etcd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ func (h Etcd) Build(cfg *common.Config, bcfg *common.BuildConfig) error {
5858
}
5959
// Build etcd's benchmarking tool. Our benchmark is just a wrapper around that.
6060
benchmarkPkg := filepath.Join(bcfg.SrcDir, "tools", "benchmark")
61-
if err := cfg.GoTool().BuildPath(benchmarkPkg, filepath.Join(bcfg.BinDir, "benchmark")); err != nil {
61+
if err := cfg.GoTool(bcfg.BuildLog).BuildPath(benchmarkPkg, filepath.Join(bcfg.BinDir, "benchmark")); err != nil {
6262
return err
6363
}
6464
// Build the benchmark wrapper.
65-
return cfg.GoTool().BuildPath(bcfg.BenchDir, filepath.Join(bcfg.BinDir, "etcd-bench"))
65+
return cfg.GoTool(bcfg.BuildLog).BuildPath(bcfg.BenchDir, filepath.Join(bcfg.BinDir, "etcd-bench"))
6666
}
6767

6868
func (h Etcd) Run(cfg *common.Config, rcfg *common.RunConfig) error {

sweet/harnesses/go-build.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (h GoBuild) Build(pcfg *common.Config, bcfg *common.BuildConfig) error {
117117
return fmt.Errorf("error copying GOROOT: %v", err)
118118
}
119119
cfg.GoRoot = goroot
120-
if err := cfg.GoTool().Do("", "install", "cmd/go", "cmd/compile", "cmd/link"); err != nil {
120+
if err := cfg.GoTool(bcfg.BuildLog).Do("", "install", "cmd/go", "cmd/compile", "cmd/link"); err != nil {
121121
return fmt.Errorf("error building cmd/go, cmd/compile, and cmd/link: %v", err)
122122
}
123123

@@ -147,14 +147,14 @@ func (h GoBuild) Build(pcfg *common.Config, bcfg *common.BuildConfig) error {
147147
// when benchmarking.
148148
pkgPath := filepath.Join(bcfg.BinDir, bench.name, bench.pkg)
149149
dummyBin := filepath.Join(bcfg.BinDir, "dummy")
150-
goTool := cfg.GoTool()
150+
goTool := cfg.GoTool(bcfg.BuildLog)
151151
goTool.Env = cfg.ExecEnv.MustSet("GOROOT=" + cfg.GoRoot)
152152
if err := goTool.BuildPath(pkgPath, dummyBin); err != nil {
153153
return fmt.Errorf("error building %s %s: %w", bench.name, bench.pkg, err)
154154
}
155155
}
156156

157-
if err := cfg.GoTool().BuildPath(bcfg.BenchDir, filepath.Join(bcfg.BinDir, "go-build-bench")); err != nil {
157+
if err := cfg.GoTool(bcfg.BuildLog).BuildPath(bcfg.BenchDir, filepath.Join(bcfg.BinDir, "go-build-bench")); err != nil {
158158
return fmt.Errorf("error building go-build tool: %w", err)
159159
}
160160
return nil
@@ -174,7 +174,7 @@ func (h GoBuild) Run(pcfg *common.Config, rcfg *common.RunConfig) error {
174174
cmd := exec.Command(
175175
filepath.Join(rcfg.BinDir, "go-build-bench"),
176176
append(rcfg.Args, []string{
177-
"-go", cfg.GoTool().Tool,
177+
"-go", cfg.GoTool(nil).Tool,
178178
"-tmp", rcfg.TmpDir,
179179
filepath.Join(rcfg.BinDir, bench.name, bench.pkg),
180180
}...)...,
@@ -199,7 +199,7 @@ func goBuildBenchmarks(cfg *common.Config, short bool) ([]*buildBenchmark, error
199199
var bi *buildinfo.BuildInfo
200200
if cfg != nil {
201201
var err error
202-
bi, err = buildinfo.ReadFile(cfg.GoTool().Tool)
202+
bi, err = buildinfo.ReadFile(cfg.GoTool(nil).Tool)
203203
if err != nil {
204204
return nil, fmt.Errorf("error reading build info from Go toolchain: %v", err)
205205
}

sweet/harnesses/gvisor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ func (h GVisor) Get(gcfg *common.GetConfig) error {
3838

3939
func (h GVisor) Build(cfg *common.Config, bcfg *common.BuildConfig) error {
4040
// Build benchmarking client which will handle a bunch of coordination.
41-
if err := cfg.GoTool().BuildPath(filepath.Join(bcfg.BenchDir), filepath.Join(bcfg.BinDir, "gvisor-bench")); err != nil {
41+
if err := cfg.GoTool(bcfg.BuildLog).BuildPath(filepath.Join(bcfg.BenchDir), filepath.Join(bcfg.BinDir, "gvisor-bench")); err != nil {
4242
return err
4343
}
4444

4545
// Build the runsc package in the repository. CGO_ENABLED must be 0.
4646
// See https://github.com/google/gvisor#using-go-get.
4747
cfg.BuildEnv.Env = cfg.BuildEnv.MustSet("CGO_ENABLED=0")
4848
bin := filepath.Join(bcfg.BinDir, "runsc")
49-
if err := cfg.GoTool().BuildPath(filepath.Join(bcfg.SrcDir, "runsc"), bin); err != nil {
49+
if err := cfg.GoTool(bcfg.BuildLog).BuildPath(filepath.Join(bcfg.SrcDir, "runsc"), bin); err != nil {
5050
return err
5151
}
5252

sweet/harnesses/local.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (h *localBenchHarness) Get(_ *common.GetConfig) error {
2727
}
2828

2929
func (h *localBenchHarness) Build(cfg *common.Config, bcfg *common.BuildConfig) error {
30-
return cfg.GoTool().BuildPath(bcfg.BenchDir, filepath.Join(bcfg.BinDir, h.binName))
30+
return cfg.GoTool(bcfg.BuildLog).BuildPath(bcfg.BenchDir, filepath.Join(bcfg.BinDir, h.binName))
3131
}
3232

3333
func (h *localBenchHarness) Run(cfg *common.Config, rcfg *common.RunConfig) error {

0 commit comments

Comments
 (0)