NOTE
4.5 trace
Runtime/trace records Go execution traces. These notes start with importing the package and collecting data, then describe viewing the results.
This is a historical learning note and may contain outdated or incomplete understanding.
1. Usage
The steps are as follows:
- Import the package:
import runtime/trace - Start analysis:
trace.Start(file); stop analysis:trace.Stop()
package main
import (
"fmt"
"os"
"runtime/trace"
)
func main() {
file, err := os.Create("trace.out")
if err != nil {
panic(err)
}
defer file.Close()
err = trace.Start(file)
if err != nil {
panic(err)
}
fmt.Println("Hello World")
trace.Stop()
}
- Command-line analysis
go tool trace trace.out
2. References
Go execution tracer | Gopher Academy Blog Go Execution Tracer - Go Language Chinese Website - Golang Chinese Community An Introduction to go tool trace How to analyze the performance of your go application in production | Developer’s life Go code refactoring : the 23x performance hunt | by Val Deleplace | Medium
Drag to pan, scroll to zoom, and click a node to expand or collapse it. Large maps start with deeper levels collapsed; click nodes to expand them.

Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub