Commit 0b4f4e01 authored by Hana Kim's avatar Hana Kim Committed by Hyang-Ah Hana Kim

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/59570Reviewed-by: default avatarHeschi Kreinick <heschi@google.com>
Reviewed-by: default avatarDmitry Vyukov <dvyukov@google.com>
parent 2a56b023
...@@ -42,6 +42,7 @@ Supported profile types are: ...@@ -42,6 +42,7 @@ Supported profile types are:
Flags: Flags:
-http=addr: HTTP service address (e.g., ':6060') -http=addr: HTTP service address (e.g., ':6060')
-pprof=type: print a pprof-like profile instead -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 Note that while the various profiles available when launching
'go tool trace' work on every browser, the trace viewer itself 'go tool trace' work on every browser, the trace viewer itself
...@@ -52,6 +53,7 @@ and is only actively tested on that browser. ...@@ -52,6 +53,7 @@ and is only actively tested on that browser.
var ( var (
httpFlag = flag.String("http", "localhost:0", "HTTP service address (e.g., ':6060')") httpFlag = flag.String("http", "localhost:0", "HTTP service address (e.g., ':6060')")
pprofFlag = flag.String("pprof", "", "print a pprof-like profile instead") 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. // The binary file name, left here for serveSVGProfile.
programBinary string programBinary string
...@@ -103,13 +105,18 @@ func main() { ...@@ -103,13 +105,18 @@ func main() {
dief("failed to create server socket: %v\n", err) dief("failed to create server socket: %v\n", err)
} }
log.Printf("Parsing trace...") log.Print("Parsing trace...")
events, err := parseEvents() events, err := parseEvents()
if err != nil { if err != nil {
dief("%v\n", err) dief("%v\n", err)
} }
log.Printf("Serializing trace...") if *debugFlag {
trace.Print(events)
os.Exit(0)
}
log.Print("Serializing trace...")
params := &traceParams{ params := &traceParams{
events: events, events: events,
endTime: int64(1<<63 - 1), endTime: int64(1<<63 - 1),
...@@ -119,13 +126,12 @@ func main() { ...@@ -119,13 +126,12 @@ func main() {
dief("%v\n", err) dief("%v\n", err)
} }
log.Printf("Splitting trace...") log.Print("Splitting trace...")
ranges = splitTrace(data) ranges = splitTrace(data)
log.Printf("Opening browser") addr := "http://" + ln.Addr().String()
if !browser.Open("http://" + ln.Addr().String()) { log.Printf("Opening browser. Trace viewer is listening on %s", addr)
fmt.Fprintf(os.Stderr, "Trace viewer is listening on http://%s\n", ln.Addr().String()) browser.Open(addr)
}
// Start http server. // Start http server.
http.HandleFunc("/", httpMain) http.HandleFunc("/", httpMain)
......
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