cmd/compilebench: use go command in goroot, not environment
The "go" command is a random "go" in the environment, not necessarily the one under test. Use the go command in the goroot we're testing. This CL removes the need to add $GOROOT/bin to your path before running compilebench. Change-Id: Ieb7f441f8287105e13446006e73b760d80e51e03 Reviewed-on: https://go-review.googlesource.com/42932 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
11b386927a
commit
a6971f4c11
|
|
@ -76,20 +76,20 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
goroot = runtime.GOROOT()
|
goroot string
|
||||||
compiler string
|
compiler string
|
||||||
runRE *regexp.Regexp
|
runRE *regexp.Regexp
|
||||||
is6g bool
|
is6g bool
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
flagGoCmd = flag.String("go", "go", "path to \"go\" command")
|
||||||
flagAlloc = flag.Bool("alloc", false, "report allocations")
|
flagAlloc = flag.Bool("alloc", false, "report allocations")
|
||||||
flagObj = flag.Bool("obj", false, "report object file stats")
|
flagObj = flag.Bool("obj", false, "report object file stats")
|
||||||
flagCompiler = flag.String("compile", "", "use `exe` as the cmd/compile binary")
|
flagCompiler = flag.String("compile", "", "use `exe` as the cmd/compile binary")
|
||||||
|
|
@ -139,14 +139,20 @@ func main() {
|
||||||
usage()
|
usage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s, err := exec.Command(*flagGoCmd, "env", "GOROOT").CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%s env GOROOT: %v", *flagGoCmd, err)
|
||||||
|
}
|
||||||
|
goroot = strings.TrimSpace(string(s))
|
||||||
|
|
||||||
compiler = *flagCompiler
|
compiler = *flagCompiler
|
||||||
if compiler == "" {
|
if compiler == "" {
|
||||||
out, err := exec.Command("go", "tool", "-n", "compile").CombinedOutput()
|
out, err := exec.Command(*flagGoCmd, "tool", "-n", "compile").CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
out, err = exec.Command("go", "tool", "-n", "6g").CombinedOutput()
|
out, err = exec.Command(*flagGoCmd, "tool", "-n", "6g").CombinedOutput()
|
||||||
is6g = true
|
is6g = true
|
||||||
if err != nil {
|
if err != nil {
|
||||||
out, err = exec.Command("go", "tool", "-n", "compile").CombinedOutput()
|
out, err = exec.Command(*flagGoCmd, "tool", "-n", "compile").CombinedOutput()
|
||||||
log.Fatalf("go tool -n compiler: %v\n%s", err, out)
|
log.Fatalf("go tool -n compiler: %v\n%s", err, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -193,14 +199,14 @@ func runStdCmd() {
|
||||||
args = append(args, "-gcflags", *flagCompilerFlags)
|
args = append(args, "-gcflags", *flagCompilerFlags)
|
||||||
}
|
}
|
||||||
args = append(args, "std", "cmd")
|
args = append(args, "std", "cmd")
|
||||||
cmd := exec.Command("go", args...)
|
cmd := exec.Command(*flagGoCmd, args...)
|
||||||
cmd.Dir = filepath.Join(runtime.GOROOT(), "src")
|
cmd.Dir = filepath.Join(goroot, "src")
|
||||||
runCmd("BenchmarkStdCmd", cmd)
|
runCmd("BenchmarkStdCmd", cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// path is either a path to a file ("$GOROOT/test/helloworld.go") or a package path ("cmd/go").
|
// path is either a path to a file ("$GOROOT/test/helloworld.go") or a package path ("cmd/go").
|
||||||
func runSize(name, path string) {
|
func runSize(name, path string) {
|
||||||
cmd := exec.Command("go", "build", "-o", "_compilebenchout_", path)
|
cmd := exec.Command(*flagGoCmd, "build", "-o", "_compilebenchout_", path)
|
||||||
cmd.Stdout = os.Stderr
|
cmd.Stdout = os.Stderr
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
|
|
@ -240,7 +246,7 @@ func runBuild(name, dir string, count int) {
|
||||||
runSize("BenchmarkCmdGoSize", "cmd/go")
|
runSize("BenchmarkCmdGoSize", "cmd/go")
|
||||||
return
|
return
|
||||||
case "BenchmarkHelloSize":
|
case "BenchmarkHelloSize":
|
||||||
runSize("BenchmarkHelloSize", filepath.Join(runtime.GOROOT(), "test/helloworld.go"))
|
runSize("BenchmarkHelloSize", filepath.Join(goroot, "test/helloworld.go"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue