Search⌘ K
AI Features

Tracing Our Tool

Explore how to utilize the Go tracer tool to gain insights into your program's execution, including CPU use, goroutines, and scheduling. Understand how to interpret trace results via the Go trace viewer and improve performance by optimizing concurrency in your Go command-line applications.

We'll cover the following...

Overview

The Go profiler is a great tool to help you understand how your program is spending CPU time. However, sometimes a program is spending time waiting for resources to be available. For example, it could be spending time waiting for a network connection or a file to be read. To help you understand those cases, Go provides another tool: the tracer.

Similar to the profiler, the tracer is also integrated with the testing and benchmarking features through the go test tool. Run the benchmarks again with the -trace option to create a trace:

Shell
go test -bench . -benchtime=10x -run ^$ -trace trace01.out
goos: linux
goarch: amd64
pkg: usercode/performance/colStats
Benchmark_Run-4 10 685356800 ns/op
PASS
ok usercode/performance/colStats 7.712s

Once the trace is created, view the results with the go tool trace command: ...