1. A four-step method #
From symptom to line of code.
Method #
Available in: ✓ OSS ✓ Enterprise ✓ Cloud Pyroscope open source and Grafana Cloud Profiles
- Start from a symptom: high CPU on a dashboard, degraded p99 latency, OOMKilled.
- Choose the right profile type: CPU for consumption, wall clock for latency,
inuse_spacefor a leak,alloc_spacefor GC pressure,mutex/blockfor contention. - Narrow the scope by labels (
service_name,pod,endpoint) and by time range. - Read the top table sorted by self time, then the flame graph to understand where the calls come from.
2. Comparing two periods #
The diff feature.
Before / after #
The Comparison view (diff flame graph) overlays two selections: the baseline and the comparison. Functions in red consume more, those in green less. It is the ideal tool to:
- compare version N and N+1 (
versionlabel); - compare a CPU spike with a normal period;
- compare two regions or two instance types.
Good practice: Always add a version label (commit or tag) to your profiles: every deployment becomes comparable in one click.3. Real cases #
What you actually find.
Frequent examples #
| Symptom | Profile | Typical finding |
|---|---|---|
| High CPU | process_cpu | Regular expression compiled on every call, reflection-based JSON serialization |
| Very active GC | alloc_space | String concatenations in a loop, slices not pre-allocated |
| Memory growing endlessly | inuse_space | Cache without eviction, blocked goroutines holding on to objects |
| High latency, low CPU | wall, block, mutex | Global lock, connection pool too small |
| Cloud cost | process_cpu aggregated across the fleet | A logging library costs 15% of total CPU |
// Avant : compilée à chaque appel (visible dans le flame graph : regexp.Compile)
func isValid(s string) bool { return regexp.MustCompile(`^[A-Z]{3}-\d+$`).MatchString(s) }
// Après : compilée une fois
var ref = regexp.MustCompile(`^[A-Z]{3}-\d+$`)
func isValid(s string) bool { return ref.MatchString(s) }Profiles in dashboards #
Grafana's Flame graph panel can be placed in a dashboard next to the service's CPU metrics. You can also plot a series derived from profiles (for example the CPU of a given function) to track the effect of an optimization over time.
