1
0
mirror of https://github.com/golang/go synced 2024-11-18 15:24:41 -07:00

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
This commit is contained in:
Alan Donovan 2013-08-29 21:34:36 -04:00
parent 3184482148
commit b43fa6fbda
2 changed files with 16 additions and 6 deletions

View File

@ -2,17 +2,15 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // 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. // ssadump: a tool for displaying and interpreting the SSA form of Go programs.
package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"log" "log"
"os" "os"
"runtime"
"runtime/pprof" "runtime/pprof"
"code.google.com/p/go.tools/importer" "code.google.com/p/go.tools/importer"
@ -52,6 +50,18 @@ Examples:
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") 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() { func main() {
flag.Parse() flag.Parse()
args := flag.Args() args := flag.Args()

View File

@ -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) info := imp.CreateSourcePackage("main", files)
if info.Err != nil { if info.Err != nil {
t.Errorf("importer.CreateSourcePackage(%s) failed: %s", inputs, info.Err.Error()) 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 := prog.Package(info.Pkg)
mainPkg.CreateTestMainFunction() // (no-op if main already exists) 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 { if exitCode := interp.Interpret(mainPkg, 0, inputs[0], []string{}); exitCode != 0 {
t.Errorf("interp.Interpret(%s) exited with code %d, want zero", inputs, exitCode) t.Errorf("interp.Interpret(%s) exited with code %d, want zero", inputs, exitCode)
return false return false