Zum Inhalt springen

async-profiler - Low-Overhead JVM Profiler Cheatsheet

async-profiler - Low-Overhead JVM Profiler Cheatsheet

async-profiler ist ein Low-Overhead Sampling Profiler für die JVM. Traditionelle Java Profiler samplen nur bei Safepoints, was Ergebnisse zu großartig macht, was Code zu einer Safepoint mit sich bringt und die reale Hot Path verbergen kann. async-profiler nutzt AsyncGetCallTrace plus Perf Events zum Samplen überall, inkludierend Native Code und Kernel Frames, gebend ein viel ehrlicheres Bild. Es profiled CPU, Allocations, Lock Contention und mehr und exporte Flame Graphs oder JFR.

Installation

MethodeWie
DownloadGet das Release Tarball für deine Platform
Extracttar xzf async-profiler-*.tar.gz
Run./bin/asprof <pid> (neuer) oder ./profiler.sh <pid>
Permissionskann sysctl kernel.perf_event_paranoid=1 und kernel.kptr_restrict=0 benötigen
Verifikation./bin/asprof --version

Basis-Profiling

BefehlBeschreibung
asprof -d 30 -f out.html <pid>Profile 30s → Flame Graph
asprof -e alloc -d 30 -f alloc.html <pid>Allocation Profiling
asprof -e lock -d 30 -f lock.html <pid>Lock Contention
asprof -e wall -d 30 -f wall.html <pid>Wall-Clock (inkludiert Warten)
asprof start <pid> / asprof stop -f out.html <pid>Manual Start/Stop
jpsFinde die JVM PID

Event-Typen

EventMisst
cpuCPU-Zeit (Standard)
allocHeap Allocations nach Stack
lockLock/Monitor Contention
wallWall-Clock inkludierend Blocked Time
itimerFallback wenn Perf nicht verfügbar ist
cache-misses, page-faultsHardware/Software Perf Events
# Wo verbringt die App tatsächlich Wall-Clock-Zeit (inkl. IO Waits)?
./bin/asprof -e wall -t -d 30 -f wall.html <pid>

Output-Formate

FlagProduces
-f out.htmlInteractive Flame Graph
-o collapsedFolded Stacks (für FlameGraph Tooling)
-o treeCall Tree
-o flatFlat Hot-Method List
-f out.jfrJFR Recording (open in JMC)
-tSplit nach Thread

Launching Mit dem Agent

# Profile von JVM Startup (captures Warmup)
java -agentpath:/path/libasyncProfiler.so=start,event=cpu,file=profile.html \
  -jar app.jar
Agent-OptionZweck
startBegin sofort
event=cpu|alloc|lockWas zu samplen ist
file=NAMEOutput Path
interval=10msSampling Interval
jfrEmit JFR-Format

Lesen der Flame Graph

FeatureBedeutung
BreiteShare von Samples (Zeit) — Breiter ist Heißer
HöheStack-Tiefe, nicht Kosten
FarbenJava (Grün), Native (Gelblich), Kernel (Orange)
ClickZoom in eine Subtree
SearchHighlight Matching Frames

Look für Wide Plateaus — ein Single Frame, der einen großen Horizontal-Share konsumiert, ist dein Hot Spot. Mixed Java/Native/Kernel Frames sind genau das, was Safepoint-Biased Profiler verbergen.

Common Workflows

# 1) CPU Hotspots in einem Running Service
./bin/asprof -d 60 -f cpu.html $(jps | grep MyApp | cut -d' ' -f1)

# 2) Chasing GC Pressure — wer allocates den meisten?
./bin/asprof -e alloc -d 60 -f alloc.html <pid>

# 3) Threads schauen Idle aber Latency ist Hoch → Wall-Clock
./bin/asprof -e wall -t -d 30 -f wall.html <pid>

# 4) Contention auf einer Shared Resource
./bin/asprof -e lock -d 30 -f lock.html <pid>

async-profiler vs Alternativen

AspektAsync-ProfilerJFRVisualVM
Safepoint BiasVermiedenReduziertAnwesend
Native/Kernel FramesJaBegrenztNein
OverheadSehr NiedrigNiedrigHöher
Allocation ProfilingJaJaBasis
Am besten fürAccurate JVM HotspotsBuilt-in Continuous RecordingQuick GUI Inspection

Das JVM-Pendant zu perf + FlameGraph für Native Code.

Ressourcen