Skip to content

Pyroscope

Pyroscope is PerfShop's continuous profiling service. It receives, in push mode, the CPU, memory allocation, and lock contention profiles produced by the Pyroscope Java agent embedded in the backend, stores them in the named volume pyroscope-data, and feeds the Flamegraph panels of the APM dashboards.

Source of truth

This page is taken from pyroscope/pyroscope-config.yml, the backend JAVA_OPTS in the compose files, the Pyroscope datasource (grafana/provisioning/datasources/pyroscope.yml) and measurements made on 2026-09-25 on the development stack (Docker Desktop, itimer mode). Since 2026-10-14, docker-compose.build.yml also profiles in itimer mode: the cpu mode stopped the agent on Linux (Ubuntu 24.04 VM: "No access to perf events"), and itimer profiles the backend there (measured the same day).

Why Pyroscope?

Continuous profiling is the lesser-known pillar of the "four pillars of observability" (metrics, logs, traces, profiles). Where metrics say "how much", traces say "where in the path of a request", profiles say "which method consumes".

In PerfShop, Pyroscope answers questions such as:

  • "When CPU chaos is active, which Java method is consuming the CPU?"
  • "Which method allocates the memory while the F3 anomaly (OutOfMemoryError) or the memory leak is running?"
  • "On which lock do threads block when lock contention is active?"

Answers are visual: flamegraphs, where the width of each rectangle represents the share of CPU time, allocated bytes or contentions attributed to the method.

Architecture

flowchart LR
  subgraph BE["perfshop-app (JVM)"]
    direction TB
    APP["Spring Boot 3.2"]
    PA["Pyroscope agent<br/>pyroscope.jar 0.14.0"]
    APP -.injected.-> PA
  end

  PYRO["perfshop-pyroscope<br/>(grafana/pyroscope:1.13.0)<br/>filesystem storage"]

  GRAF["Grafana<br/>(Pyroscope datasource)"]

  PA -->|"JFR HTTP push :4040<br/>(CPU, alloc, lock) every 10 s"| PYRO
  PYRO -->|"Pyroscope datasource<br/>(flamegraph queries)"| GRAF

Pyroscope works in push mode: the agent sends its profiles every 10 s (uploadInterval=PT10S in its startup log), Pyroscope scrapes nothing.

Read-only for students (since 2026-10-18)

The perfshop-pyroscope service no longer publishes a port: the agent and Grafana reach it through the Docker network. The public port 4040 belongs to the landing page, whose nginx (welcome/nginx-pyroscope.conf) only lets through what the UI reads — its pages (Single, Comparison, Diff, Tag Explorer), its assets, flamegraph rendering, read queries and /ready. Profile uploads (/ingest, Push), administration (/admin) and everything else get 403: a profile sent from a classroom workstation no longer pollutes the shared history.

Pyroscope configuration

server:
  http_listen_port: 4040
  log_level: warn

storage:
  backend: filesystem
  filesystem:
    dir: /data/shared

limits:
  compactor_blocks_retention_period: 7d

The container loads it with command: ["-config.file=/etc/pyroscope/pyroscope-config.yml"].

Command syntax and volume mount

Pyroscope 1.x has no server subcommand (Pyroscope 0.x syntax). Until 2026-09-25, the command server --config.file=… stopped option parsing at the word server: this file was never loaded — no persistent storage, no retention, logs at info level. The named volume is mounted on /data, an image directory owned by the pyroscope user (a new volume inherits it): mounted on /var/pyroscope, it stayed owned by root and writes failed (mkdir /var/pyroscope/data: permission denied). Check: no no storage bucket configured nor permission denied message in docker logs perfshop-pyroscope.

Parameter Value Effect
http_listen_port 4040 Single HTTP port — profile ingestion (/ingest) and query API (Grafana, UI)
log_level warn Pyroscope log level
storage.backend / filesystem.dir filesystem, /data/shared Shared block storage, in the named volume pyroscope-data mounted on /data; enables the compactor and store-gateway modules of the single binary
limits.compactor_blocks_retention_period 7d Retention: 7 days — the compactor deletes older blocks

