]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/trace: add -d that prints parsed traces
authorHana Kim <hakim@google.com>
Fri, 25 Aug 2017 16:56:29 +0000 (12:56 -0400)
committerHyang-Ah Hana Kim <hyangah@gmail.com>
Mon, 28 Aug 2017 20:40:49 +0000 (20:40 +0000)
This is useful when debugging the tool.

Some tweaks on logging: log the webserver address, log.Print instead
of log.Printf when possible.

Change-Id: Iaf71b6523b40dc13795511784d48eacf0f5a396a
Reviewed-on: https://go-review.googlesource.com/59570
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
src/cmd/trace/main.go

index 8ea0ba01615ab5a6c7315905903e8a23e1fc3f20..c8bd082d0dcd4cc7ae83883f34cb045563cb2858 100644 (file)
@@ -42,6 +42,7 @@ Supported profile types are:
 Flags:
        -http=addr: HTTP service address (e.g., ':6060')
        -pprof=type: print a pprof-like profile instead
+       -d: print debug info such as parsed events
 
 Note that while the various profiles available when launching
 'go tool trace' work on every browser, the trace viewer itself
@@ -52,6 +53,7 @@ and is only actively tested on that browser.
 var (
        httpFlag  = flag.String("http", "localhost:0", "HTTP service address (e.g., ':6060')")
        pprofFlag = flag.String("pprof", "", "print a pprof-like profile instead")
+       debugFlag = flag.Bool("d", false, "print debug information such as parsed events list")
 
        // The binary file name, left here for serveSVGProfile.
        programBinary string
@@ -103,13 +105,18 @@ func main() {
                dief("failed to create server socket: %v\n", err)
        }
 
-       log.Printf("Parsing trace...")
+       log.Print("Parsing trace...")
        events, err := parseEvents()
        if err != nil {
                dief("%v\n", err)
        }
 
-       log.Printf("Serializing trace...")
+       if *debugFlag {
+               trace.Print(events)
+               os.Exit(0)
+       }
+
+       log.Print("Serializing trace...")
        params := &traceParams{
                events:  events,
                endTime: int64(1<<63 - 1),
@@ -119,13 +126,12 @@ func main() {
                dief("%v\n", err)
        }
 
-       log.Printf("Splitting trace...")
+       log.Print("Splitting trace...")
        ranges = splitTrace(data)
 
-       log.Printf("Opening browser")
-       if !browser.Open("http://" + ln.Addr().String()) {
-               fmt.Fprintf(os.Stderr, "Trace viewer is listening on http://%s\n", ln.Addr().String())
-       }
+       addr := "http://" + ln.Addr().String()
+       log.Printf("Opening browser. Trace viewer is listening on %s", addr)
+       browser.Open(addr)
 
        // Start http server.
        http.HandleFunc("/", httpMain)