Execution Tracing
go tool trace for goroutine-level analysis
Execution Tracing is a free Go Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Go Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What is execution tracing?
The Go execution tracer records a timeline of goroutine scheduling, GC events, syscalls, and heap growth. It provides a visual view of parallelism and latency unavailable from CPU or heap profiles.
Capturing a trace
Capture a trace via the HTTP endpoint:
curl http://localhost:6060/debug/pprof/trace?seconds=5 -o trace.out
go tool trace trace.outFile-based trace
Use runtime/trace to record a trace programmatically:
f, _ := os.Create("trace.out")
trace.Start(f)
defer trace.Stop()
// run workloadgo test -trace
Capture a trace during test/benchmark runs:
go test -trace trace.out -bench=. ./...
go tool trace trace.outTrace viewer
The trace viewer (go tool trace) opens in a browser showing goroutine timelines, GC events, heap size, and per-goroutine stack traces at any moment in time.
Goroutine analysis
The Goroutine Analysis view groups goroutines by function and shows how long each spends in states: running, runnable (waiting for a P), blocked (channel/mutex/syscall), and sleeping.
Finding scheduler latency
High "runnable" time means goroutines are ready but not scheduled. This indicates too many goroutines competing for GOMAXPROCS Ps, or a CPU-starved process.
GC impact
GC stop-the-world pauses appear as grey bars across all goroutines. Large pauses or frequent GC indicate excessive allocation — combine with heap profiling to reduce allocations.
User annotations
Add custom spans to the trace using trace.WithRegion and trace.Log to annotate your own code sections for easier analysis.
trace.WithRegion(ctx, "parse request", func() {
parseRequest(req)
})task and region
trace.NewTask groups related regions under a named task, letting you measure end-to-end latency for a logical operation across multiple goroutines.
ctx, task := trace.NewTask(ctx, "handle request")
defer task.End()Trace vs profile
CPU profile: which functions consume CPU over time. Heap profile: which functions allocate memory. Trace: when goroutines run, block, and how GC interleaves — different tools for different questions.
Quick Check
What does "runnable" goroutine state mean in the execution trace?
Recap: Execution Tracing
Key points:
- go tool trace shows goroutine timelines, GC events, and scheduling
- Capture via HTTP endpoint or runtime/trace package
- Runnable time → scheduler contention; GC pauses → excessive allocations
- User annotations (WithRegion, NewTask) mark your own sections
Frequently asked questions
Is the “Execution Tracing” lesson free?
Yes — the full text of “Execution Tracing” is free to read here on the web, and the Go Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Go Academy course, upgrade to CoddyKit PRO.
What will I learn in “Execution Tracing”?
go tool trace for goroutine-level analysis You practise Go Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Go Academy?
No prior experience is required. Go Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Execution Tracing” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Go Academy lesson?
Yes. Every Go Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.