The default host port is 4040 (variable PYROSCOPE_HTTP_PORT). The Pyroscope UI (http://localhost:4040) opens without an account; it lists two services: perfshop (the backend) and pyroscope (Pyroscope profiles itself).

Pyroscope agent on the backend side

The agent is embedded in the perfshop-backend image (/agents/pyroscope.jar, version 0.14.0) and activated via JAVA_OPTS:

-javaagent:/agents/pyroscope.jar
-Dpyroscope.server.address=http://perfshop-pyroscope:4040
-Dpyroscope.application.name=perfshop
-Dpyroscope.format=jfr
-Dpyroscope.profiler.event=itimer        # both compose files ("cpu" is refused without an extra capability)
-Dpyroscope.profiler.alloc=512k
-Dpyroscope.profiler.lock=10ms
-Dpyroscope.profiling.interval=20ms
Property Effect
pyroscope.server.address Pyroscope address on the Docker network
pyroscope.application.name=perfshop Application name — label service_name="perfshop" in queries
pyroscope.format=jfr Java Flight Recorder format
pyroscope.profiler.event CPU sampling mode, set by the compose files (no automatic choice): itimer everywhere — perf_event_open is refused to a container without an extra capability, under Docker Desktop as on Linux with Docker's default settings (the cpu mode stopped the agent on Linux: measured on 2026-10-14)
pyroscope.profiler.alloc=512k Allocation profile: one sample every ~512 KB allocated
pyroscope.profiler.lock=10ms Contention profile: waits on a lock ≥ 10 ms only
pyroscope.profiling.interval=20ms CPU sampling every 20 ms — the agent prints it at startup: profilingInterval=PT0.02S

Name of the interval property

Agent 0.14.0 reads pyroscope.profiling.interval (derived from the environment variable PYROSCOPE_PROFILING_INTERVAL). The former -Dpyroscope.profilingInterval=PT0.02S was ignored: sampling stayed at 10 ms.

Profiles actually published

Measured (/querier.v1.QuerierService/Series, service_name="perfshop"):

Profile type Content
process_cpu:cpu:nanoseconds:cpu:nanoseconds CPU profile — the only CPU panel of the dashboards
memory:alloc_in_new_tlab_bytes:bytes:space:bytes · …_objects:count:space:bytes Sampled allocations (bytes, objects) — the only allocation type published by the agent, large arrays included (measured: 873 MB attributed to applyF3CatalogOom for a single F3 request, made of 8 MB arrays)
mutex:contentions:count:mutex:count · mutex:delay:nanoseconds:mutex:count JVM monitor (synchronized) contentions and wait time
block:* Occasional blocking (not used by the dashboards)

Profile type of the panels

A panel querying a type not published for perfshop (e.g. memory:alloc_objects:count:space:bytes or process_cpu:samples:count:cpu:nanoseconds) stays empty, without error. Both types do exist in Pyroscope: they come from the pyroscope service (Pyroscope's own profile). Check the list of types of the perfshop service before building a panel.

CPU profile

One CPU panel per APM dashboard, on process_cpu:cpu:nanoseconds:cpu:nanoseconds. The process_cpu:samples:count type is not published for perfshop: the former second panel ("itimer — empty on Linux") was always empty and has been removed.

CPU chaos (student level 1 = intensity 40, or the "CPU Overload" slider) — measured hot path: Thread.run → ThreadPoolExecutor$Worker.run → FutureTask.run → CpuChaosScheduler$$Lambda.run → CpuChaosScheduler.lambda$executeCpuChaos$0 → CpuChaosScheduler.busyLoop → MessageDigest.digest (SHA-256). Neither Tomcat nor ChaosInterceptor: CPU chaos runs on its own threads, not inside requests. The thread name does not appear as a frame.

Allocation profile

Panel "Allocations mémoire — profil d'allocation : F3, fuite, pression GC" of the Instructor APM dashboard (and Pyroscope UI, profile memory:alloc_in_new_tlab_bytes). Measured frames:

  • F3 (functional level 3, GET /api/products): FunctionalChaosService.applyF3CatalogOom;
  • memory leak (N2-05, "JVM Memory Leak" slider): MemoryLeakSimulator.leakMemory → MemoryLeakSimulator.allocate;
  • GC pressure (N2-06, "GC Pressure (sawtooth)" slider): GcPressureSimulator.pressureGc.

Lock contention profile

Panel "Contention de verrous" (Student and Instructor APM, profile mutex:contentions:count:mutex:count). The lock_contention lever ("Lock Contention" slider, scenario N3-07) routes the catalog read through a synchronized section held for up to 20 ms: under concurrent load, Tomcat threads wait for the monitor (BLOCKED state) and the profile shows ProductController.getAllProducts → LockContentionSimulator.applyToCatalogRead → holdCatalogLock (measured under load on the product list: 1,355 of the 1,425 contentions over 3 h; getProductById goes through the same lock, not measured). Only waits ≥ 10 ms are recorded (pyroscope.profiler.lock=10ms): without concurrency, the profile stays empty. Without this lever, the profile only contains JVM noise (class loading, technical threads).

Grafana datasource

- name: Pyroscope
  type: grafana-pyroscope-datasource
  uid: pyroscope
  access: proxy
  url: http://perfshop-pyroscope:4040
  isDefault: false
  editable: true

Reading a flamegraph — quick guide

Measured on 2026-09-25 under CPU chaos level 1, idle application (CPU profile, 2 min, 44.7 s of CPU i.e. 37% of one core):

flowchart TB
  R["Root (total)<br/>= 100% of CPU samples"]
  R --> M1["Thread.run → ThreadPoolExecutor → FutureTask.run<br/>98.9%"]
  R --> M2["JVM, GC, Tomcat<br/>~1%"]
  M1 --> M11["CpuChaosScheduler.busyLoop<br/>98.6%"]
  M11 --> M111["MessageDigest.digest (SHA-256)<br/>82% of busyLoop"]
  M11 --> M112["thread CPU clock (getAsLong)<br/>16% of busyLoop"]
Concept Reading
Width of a rectangle Share of samples (CPU, bytes, contentions) attributed to the method and its descendants
Height (vertical axis) Depth of the call stack
Stacking A method called by the method below
Left-to-right order Alphabetical — not chronological
Hot path The widest path from the root to a leaf

The classic mistake is to look at the height: only the width matters.

Volumes

Volume Mount Content
pyroscope-data (named volume) /data Ingester local blocks (/data/anonymous) and shared storage (/data/shared, 7-day retention)
./pyroscope/pyroscope-config.yml (bind mount) /etc/pyroscope/pyroscope-config.yml Configuration (read-only)

Ports

Service Host port Container port Env variable
perfshop-pyroscope — (Docker network) 4040 —
perfshop-welcome (read-only UI) 4040 4040 PYROSCOPE_HTTP_PORT

To go further

  • Overview — four observability signals
  • Grafana — Pyroscope datasource
  • Shipped dashboards — Flamegraph panels of the Student and Instructor APM dashboards
  • Tempo — the other agent embedded in the backend image
  • Performance Chaos — CPU, memory, GC pressure and lock contention levers