Skip to content

Commit

Permalink
cmd/bench: add subrepo directories to run benchmarks on
Browse files Browse the repository at this point in the history
For golang/go#53538

Change-Id: I0eb1d2f00ca1977bdd909e0a4bfe4367d388ba16
Reviewed-on: https://go-review.googlesource.com/c/benchmarks/+/453502
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Dylan Le <dungtuanle@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
Dung Le committed Dec 13, 2022
1 parent 0e4f958 commit 6a564b0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
22 changes: 21 additions & 1 deletion cmd/bench/gotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,30 @@ func goTest(tcs []*toolchain) error {
for _, tc := range tcs {
log.Printf("Running Go test benchmarks for %s", tc.Name)
fmt.Printf("toolchain: %s\n", tc.Name)
err := tc.Do("test", "-v", "-run=none", "-bench=.", "-count=5", "golang.org/x/benchmarks/...")
err := tc.Do("", "test", "-v", "-run=none", "-bench=.", "-count=5", "golang.org/x/benchmarks/...")
if err != nil {
return fmt.Errorf("error running gotest with toolchain %s: %w", tc.Name, err)
}
}
return nil
}

func goTestSubrepo(tc *toolchain, subRepo string, dirs []string) error {
switch subRepo {
case "tools":
log.Printf("Running sub-repo benchmarks for %s", subRepo)
fmt.Printf("toolchain: %s\n", tc.Name)

for _, dir := range dirs {
err := tc.Do(dir, "test", "-v", "-bench=.", "./gopls/internal/regtest/bench/", "-count=5")
if err != nil {
log.Printf("Error: %v", err)
return fmt.Errorf("error running sub-repo %s benchmark with toolchain %s in dir %s: %w", subRepo, tc.Name, dir, err)
}
}
default:
return fmt.Errorf("unsupported subrepo %s", subRepo)
}

return nil
}
31 changes: 23 additions & 8 deletions cmd/bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ import (
)

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

func determineGOROOT() (string, error) {
Expand Down Expand Up @@ -141,11 +143,24 @@ func main() {
}
fmt.Printf("branch: %s\n", branch)

if repository != "go" {
// TODO(go.dev/issue/53538): Support other repositories.
log.Fatalf("Unknown repository %q", repository)
subRepoExperiment := *subRepoExperiment
if subRepoExperiment == "" {
subRepoExperiment = os.Getenv("BENCH_SUBREPO_PATH")
}
subRepoBaseline := *subRepoBaseline
if subRepoBaseline == "" {
subRepoBaseline = os.Getenv("BENCH_SUBREPO_BASELINE_PATH")
}
dirs := []string{subRepoExperiment, subRepoBaseline}

if repository != "go" {
toolchain := toolchainFromGOROOT("baseline", gorootBaseline)
if err := goTestSubrepo(toolchain, repository, dirs); err != nil {
log.Print("FAIL")
os.Exit(1)
}
return
}
// Run benchmarks against the toolchains.
if err := run(toolchains); err != nil {
log.Print("FAIL")
Expand Down
9 changes: 6 additions & 3 deletions sweet/common/gotool.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ func SystemGoTool() (*Go, error) {
}, nil
}

func (g *Go) Do(args ...string) error {
func (g *Go) Do(dir string, args ...string) error {
cmd := exec.Command(g.Tool, args...)
if dir != "" {
cmd.Dir = dir
}
cmd.Env = g.Env.Collapse()
if g.PassOutput {
cmd.Stdout = os.Stdout
Expand Down Expand Up @@ -66,7 +69,7 @@ func (g *Go) BuildPackage(pkg, out string) error {
if pkg[0] == '/' || pkg[0] == '.' {
return fmt.Errorf("path used as package in go build")
}
return g.Do("build", "-o", out, pkg)
return g.Do("", "build", "-o", out, pkg)
}

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

func chdir(path string) error {
Expand Down

0 comments on commit 6a564b0

Please sign in to comment.