]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/trace: make binary argument optional
authorDmitry Vyukov <dvyukov@google.com>
Sun, 24 Apr 2016 11:33:33 +0000 (13:33 +0200)
committerDmitry Vyukov <dvyukov@google.com>
Tue, 3 May 2016 12:35:09 +0000 (12:35 +0000)
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/22410
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Austin Clements <austin@google.com>
src/cmd/go/test.go
src/cmd/go/testflag.go
src/cmd/trace/main.go

index 5c21de5d9ba558696ea3edffd20b738a6840f0e3..02abcbe23a07f063fe761465728b5baa63655962 100644 (file)
@@ -233,7 +233,6 @@ const testFlag2 = `
 
        -trace trace.out
            Write an execution trace to the specified file before exiting.
-           Writes test binary as -c would.
 
        -v
            Verbose output: log all tests as they are run. Also print all
index 873df1ffc36ce7434f2022fb35bfa6d4e1371e3c..a65ed1f3840293c4df906664b50121cd4a98357e 100644 (file)
@@ -149,9 +149,11 @@ func testFlags(args []string) (packageNames, passToTest []string) {
                                testBench = true
                        case "timeout":
                                testTimeout = value
-                       case "blockprofile", "cpuprofile", "memprofile", "trace":
+                       case "blockprofile", "cpuprofile", "memprofile":
                                testProfile = true
                                testNeedBinary = true
+                       case "trace":
+                               testProfile = true
                        case "coverpkg":
                                testCover = true
                                if value == "" {
index cfd222e132afe899ac87124cace7e59e531a602f..2735bf13ea23e99d816c239c438c0317f38cf774 100644 (file)
@@ -14,7 +14,7 @@ Example usage:
 Generate a trace file with 'go test':
        go test -trace trace.out pkg
 View the trace in a web browser:
-       go tool trace pkg.test trace.out
+       go tool trace trace.out
 */
 package main
 
@@ -37,7 +37,9 @@ Given a trace file produced by 'go test':
        go test -trace=trace.out pkg
 
 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:
        -http=addr: HTTP service address (e.g., ':6060')
@@ -58,12 +60,17 @@ func main() {
        }
        flag.Parse()
 
-       // Usage information when no arguments.
-       if flag.NArg() != 2 {
+       // Go 1.7 traces embed symbol info and does not require the binary.
+       // 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()
        }
-       programBinary = flag.Arg(0)
-       traceFile = flag.Arg(1)
 
        ln, err := net.Listen("tcp", *httpFlag)
        if err != nil {
@@ -91,7 +98,7 @@ var loader struct {
 
 func parseEvents() ([]*trace.Event, error) {
        loader.once.Do(func() {
-               tracef, err := os.Open(flag.Arg(1))
+               tracef, err := os.Open(traceFile)
                if err != nil {
                        loader.err = fmt.Errorf("failed to open trace file: %v", err)
                        return