Find Go hot spots with profiles and execution traces
8 steps · about 2 h 14 min · Intermediate
- Choose between profiling, tracing and debugging tools (doc, The Go Project, 20 min)
Maps each Go diagnostic tool to the question it answers.
- Expose live profiles from a Go server (doc, Go standard library, 10 min)
One import gives you CPU, heap and goroutine profiles over HTTP.
- Read flame graphs and top tables in pprof (guide, Google, 25 min)
Explains flat versus cumulative cost and the views pprof offers.
- Tune garbage collection with GOGC and memory limits (guide, The Go Project, 30 min)
Explains how heap profiles relate to GC cost and which knobs change it.
- Capture execution traces with low overhead (article, The Go Blog, 12 min)
Shows how modern traces and the flight recorder catch latency problems profiles miss.
- Open a trace with go tool trace (doc, Go standard library, 10 min)
Covers the trace viewer for goroutine scheduling, blocking and GC events.
- Build with profile-guided optimization (doc, The Go Project, 15 min)
Turns a production CPU profile into a faster binary with default.pgo.
- Walk through a PGO speed-up on a real service (article, The Go Blog, 12 min)
A worked example shows the collect, build and measure loop end to end.