From b43fa6fbda03d2d4ec615ec291605371e0b5bbb3 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 29 Aug 2013 21:34:36 -0400 Subject: [PATCH] go.tools/cmd/ssadump: move ssa/ssadump.go command to its own package. (Its former location was based on a misunderstanding of 'go build'.) Also: set GOMAXPROCS to NumCPU by default. R=crawshaw CC=golang-dev https://golang.org/cl/13354043 --- ssa/ssadump.go => cmd/ssadump/main.go | 18 ++++++++++++++---- ssa/interp/interp_test.go | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) rename ssa/ssadump.go => cmd/ssadump/main.go (93%) diff --git a/ssa/ssadump.go b/cmd/ssadump/main.go similarity index 93% rename from ssa/ssadump.go rename to cmd/ssadump/main.go index 33c020ed..24992bd1 100644 --- a/ssa/ssadump.go +++ b/cmd/ssadump/main.go @@ -2,17 +2,15 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build ignore - -package main - // ssadump: a tool for displaying and interpreting the SSA form of Go programs. +package main import ( "flag" "fmt" "log" "os" + "runtime" "runtime/pprof" "code.google.com/p/go.tools/importer" @@ -52,6 +50,18 @@ Examples: var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") +func init() { + // If $GOMAXPROCS isn't set, use the full capacity of the machine. + // For small machines, use at least 4 threads. + if os.Getenv("GOMAXPROCS") == "" { + n := runtime.NumCPU() + if n < 4 { + n = 4 + } + runtime.GOMAXPROCS(n) + } +} + func main() { flag.Parse() args := flag.Args() diff --git a/ssa/interp/interp_test.go b/ssa/interp/interp_test.go index 60011844..9c0a55ce 100644 --- a/ssa/interp/interp_test.go +++ b/ssa/interp/interp_test.go @@ -185,7 +185,7 @@ func run(t *testing.T, dir, input string) bool { } }() - hint = fmt.Sprintf("To dump SSA representation, run:\n%% go run src/code.google.com/p/go.tools/ssa/ssadump.go -build=CFP %s\n", input) + hint = fmt.Sprintf("To dump SSA representation, run:\n%% go build code.google.com/p/go.tools/cmd/ssadump; ./ssadump -build=CFP %s\n", input) info := imp.CreateSourcePackage("main", files) if info.Err != nil { t.Errorf("importer.CreateSourcePackage(%s) failed: %s", inputs, info.Err.Error()) @@ -201,7 +201,7 @@ func run(t *testing.T, dir, input string) bool { mainPkg := prog.Package(info.Pkg) mainPkg.CreateTestMainFunction() // (no-op if main already exists) - hint = fmt.Sprintf("To trace execution, run:\n%% go run src/code.google.com/p/go.tools/ssa/ssadump.go -build=C -run --interp=T %s\n", input) + hint = fmt.Sprintf("To trace execution, run:\n%% go build code.google.com/p/go.tools/cmd/ssadump; ./ssadump -build=C -run --interp=T %s\n", input) if exitCode := interp.Interpret(mainPkg, 0, inputs[0], []string{}); exitCode != 0 { t.Errorf("interp.Interpret(%s) exited with code %d, want zero", inputs, exitCode) return false