$ show async-profiler/async-profiler
async-profiler is a low-overhead sampling profiler for Java and native applications on Linux/macOS. It runs as a native JVM agent (libasyncProfiler.so/.dylib) loaded via -agentpath at JVM startup, or attached to a running JVM through its own C++ launcher `asprof` using an embedded jattach implementation. The core engine (src/profiler.cpp) orchestrates multiple sampling engines — perf_event_open-based CPU sampling, POSIX interval timers, wall-clock thread sampling, JVMTI allocation hooks with int3 breakpoint traps, and malloc/lock interception — then walks Java and native stacks using frame-pointer, DWARF, and HotSpot VMStructs-based unwinders. Sampled call traces are deduplicated in a lock-free CallTraceStorage and emitted as Java Flight Recorder (JFR) files, interactive HTML flame graphs, collapsed stacks, OpenTelemetry (OTLP) protobuf, pprof, or heatmaps. Architecturally this is a native library + CLI tool + standalone Java converter, not a service. The agent entry points are in src/vmEntry.cpp (JVMTI: Agent_OnLoad, Agent_OnAttach), the CLI in src/main/main.cpp, and the programmatic API in src/api/one/profiler/AsyncProfiler.java with a companion JMX MBean. A separate Java application (src/converter) parses JFR output — JfrReader.java is a full binary JFR parser — and transforms it into flame graphs, differential visualizations, heatmaps (using a custom LZ78-like tree plus Huffman encoding), and OTLP profiles. The codebase depends deeply on Linux kernel facilities (perf_event_open, /proc, signals) and on HotSpot internals such as AsyncGetCallTrace and hand-maintained VMStructs offset tables; the latter is the primary source of cross-JDK maintenance risk. Although the dominant character is a profiling tool/agent, the JFR converter and heatmap/flamegraph generators give the repo an analytical data-processing flavor that is embedded in the tool's output pipeline rather than a separate research workflow. Strengths: exceptional systems craftsmanship throughout — signal-safe memory allocation via raw syscalls, lock-free append-only dictionaries and linear allocators, a standalone Rust symbol demangler, a from-scratch protobuf wire-format writer, architecture-specific stack unwinders, and a self-contained test harness that spawns real JVMs. The project is actively maintained, runs integration tests across JDK 8–25 and multiple distributions in CI, and publishes nightly releases. Weaknesses are inherent to the domain: fragile hand-maintained JVM internals, heavy platform #ifdef sprawl across x64/aarch64/arm/ppc64/riscv64/loongarch64, some commented-out tests pending tiered CI re-enablement, and experimental features (OTLP output, --all multi-event mode) explicitly flagged unstable.
The LLM identified 6 files worth highlighting for reuse:
A standalone Rust symbol demangler supporting both v0 and legacy mangling schemes. It has no dependency on any profiler-specific state and parses Rust name mangling directly, making it trivially extractable into any tool that needs to symbolize Rust stack traces. Demonstrates non-obvious parsing craftsmanship for a notoriously complex name format.
An append-only concurrent hash table used to intern symbol, class, and method names during stack-trace aggregation. The design is lock-free for readers, safe for concurrent writers, and grows without invalidating existing buckets — a reusable pattern for any high-throughput logging, tracing, or deduplication subsystem where memory stability and concurrency matter.
A lock-free bump allocator designed for allocation-heavy, multi-threaded hot paths (call trace storage). It parcels out memory from pre-mapped arenas with atomic bump pointer arithmetic, avoiding malloc contention entirely. The abstraction is self-contained and directly reusable in any performance-critical trace or event-capture component.
A dependency-free protobuf wire-format writer implementing varints, length-delimited fields, and nested messages from scratch. It is decoupled from the profiler's output machinery and can be lifted into any project needing compact protobuf encoding without pulling in the full protobuf runtime. Demonstrates clean, low-level serialization engineering.
A complete standalone reader for the JDK Flight Recorder binary format — parsing chunk headers, constant pools, metadata, and typed event records. It is independent of async-profiler's native code and reusable as a library by any JVM tooling that needs to consume JFR files programmatically without the JDK's built-in FlightRecorder API. Non-obvious skill: reverse-engineering a complex evolving binary format with no external dependencies.
A self-contained Huffman coder used to compress heatmap/timeline profile data before embedding it into HTML output. It builds canonical Huffman tables and bit-writes compact streams; the same class could compress any frequency-distributed data payload. Combined with the LZ78-like LzNodeTree, it demonstrates a clever, dependency-free compression pipeline for embedded visualizations.