Continuous profiling agent for Java applications. Integrates with Pyroscope / Grafana Profiles to collect CPU, allocation, and lock contention profiles with minimal overhead.
Built on top of async-profiler.
- Features
- Distribution
- Quick Start
- Installation
- Configuration
- Labels & Context
- OpenTelemetry Integration
- Profiler Types
- Building from Source
- Examples
- Maintainers
- CPU profiling via async-profiler (Linux x64/ARM64, macOS x64/ARM64)
- Windows support via JVM Flight Recorder (JFR)
- Allocation profiling — track heap allocations above a configurable threshold
- Lock contention profiling — identify threads blocked on monitors
- Dynamic labels — annotate profiles with per-request metadata (user ID, request ID, etc.)
- OpenTelemetry integration — correlate profiles with traces via
trace_id/span_id - Zero-code-change setup — attach as a JVM agent with no application modifications needed
- Programmatic API — start/stop profiling and set labels from application code
The agent is distributed as a single JAR file pyroscope.jar that bundles native async-profiler libraries for:
- Linux x64
- Linux ARM64
- macOS x64
- macOS ARM64
On Windows, the agent falls back to the JVM built-in JFR profiler automatically.
Download the latest release from the releases page.
java -javaagent:pyroscope.jar \ -DPYROSCOPE_APPLICATION_NAME=my-app \ -DPYROSCOPE_SERVER_ADDRESS=http://localhost:4040 \ -jar myapp.jar
That's it — the agent starts profiling and uploads data to your Pyroscope server every 10 seconds.
Attach the agent at startup using the -javaagent flag:
java -javaagent:/path/to/pyroscope.jar \ -DPYROSCOPE_APPLICATION_NAME=my-service \ -DPYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040 \ -jar myapp.jar
Create a pyroscope.properties file:
PYROSCOPE_APPLICATION_NAME=my-service PYROSCOPE_SERVER_ADDRESS=http://localhost:4040 PYROSCOPE_PROFILER_EVENT=itimer PYROSCOPE_PROFILING_INTERVAL=10ms PYROSCOPE_UPLOAD_INTERVAL=10s PYROSCOPE_LOG_LEVEL=info
Then reference it at startup:
java -javaagent:pyroscope.jar \ -Dpyroscope.config=/path/to/pyroscope.properties \ -jar myapp.jar
import io.pyroscope.javaagent.PyroscopeAgent; import io.pyroscope.javaagent.config.Config; import io.pyroscope.javaagent.EventType; Config config = new Config.Builder() .setApplicationName("my-service") .setServerAddress("http://localhost:4040") .setProfilingEvent(EventType.ITIMER) .build(); PyroscopeAgent.start(config); // ... your application runs ... PyroscopeAgent.stop();
Configuration is resolved in the following priority order:
- System properties (
-Dproperty=value) - Environment variables (
PYROSCOPE_*) - Properties file (
-Dpyroscope.config=/path/to/file) - Defaults
| Variable | Default | Description |
|---|---|---|
PYROSCOPE_APPLICATION_NAME |
(required) | Application name shown in Pyroscope UI |
PYROSCOPE_SERVER_ADDRESS |
http://localhost:4040 |
Pyroscope server endpoint |
PYROSCOPE_AGENT_ENABLED |
true |
Enable or disable the agent |
PYROSCOPE_LOG_LEVEL |
info |
Log verbosity: debug, info, warn, error |
| Variable | Default | Description |
|---|---|---|
PYROSCOPE_PROFILER_TYPE |
ASYNC |
Profiler backend: ASYNC or JFR |
PYROSCOPE_PROFILER_EVENT |
ITIMER |
CPU profiling event: ITIMER, CTIMER, CPU |
PYROSCOPE_PROFILING_INTERVAL |
10ms |
Sampling frequency |
PYROSCOPE_PROFILER_ALLOC |
(disabled) | Allocation tracking threshold (e.g. 512k) |
PYROSCOPE_PROFILER_LOCK |
(disabled) | Lock contention threshold (e.g. 10ms) |
PYROSCOPE_JAVA_STACK_DEPTH_MAX |
2048 |
Maximum stack trace depth |
| Variable | Default | Description |
|---|---|---|
PYROSCOPE_UPLOAD_INTERVAL |
10s |
How often to upload profiles |
PYROSCOPE_FORMAT |
JFR |
Export format: JFR or PPROF |
PYROSCOPE_PUSH_QUEUE_CAPACITY |
8 |
In-memory snapshot buffer size |
PYROSCOPE_INGEST_MAX_TRIES |
8 |
Upload retry attempts (exponential backoff) |
PYROSCOPE_PROFILE_EXPORT_TIMEOUT |
10s |
Timeout per upload request |
| Variable | Default | Description |
|---|---|---|
PYROSCOPE_AUTH_TOKEN |
(optional) | Bearer token for Grafana Cloud |
PYROSCOPE_BASIC_AUTH_USER |
(optional) | Basic auth username |
PYROSCOPE_BASIC_AUTH_PASSWORD |
(optional) | Basic auth password |
Attach fixed key-value metadata to all profiles from this instance:
-DPYROSCOPE_LABELS=env=production,region=us-east-1,version=2.1.0
Labels allow you to slice profiles by arbitrary dimensions in the Pyroscope UI — for example, by request ID, user ID, or endpoint.
Set once at startup, applied to all profiles:
import io.pyroscope.labels.v2.Pyroscope; Pyroscope.setStaticLabels(Map.of( "region", "us-east-1", "version", "2.1.0" ));
Use ScopedContext to attach labels for the duration of a code block. Labels are removed automatically when the block exits.
import io.pyroscope.labels.v2.ScopedContext; import io.pyroscope.labels.v2.LabelsSet; // Try-with-resources (recommended) try (ScopedContext ctx = new ScopedContext( new LabelsSet("request_id", "abc123", "user_id", "42"))) { handleRequest(); } // labels removed here // Or with a lambda Pyroscope.LabelsWrapper.run( new LabelsSet("endpoint", "/checkout"), () -> processCheckout() );
For contexts that outlive a single request:
ConstantContext ctx = Pyroscope.LabelsWrapper.registerConstant("worker-thread-1"); // ... later ... ctx.close();
The agent can inject trace_id and span_id into profiles so you can jump from a slow trace span directly to the matching flame graph in Pyroscope.
Download pyroscope-otel-extension.jar from the releases page, then add it to the OpenTelemetry Java agent:
java \ -javaagent:opentelemetry-javaagent.jar \ -Dotel.javaagent.extensions=pyroscope-otel-extension.jar \ -DPYROSCOPE_APPLICATION_NAME=my-traced-service \ -DPYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040 \ -jar myapp.jar
No code changes are required. The PyroscopeSpanProcessor automatically injects trace context into each profile sample.
If you manage spans manually:
import io.pyroscope.otel.PyroscopeSpanProcessor; SdkTracerProvider provider = SdkTracerProvider.builder() .addSpanProcessor(new PyroscopeSpanProcessor()) .build();
Uses async-profiler via native JNI. Provides accurate CPU profiling without safepoint bias. Supports:
ITIMER— interval timer (default, works without root)CTIMER— CPU timer (better accuracy on some systems)CPU— perf_events based (requiresperf_event_paranoid=1)
Uses the JVM built-in Java Flight Recorder. Works on all platforms but requires Java 11+. Enable explicitly:
-DPYROSCOPE_PROFILER_TYPE=JFR
You can supply a custom JFR configuration file:
-DPYROSCOPE_JFR_PROFILER_SETTINGS=/path/to/custom.jfc
- JDK 8+ (JDK 11+ required for the demo/OTel module)
- Gradle (wrapper included)
./gradlew shadowJar
Output: agent/build/libs/pyroscope.jar
./gradlew :demo:shadowJar
Output: demo/build/libs/pyroscope-otel-extension.jar
./gradlew testmake itest
A complete example with a demo app and Pyroscope server:
services: pyroscope: image: grafana/pyroscope:latest ports: - "4040:4040" app: image: my-java-app environment: PYROSCOPE_APPLICATION_NAME: my-app PYROSCOPE_SERVER_ADDRESS: http://pyroscope:4040 PYROSCOPE_PROFILER_EVENT: itimer PYROSCOPE_PROFILING_INTERVAL: 10ms
See the examples/ directory for complete Docker Compose configurations.
Track heap allocations to find GC pressure:
java -javaagent:pyroscope.jar \ -DPYROSCOPE_APPLICATION_NAME=my-app \ -DPYROSCOPE_PROFILER_ALLOC=512k \ -jar myapp.jar
Find threads blocked waiting for monitors:
java -javaagent:pyroscope.jar \ -DPYROSCOPE_APPLICATION_NAME=my-app \ -DPYROSCOPE_PROFILER_LOCK=10ms \ -jar myapp.jar
java -javaagent:pyroscope.jar \ -DPYROSCOPE_APPLICATION_NAME=my-app \ -DPYROSCOPE_SERVER_ADDRESS=https://profiles-prod-001.grafana.net \ -DPYROSCOPE_AUTH_TOKEN=<your-grafana-cloud-token> \ -jar myapp.jar
This package is maintained by @grafana/pyroscope-java. Mention this team on issues or PRs for feedback.