Self-Hosted eBPF Continuous Profiling for JVM and .NET: JIT Code Blame and Allocation Flame Graphs
Quick Summary (TL;DR)
- What: Run eBPF-based continuous profilers (Parca, Pyroscope, or Grafana Alloy) on your own infrastructure to capture CPU and allocation profiles for JVM and .NET workloads—without code changes or agent injection.
- Why: Kernel-level sampling gives near-zero overhead (<1–2% CPU), cross-runtime visibility, and the ability to “blame” JIT-compiled methods and GC pressure directly in flame graphs.
- How: Kernel 5.8+ (BTF/CO-RE), enable perf maps (
-XX:+PreserveFramePointerfor JVM,DOTNET_PerfMapEnabled=1for .NET), deploy the profiler as a DaemonSet, and wire profiles into Grafana.- Key gotcha: Missing method names almost always mean perf maps aren’t being emitted or the profiler can’t read
/tmp/perf-<pid>.map.
Introduction to eBPF Continuous Profiling
Continuous profiling answers a question batch profilers can’t: what has been consuming CPU—or allocating memory—for the last hour, day, or week, in production? Traditional profilers (JFR, async-profiler, dotnet-trace) answer that for a single process on demand. eBPF continuous profilers answer it for every process on every host, continuously, by sampling stack traces at the kernel level.
For JVM and .NET, the interesting twist is JIT code blame: managed runtimes compile hot methods into native code at runtime, so a raw native stack trace is meaningless until you map those addresses back to method names. eBPF profilers do this by reading runtime-emitted perf maps and, where available, DWARF/compiler-generated symbols.
This guide walks through a production-ready self-hosted deployment: choosing a profiler, meeting kernel prerequisites, configuring JVM and .NET symbol resolution, and building CPU and allocation flame graphs you can actually read.
Why eBPF for JVM and .NET?
Three properties make eBPF compelling for managed runtimes:
- Zero instrumentation. No
-javaagent, noDOTNET_tracing sidecar, no code changes. The profiler samples the kernel’sperf_eventstack traces. - Cross-runtime by default. One DaemonSet profiles JVM, .NET, Go, Python, and native code on the same node—useful in polyglot clusters.
- Low, tunable overhead. Sampling at 19–99 Hz typically costs 1–2% CPU. You trade resolution for cost with a single flag.
The trade-off: eBPF sees native stack frames. Method names only appear when the runtime publishes a perf map (/tmp/perf-<pid>.map) or when the profiler can resolve symbols from the binary. That’s the central configuration task below.
flowchart LR
A[Kernel perf_event<br/>sampler] --> B[eBPF program<br/>captures stack]
B --> C{Resolve symbols}
C -->|Native frames| D[ELF/DWARF<br/>symbols]
C -->|JIT frames| E[/tmp/perf-PID.map<br/>perf map]
E --> F[JVM or .NET<br/>method names]
D --> G[Profile: stack samples]
F --> G
G --> H[Backend<br/>Parca / Pyroscope]
H --> I[Grafana<br/>Flame Graph]
Choosing Your eBPF Profiler: Parca vs. Pyroscope vs. Grafana Alloy
| Feature | Parca | Pyroscope (Grafana) | Grafana Alloy (as collector) |
|---|---|---|---|
| Role | Full profiling backend + agent | Full profiling backend + agent | Agent/collector that forwards profiles |
| eBPF agent | Built-in (parca-agent) | Built-in (pyroscope ebpf) | pyroscope.ebpf component |
| Storage | Parca server (Parquet/object store) | Grafana Pyroscope (TSDB/object store) | Forwards to backend |
| Query UI | Parca UI + Grafana plugin | Grafana native (Explore → Profiles) | N/A (uses Grafana) |
| Best for | Self-contained, lightweight stacks | Teams already on Grafana/Loki | Centralized collection with existing Alloy |
| Symbol handling | Reads perf maps + DWARF | Reads perf maps + DWARF | Delegates to embedded agent |
Recommendation: If you already run Grafana, Pyroscope (or Alloy → Pyroscope) integrates most naturally. If you want a minimal, single-binary footprint, Parca is excellent. Alloy shines when you want one collector for metrics, logs, traces, and profiles.
Prerequisites and Kernel Requirements
- Kernel: 5.8+ strongly recommended (BTF + CO-RE support). 4.18+ works with fallbacks but expect friction.
- Distro: Ubuntu 20.04+, RHEL/Rocky 8+, Debian 11+.
- Capabilities:
CAP_BPF,CAP_PERFMON,CAP_SYS_ADMIN(or run privileged) on the DaemonSet. - Mounts:
/proc,/sys, and/tmp(for perf maps) must be visible to the profiler container—usehostPID: trueandhostPathmounts. - Managed runtimes: JVM 11+ and .NET 6+ for reliable perf-map support.
Verify BTF is present:
ls /sys/kernel/btf/vmlinux # should exist on 5.8+
uname -r
Deploying the eBPF Profiler
A minimal Pyroscope eBPF DaemonSet (Parca is analogous). Note hostPID, the /tmp mount for perf maps, and capabilities:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: pyroscope-ebpf
namespace: observability
spec:
selector:
matchLabels: { app: pyroscope-ebpf }
template:
metadata:
labels: { app: pyroscope-ebpf }
spec:
hostPID: true
containers:
- name: ebpf
image: grafana/pyroscope:latest
args: ["ebpf"]
securityContext:
privileged: true # or granular CAP_BPF/CAP_PERFMON
volumeMounts:
- { name: sys, mountPath: /sys }
- { name: proc, mountPath: /proc }
- { name: tmp, mountPath: /tmp } # perf maps live here
volumes:
- { name: sys, hostPath: { path: /sys } }
- { name: proc, hostPath: { path: /proc } }
- { name: tmp, hostPath: { path: /tmp } }
Once running, the agent auto-discovers JVM and .NET processes. Confirm it sees them:
kubectl -n observability logs ds/pyroscope-ebpf | grep -Ei 'jvm|dotnet|perf-map'
Configuring JVM Symbol Resolution
The JVM does not emit perf maps by default. Enable them at startup:
java -XX:+UnlockDiagnosticVMOptions \
-XX:+PreserveFramePointer \
-XX:+DumpPerfMapAtExit \
-jar app.jar
-XX:+PreserveFramePointerkeeps frame pointers intact so the kernel can walk stacks reliably.-XX:+DumpPerfMapAtExitwrites the map on exit; for continuous profiling you want periodic updates—useperf-map-agent(attach mode) or rely on the profiler’s own JVM symbolizer.
Verify the map exists and is readable:
ls -l /tmp/perf-$(pgrep -f app.jar).map
head -3 /tmp/perf-$(pgrep -f app.jar).map
# 7f3c1a2b0000 1c0 Lorg/example/Service;::handle
If the file is missing, the profiler will show raw hex addresses instead of org.example.Service::handle.
Configuring .NET Symbol Resolution
.NET Core/5+ emits perf maps when told to. Set the environment variable on the workload:
env:
- name: DOTNET_PerfMapEnabled
value: "1"
Optionally, DOTNET_EnableWriteXorExecute=0 can improve frame-walking on some kernels. Confirm the map:
ls -l /tmp/perf-$(pgrep -f MyApp.dll).map
# 7f9a... 2d0 MyApp.Services.OrderService::Process
With the map present, .NET JIT methods resolve to Namespace.Type::Method in flame graphs.
Building CPU Flame Graphs for GC Workloads
CPU profiles let you separate application work from GC work. In Grafana’s Flame Graph panel (Pyroscope data source), filter by process_name and look for GC frames:
| Frame pattern | Meaning | Action |
|---|---|---|
GCTaskThread::run / V8 GC | GC threads consuming CPU | Tune heap/GC flags |
ParNew/G1Young frames | Young-gen collections | Check allocation rate |
gen0/gen1/gen2 (.NET) | GC generation pressure | Reduce allocations |
JIT_Compile | JIT compilation overhead | Warm up, tiered compilation tuning |
A typical CPU flame graph for a GC-heavy JVM shows a wide GCTaskThread trunk next to application frames—if that trunk exceeds ~15–20% of samples, allocation reduction usually pays off more than CPU micro-tuning.
Building Allocation Flame Graphs
Allocation profiles trace kernel allocation paths (kmalloc, kmem_cache_alloc) and, where supported, runtime hooks. For managed runtimes these native allocations correlate strongly with managed allocation hotspots—strings, buffers, and object churn show up as wide trunks.
flowchart TD
A[Allocation event] --> B{Source}
B -->|Native| C[kmalloc / mmap]
B -->|JVM| D[TLAB / new object]
B -->|.NET| E[GC alloc context]
C --> F[Stack sample]
D --> F
E --> F
F --> G[Allocation flame graph]
G --> H[Blame hottest allocator]
Read allocation graphs top-down: the widest leaf frames are your allocation hot spots. Cross-reference with CPU graphs—an allocation hot spot that also burns CPU is a prime optimization target.
Interpreting JIT Code Blame
“JIT code blame” means attributing samples to specific JIT-compiled methods that only exist at runtime. Without perf maps you’d see 0x7f3c...; with them you see com.acme.Pricing::recalc. This matters because:
- Inlined & tiered code may not appear in static symbol tables.
- Hot methods are exactly what JIT optimizes—so they dominate profiles.
- Deoptimization events show as recompilation frames, hinting at polymorphic call sites.
Practical workflow: sort the flame graph by self-time, identify the top 5 JIT frames, then confirm with source or a targeted microbenchmark.
Performance Overhead and Tuning
| Sampling rate | CPU overhead | Use case |
|---|---|---|
| 19 Hz | ~0.5–1% | Always-on production |
| 49 Hz | ~1–2% | Default balance |
| 99 Hz | ~2–4% | Deep investigation |
| 199 Hz | 4%+ | Short bursts only |
Tune via the agent’s sampling-frequency flag (e.g., --profiling-frequency=49 for Parca, equivalent for Pyroscope). Also cap per-node memory (a few hundred MB) and stagger collection windows if you run many nodes.
Troubleshooting Common Issues
| Symptom | Likely cause | Fix |
|---|---|---|
| Hex addresses, no method names | Perf map missing/unreadable | Enable PreserveFramePointer/DOTNET_PerfMapEnabled; mount /tmp |
| No samples at all | Missing capabilities or hostPID | Add CAP_BPF/CAP_PERFMON, set hostPID: true |
| Kernel rejects eBPF program | Old kernel / no BTF | Upgrade to 5.8+, verify /sys/kernel/btf/vmlinux |
| High overhead | Sampling too high | Drop to 19–49 Hz |
.NET frames show [unknown] | Perf map disabled | Set DOTNET_PerfMapEnabled=1 and restart |
Conclusion
Self-hosted eBPF continuous profiling gives you production-grade CPU and allocation visibility for JVM and .NET without touching application code. The essentials: a modern kernel with BTF, a DaemonSet with the right capabilities and /tmp mounted, perf maps enabled on both runtimes, and flame graphs read with GC and JIT frames in mind. Start at 19 Hz in production, enable perf maps everywhere, and let the flame graphs tell you where to optimize.
Frequently Asked Questions
What are the system requirements for running eBPF continuous profiling?
Linux kernel 4.18+ (5.8+ recommended for BTF and CO-RE), a modern distro like Ubuntu 20.04+, RHEL 8+, or Debian 11+, and root or CAP_BPF/CAP_PERFMON capabilities. For JVM and .NET symbol resolution, ensure perf maps are enabled and readable.
How does eBPF profiling differ from traditional JVM profilers like JFR or async-profiler? eBPF profiling operates at the kernel level, capturing stack traces without code changes or JVM agents. It has lower overhead (typically <1–2% CPU) and works across all runtimes on the host. However, it may lack some language-specific details that JFR provides, such as exact object allocation sites.
Can I profile both JVM and .NET applications on the same host? Yes. Profilers like Parca and Pyroscope profile multiple runtimes simultaneously. They use different symbol resolution mechanisms for each runtime, so you can collect CPU and allocation profiles from both JVM and .NET processes on the same node.
Why are my JVM stack traces missing method names?
The JVM is not generating perf maps. Start it with -XX:+PreserveFramePointer and -XX:+UnlockDiagnosticVMOptions -XX:+DumpPerfMapAtExit (or use the perf-map-agent), and verify the profiler can read /tmp/perf-<pid>.map.
How do I resolve .NET symbols for eBPF profiling?
Set DOTNET_PerfMapEnabled=1 so the runtime emits /tmp/perf-<pid>.map files that eBPF profilers read to resolve JIT-compiled methods. Confirm the file exists and is readable by the profiler container.
What is JIT code blame and how is it useful? JIT code blame attributes CPU time or allocations to specific JIT-compiled methods. It helps identify hot methods optimized at runtime that might not appear in static symbol tables—crucial for understanding managed-runtime performance.
Can eBPF profiling capture allocation flame graphs?
Yes. By tracing kernel functions like kmalloc and kmem_cache_alloc, eBPF profilers capture allocation events and build flame graphs. For JVM and .NET, these native allocations often correlate with managed allocation hotspots.
Is eBPF profiling safe for production? Yes. eBPF programs are verified by the kernel for safety, and continuous profilers are designed for production use. They use sampling with bounded resource usage. Always test in staging first and monitor overhead.