RousselTMLEARNING

Observability

Continuous profiling with Grafana Pyroscope: why and how

The fourth signal of observability: what continuous profiling is, profile types (CPU, memory, locks), reading a flame graph and Pyroscope's place in the Grafana stack.

1. The fourth signal #

What metrics, logs and traces do not tell you.

From « what » to « which line of code » #

Available in: ✓ OSS ✓ Enterprise ✓ Cloud Pyroscope open source and Grafana Cloud Profiles

Metrics say a service uses 4 CPUs, traces say which call is slow, logs tell what happened. None of them says which function consumes that CPU or allocates that memory. That is the role of profiling.

Continuous profiling constantly samples the call stack of processes in production (for example 100 times per second) with low overhead (often 1 to 3% CPU). You can then go back to yesterday's spike, compare two versions or find the most expensive function across a fleet.

SignalQuestionGrafana tool
MetricsHow much? Is it normal?Prometheus, Mimir
LogsWhat happened?Loki
TracesWhere was time spent between services?Tempo
ProfilesWhich function consumes CPU or memory?Pyroscope
Good to know: Pyroscope was born in 2020 as an independent project, acquired by Grafana Labs in 2023 and merged with Grafana Phlare. It is open source (AGPLv3). OpenTelemetry is also standardizing profiles as a signal in their own right (OTLP profiles protocol, still in development).

2. Profile types #

CPU, memory, locks, goroutines.

The main types #

TypeMeasuresLanguages
CPU (process_cpu)CPU time spent in each functionAll
Wall clock (wall)Real time, including waitsJava, Python, .NET, Ruby
Allocations (alloc_objects, alloc_space)What is allocated (GC pressure)Go, Java, .NET
Memory in use (inuse_objects, inuse_space)What stays in memory (leaks)Go
Locks (mutex, block, lock)Time waiting on locks and channelsGo, Java, .NET
GoroutinesNumber of goroutines per stackGo

In Pyroscope, a profile type is identified by a string such as process_cpu:cpu:nanoseconds:cpu:nanoseconds (name:sample type:unit:period type:unit).

3. Reading a flame graph #

The reference visualization.

Principle #

Example flame graph
Here, 38% of the CPU is consumed by a regular expression called from computePrice.
  • Each rectangle is a function; its children (below it in Grafana) are the functions it calls.
  • The width is the share of samples in which this function was on the stack: the wider, the more it costs.
  • Horizontal order has no temporal meaning (sorted alphabetically or by size).
  • Self time is the part of a function not covered by any child: it is the function's own code.
Good practice: Look for « plateaus »: a wide rectangle at the very bottom of a stack is a function that actually does work. Grafana's « Top table » sorts functions by self time: it is often the fastest starting point.

4. Pyroscope in the stack #

Collection, storage, exploration.

Three ways to send profiles #

ModePrincipleWhen to use it
SDK (push)The Pyroscope library in the application sends its profilesBusiness labels, span profiles, languages without pprof
Alloy (pull)Alloy collects exposed pprof endpoints (Go, Rust...)Go applications already instrumented with net/http/pprof
Alloy eBPFAlloy profiles all processes on the host via the kernelProfiling a whole fleet without changing code

Related articles

Grafana Pyroscope architecture and deployment

Pyroscope components (distributor, ingester, querier, store-gateway, compactor), object storage, monolithic a…

Instrumenting applications for Pyroscope: SDKs, Alloy and eBPF

Send profiles to Pyroscope from Go, Java, Python and Node.js with the SDKs, collect pprof endpoints with Allo…

Analyzing profiles in Grafana: flame graphs, comparisons and diagnostics

A method for analyzing profiles in Grafana: Profiles Drilldown, flame graph and top table, comparing two peri…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!