Find Go hot spots with profiles and execution traces

8 steps · about 2 h 14 min · Intermediate

  1. Choose between profiling, tracing and debugging tools (doc, The Go Project, 20 min)

    Maps each Go diagnostic tool to the question it answers.

  2. Expose live profiles from a Go server (doc, Go standard library, 10 min)

    One import gives you CPU, heap and goroutine profiles over HTTP.

  3. Read flame graphs and top tables in pprof (guide, Google, 25 min)

    Explains flat versus cumulative cost and the views pprof offers.

  4. 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.

  5. 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.

  6. Open a trace with go tool trace (doc, Go standard library, 10 min)

    Covers the trace viewer for goroutine scheduling, blocking and GC events.

  7. Build with profile-guided optimization (doc, The Go Project, 15 min)

    Turns a production CPU profile into a faster binary with default.pgo.

  8. 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.