CPU Profile Analysis
Step 1 — Obtain the Profile
Ask the user for the absolute path to a CPU profile file (.pb.gz).
If they don't have one, run the golang-pprof-collect skill with profile type cpu to collect it first, then return here with the file path.
Step 2 — Extract Profile Data
Run these go tool pprof commands against the .pb.gz file. Capture all output for analysis.
Top by flat CPU time:
// turbo
go tool pprof -top <profile_path>
Top by cumulative CPU time:
// turbo
go tool pprof -top -cum <profile_path>
Text call graph for the top flat consumer: After identifying the top function from flat output, run:
// turbo
go tool pprof -text -focus=<top_function_package_prefix> <profile_path>
Peek at top cumulative functions (shows callers/callees inline):
// turbo
go tool pprof -peek=<top_cum_function> <profile_path>
Step 3 — Analyze and Report
Produce a structured analysis with these sections:
Summary
- Total CPU sample duration and sample count
- Profile timestamp and binary info
Top CPU Consumers (flat)
Table: rank, function, flat time, flat%, cum time, cum%
Top Cumulative Consumers
Functions that are expensive in aggregate even if individually cheap — identifies hot call paths.
Concurrency & Lock Contention Indicators
Flag runtime. functions that indicate contention:
runtime.mallocgc— allocation-heavyruntime.gcBgMarkWorker— GC pressure (cross-reference with heap profile)runtime.lock/runtime.unlock— lock contentionruntime.futex/runtime.semacquire— synchronization waitsruntime.chanrecv/runtime.chansend— channel bottlenecks
Call Chain Analysis
For the top 3-5 consumers, trace the cumulative call chain to identify which top-level operation is responsible.
Actionable Findings
For each major consumer, suggest:
- Whether the CPU usage is expected given the workload
- Algorithmic improvements (caching results, reducing serialization, batching)
- Concurrency improvements (reducing lock scope, sharding, buffered channels)
- Config knobs that may reduce pressure
Follow-up Commands
Suggest additional pprof commands:
-focus/-ignorefor drilling into specific subsystems- Flamegraph:
go tool pprof -http=:9090 <profile_path> - Diff between two CPU profiles:
go tool pprof -base=<baseline> <current>
Source: rumstead/golang-pprof-skills — distributed by TomeVault.