Consider the following program, which simply twists a few goroutines, and then waits for them to complete and transmit the signal through the channel they made.
package main import ( "os" "runtime/trace" "time" ) func doWork(c chan int) { startTime := time.Now() i := 0 for curTime := startTime; curTime.Sub(startTime) < 2; curTime = time.Now() { i++ } c <- i } func main() { numGoRoutine := 10 traceOutFile, _ := os.OpenFile("/tmp/Trace.out", os.O_WRONLY|os.O_CREATE, os.ModeExclusive|os.ModePerm) trace.Start(traceOutFile) // Start goroutines termChannel := make(chan int) for i := 0; i < numGoRoutine; i++ { go doWork(termChannel) } // Wait for completion for i := 0; i < numGoRoutine; i++ { <-termChannel } trace.Stop() }
When this program exits, the output is a binary file called /tmp/Trace.out . Then I tried to view the trace using the trace facility as follows.
go tool trace -http=localhost:8080 ./Main /tmp/Trace.out
This leads to the launch of a page with a link to View Trace (along with viewing other links that give only aggregate data), but when you click on this link a blank page appears. When I look at the source of this page, I see the following source, which seems to imply that JSON is expected, not binary.
<html> <head> <link href="/trace_viewer_html" rel="import"> <script> document.addEventListener("DOMContentLoaded", function(event) { var viewer = new tr.TraceViewer('/jsontrace'); document.body.appendChild(viewer); }); </script> </head> <body> </body> </html>
How to view event tracking with Go tools?
source share