The go tool trace utility
Code tracing is a process that allows you to learn information such as the operation of the garbage collector, the lifetime of goroutines, the activity of each logical processor, and the number of operating system threads used. The go tool trace
utility is a tool for viewing the data stored in trace files, which can be generated in any one of the following three ways:
- With the
runtime/trace
package - With the
net/http/pprof
package - With the
go test -trace
command
This section illustrates the use of the first technique using the code of traceCLA.go
:
package main
import (
"fmt"
"os"
"path"
"runtime/trace"
"time"
)
The runtime/trace
package is required for collecting all kinds of tracing data—there is no point in selecting specific tracing data as all tracing data is interconnected.
func main() {
filename := path.Join(os.TempDir(), "...