The Go 1.5 release note says,
The new "go tool trace" command enables the visualisation of program traces generated by new tracing infrastructure in the runtime.
This is really exciting, and I want to know more about it. But its official document at https://golang.org/cmd/trace/ is really dry.
Found that Rob Pike complained about it, requesting that "shortly after the 1.5 release, there should be a blog post about the feature."
If anyone has posted/spotted such a blog, please add a link here. Or, if you like to answer directly here, it is also welcome as well.
Thanks
Running this code with go run main.go 2> trace. out sends the tracing output to the file trace. out , which can then be read with: go tool trace trace. out .
For Golang applications using microservices architecture, distributed tracing can enable a central overview of how requests are performing across microservices. This lets application owners reconstruct the whole path of the request and see how individual components performed as part of the entire user request.
There are two ways you can generate trace files.
Method 1
Add following line at the start of your program
f, err := os.Create(time.Now().Format("2006-01-02T150405.pprof"))
if err != nil {
panic(err)
}
defer f.Close()
if err := trace.Start(f); err != nil {
panic(err)
}
defer trace.Stop()
build the program
go build
./myprogram
)go tool trace myprogram 2015-08-21T115354.pprof
Method 2
Run Test with trace flag
go test -trace trace.out
Run trace tool with generated .test and .out file
go tool trace pkg.test trace.out
In both cases your browser will open something like this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With