Commit babdbfb8 authored by Dmitry Vyukov's avatar Dmitry Vyukov

cmd/trace: make binary argument optional

1.7 traces embed symbol info and we now generate symbolized pprof profiles,
so we don't need the binary. Make binary argument optional as 1.5 traces
still need it.

Change-Id: I65eb13e3d20ec765acf85c42d42a8d7aae09854c
Reviewed-on: https://go-review.googlesource.com/22410Reviewed-by: default avatarHyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: default avatarAustin Clements <austin@google.com>
parent caa21475
...@@ -233,7 +233,6 @@ const testFlag2 = ` ...@@ -233,7 +233,6 @@ const testFlag2 = `
-trace trace.out -trace trace.out
Write an execution trace to the specified file before exiting. Write an execution trace to the specified file before exiting.
Writes test binary as -c would.
-v -v
Verbose output: log all tests as they are run. Also print all Verbose output: log all tests as they are run. Also print all
......
...@@ -149,9 +149,11 @@ func testFlags(args []string) (packageNames, passToTest []string) { ...@@ -149,9 +149,11 @@ func testFlags(args []string) (packageNames, passToTest []string) {
testBench = true testBench = true
case "timeout": case "timeout":
testTimeout = value testTimeout = value
case "blockprofile", "cpuprofile", "memprofile", "trace": case "blockprofile", "cpuprofile", "memprofile":
testProfile = true testProfile = true
testNeedBinary = true testNeedBinary = true
case "trace":
testProfile = true
case "coverpkg": case "coverpkg":
testCover = true testCover = true
if value == "" { if value == "" {
......
...@@ -14,7 +14,7 @@ Example usage: ...@@ -14,7 +14,7 @@ Example usage:
Generate a trace file with 'go test': Generate a trace file with 'go test':
go test -trace trace.out pkg go test -trace trace.out pkg
View the trace in a web browser: View the trace in a web browser:
go tool trace pkg.test trace.out go tool trace trace.out
*/ */
package main package main
...@@ -37,7 +37,9 @@ Given a trace file produced by 'go test': ...@@ -37,7 +37,9 @@ Given a trace file produced by 'go test':
go test -trace=trace.out pkg go test -trace=trace.out pkg
Open a web browser displaying trace: Open a web browser displaying trace:
go tool trace [flags] pkg.test trace.out go tool trace [flags] [pkg.test] trace.out
[pkg.test] argument is required for traces produced by Go 1.6 and below.
Go 1.7 does not require the binary argument.
Flags: Flags:
-http=addr: HTTP service address (e.g., ':6060') -http=addr: HTTP service address (e.g., ':6060')
...@@ -58,12 +60,17 @@ func main() { ...@@ -58,12 +60,17 @@ func main() {
} }
flag.Parse() flag.Parse()
// Usage information when no arguments. // Go 1.7 traces embed symbol info and does not require the binary.
if flag.NArg() != 2 { // But we optionally accept binary as first arg for Go 1.5 traces.
switch flag.NArg() {
case 1:
traceFile = flag.Arg(0)
case 2:
programBinary = flag.Arg(0)
traceFile = flag.Arg(1)
default:
flag.Usage() flag.Usage()
} }
programBinary = flag.Arg(0)
traceFile = flag.Arg(1)
ln, err := net.Listen("tcp", *httpFlag) ln, err := net.Listen("tcp", *httpFlag)
if err != nil { if err != nil {
...@@ -91,7 +98,7 @@ var loader struct { ...@@ -91,7 +98,7 @@ var loader struct {
func parseEvents() ([]*trace.Event, error) { func parseEvents() ([]*trace.Event, error) {
loader.once.Do(func() { loader.once.Do(func() {
tracef, err := os.Open(flag.Arg(1)) tracef, err := os.Open(traceFile)
if err != nil { if err != nil {
loader.err = fmt.Errorf("failed to open trace file: %v", err) loader.err = fmt.Errorf("failed to open trace file: %v", err)
return return
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment