Skip to content

Commit 6a564b0

Browse files
author
Dung Le
committed
cmd/bench: add subrepo directories to run benchmarks on
For golang/go#53538 Change-Id: I0eb1d2f00ca1977bdd909e0a4bfe4367d388ba16 Reviewed-on: https://go-review.googlesource.com/c/benchmarks/+/453502 Reviewed-by: Michael Pratt <[email protected]> Run-TryBot: Dylan Le <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 0e4f958 commit 6a564b0

File tree

3 files changed

+50
-12
lines changed

3 files changed

+50
-12
lines changed

cmd/bench/gotest.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,30 @@ func goTest(tcs []*toolchain) error {
1313
for _, tc := range tcs {
1414
log.Printf("Running Go test benchmarks for %s", tc.Name)
1515
fmt.Printf("toolchain: %s\n", tc.Name)
16-
err := tc.Do("test", "-v", "-run=none", "-bench=.", "-count=5", "golang.org/x/benchmarks/...")
16+
err := tc.Do("", "test", "-v", "-run=none", "-bench=.", "-count=5", "golang.org/x/benchmarks/...")
1717
if err != nil {
1818
return fmt.Errorf("error running gotest with toolchain %s: %w", tc.Name, err)
1919
}
2020
}
2121
return nil
2222
}
23+
24+
func goTestSubrepo(tc *toolchain, subRepo string, dirs []string) error {
25+
switch subRepo {
26+
case "tools":
27+
log.Printf("Running sub-repo benchmarks for %s", subRepo)
28+
fmt.Printf("toolchain: %s\n", tc.Name)
29+
30+
for _, dir := range dirs {
31+
err := tc.Do(dir, "test", "-v", "-bench=.", "./gopls/internal/regtest/bench/", "-count=5")
32+
if err != nil {
33+
log.Printf("Error: %v", err)
34+
return fmt.Errorf("error running sub-repo %s benchmark with toolchain %s in dir %s: %w", subRepo, tc.Name, dir, err)
35+
}
36+
}
37+
default:
38+
return fmt.Errorf("unsupported subrepo %s", subRepo)
39+
}
40+
41+
return nil
42+
}

cmd/bench/main.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ import (
2323
)
2424

2525
var (
26-
wait = flag.Bool("wait", true, "wait for system idle before starting benchmarking")
27-
gorootExperiment = flag.String("goroot", "", "GOROOT to test (default $GOROOT or 'go env GOROOT')")
28-
gorootBaseline = flag.String("goroot-baseline", "", "baseline GOROOT to test against (optional) (default $BENCH_BASELINE_GOROOT)")
29-
branch = flag.String("branch", "", "branch of the commits we're testing against (default $BENCH_BRANCH or unknown)")
30-
repository = flag.String("repository", "", "repository name of the commits we're testing against (default $BENCH_REPOSITORY or 'go')")
26+
wait = flag.Bool("wait", true, "wait for system idle before starting benchmarking")
27+
gorootExperiment = flag.String("goroot", "", "GOROOT to test (default $GOROOT or 'go env GOROOT')")
28+
gorootBaseline = flag.String("goroot-baseline", "", "baseline GOROOT to test against (optional) (default $BENCH_BASELINE_GOROOT)")
29+
branch = flag.String("branch", "", "branch of the commits we're testing against (default $BENCH_BRANCH or unknown)")
30+
repository = flag.String("repository", "", "repository name of the commits we're testing against (default $BENCH_REPOSITORY or 'go')")
31+
subRepoExperiment = flag.String("subrepo", "", "Sub-repo dir to test (default $BENCH_SUBREPO_PATH)")
32+
subRepoBaseline = flag.String("subrepo-baseline", "", "Sub-repo baseline to test against (default $BENCH_SUBREPO_BASELINE_PATH)")
3133
)
3234

3335
func determineGOROOT() (string, error) {
@@ -141,11 +143,24 @@ func main() {
141143
}
142144
fmt.Printf("branch: %s\n", branch)
143145

144-
if repository != "go" {
145-
// TODO(go.dev/issue/53538): Support other repositories.
146-
log.Fatalf("Unknown repository %q", repository)
146+
subRepoExperiment := *subRepoExperiment
147+
if subRepoExperiment == "" {
148+
subRepoExperiment = os.Getenv("BENCH_SUBREPO_PATH")
149+
}
150+
subRepoBaseline := *subRepoBaseline
151+
if subRepoBaseline == "" {
152+
subRepoBaseline = os.Getenv("BENCH_SUBREPO_BASELINE_PATH")
147153
}
154+
dirs := []string{subRepoExperiment, subRepoBaseline}
148155

156+
if repository != "go" {
157+
toolchain := toolchainFromGOROOT("baseline", gorootBaseline)
158+
if err := goTestSubrepo(toolchain, repository, dirs); err != nil {
159+
log.Print("FAIL")
160+
os.Exit(1)
161+
}
162+
return
163+
}
149164
// Run benchmarks against the toolchains.
150165
if err := run(toolchains); err != nil {
151166
log.Print("FAIL")

sweet/common/gotool.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ func SystemGoTool() (*Go, error) {
3030
}, nil
3131
}
3232

33-
func (g *Go) Do(args ...string) error {
33+
func (g *Go) Do(dir string, args ...string) error {
3434
cmd := exec.Command(g.Tool, args...)
35+
if dir != "" {
36+
cmd.Dir = dir
37+
}
3538
cmd.Env = g.Env.Collapse()
3639
if g.PassOutput {
3740
cmd.Stdout = os.Stdout
@@ -66,7 +69,7 @@ func (g *Go) BuildPackage(pkg, out string) error {
6669
if pkg[0] == '/' || pkg[0] == '.' {
6770
return fmt.Errorf("path used as package in go build")
6871
}
69-
return g.Do("build", "-o", out, pkg)
72+
return g.Do("", "build", "-o", out, pkg)
7073
}
7174

7275
func (g *Go) BuildPath(path, out string) error {
@@ -81,7 +84,7 @@ func (g *Go) BuildPath(path, out string) error {
8184
if err := chdir(path); err != nil {
8285
return fmt.Errorf("failed to enter build directory: %w", err)
8386
}
84-
return g.Do("build", "-o", out)
87+
return g.Do("", "build", "-o", out)
8588
}
8689

8790
func chdir(path string) error {

0 commit comments

Comments
 (0)