Skip to content

Commit 0b4f4e0

Browse files
committed
cmd/trace: add -d that prints parsed traces
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 <[email protected]> Reviewed-by: Dmitry Vyukov <[email protected]>
1 parent 2a56b02 commit 0b4f4e0

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/cmd/trace/main.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Supported profile types are:
4242
Flags:
4343
-http=addr: HTTP service address (e.g., ':6060')
4444
-pprof=type: print a pprof-like profile instead
45+
-d: print debug info such as parsed events
4546
4647
Note that while the various profiles available when launching
4748
'go tool trace' work on every browser, the trace viewer itself
@@ -52,6 +53,7 @@ and is only actively tested on that browser.
5253
var (
5354
httpFlag = flag.String("http", "localhost:0", "HTTP service address (e.g., ':6060')")
5455
pprofFlag = flag.String("pprof", "", "print a pprof-like profile instead")
56+
debugFlag = flag.Bool("d", false, "print debug information such as parsed events list")
5557

5658
// The binary file name, left here for serveSVGProfile.
5759
programBinary string
@@ -103,13 +105,18 @@ func main() {
103105
dief("failed to create server socket: %v\n", err)
104106
}
105107

106-
log.Printf("Parsing trace...")
108+
log.Print("Parsing trace...")
107109
events, err := parseEvents()
108110
if err != nil {
109111
dief("%v\n", err)
110112
}
111113

112-
log.Printf("Serializing trace...")
114+
if *debugFlag {
115+
trace.Print(events)
116+
os.Exit(0)
117+
}
118+
119+
log.Print("Serializing trace...")
113120
params := &traceParams{
114121
events: events,
115122
endTime: int64(1<<63 - 1),
@@ -119,13 +126,12 @@ func main() {
119126
dief("%v\n", err)
120127
}
121128

122-
log.Printf("Splitting trace...")
129+
log.Print("Splitting trace...")
123130
ranges = splitTrace(data)
124131

125-
log.Printf("Opening browser")
126-
if !browser.Open("http://" + ln.Addr().String()) {
127-
fmt.Fprintf(os.Stderr, "Trace viewer is listening on http://%s\n", ln.Addr().String())
128-
}
132+
addr := "http://" + ln.Addr().String()
133+
log.Printf("Opening browser. Trace viewer is listening on %s", addr)
134+
browser.Open(addr)
129135

130136
// Start http server.
131137
http.HandleFunc("/", httpMain)

0 commit comments

Comments
 (0)