Magic-trace: Diagnosing tricky performance issues easily with Intel Processor Trace
Magic-trace is an open-source tool that uses Intel Processor Trace in circular-buffer mode to capture roughly the last 10ms of execution before a chosen function call, then renders every function call on a nanosecond-resolution timeline in a forked Perfetto UI. Processor Trace records full control flow with about 30ns timing at 2-20% overhead and needs no instrumentation, which suits latency problems far shorter than a sampling profiler's 250µs interval. The build went from wrapping `perf` to using perf_event_open with libipt directly, and hardware breakpoints let it trigger snapshots on any function without the target's cooperation. Along the way it hit a kernel null-pointer bug and a suspected Skylake erratum, and it has already diagnosed 100ns inlining regressions and long Async cycles.
Related posts
- Reverse debugging at scale
Meta Engineering hardMasterMeta continuously records Intel Processor Trace (Intel PT) data for all running processes in production, keeping it in a bounded circular buffer. An eBPF kernel probe notifies the collector within milliseconds of a crash, so the crashed process's trace is saved before other processes overwrite it. Traces and binaries are stored for offline analysis, where an LLDB plugin decodes taken and not-taken branches against the binary, symbolicates the executed instructions, and builds a function call tree that makes reverse-step-over and reverse breakpoints cheap. The same timestamped traces also support latency analysis that sampled call stacks miss, with visualization planned for Meta's Tracery tool and VSCode.
- What the interns have wrought, 2022 edition
Jane Street Tech Blog mediumAdeptThree Jane Street intern projects from 2022 show substantial tooling work in OCaml. magic-trace gained a sampling mode that can cover 20 seconds to 20 minutes on Intel or AMD hardware, plus multi-process tracing, CPU-frequency transition reporting and a perf dlfilter backend that speeds trace decoding by 10–50%. Datafetcher jobs can now be compiled into Incremental computations, using a Response_or_waiting type to represent async state and mandatory memoization of fetch nodes. Quickcheck gained a [@@contract] syntax for deriving property tests from interface signatures, along with early support for bisimulation testing of two implementations of the same API.
- Profiling in PyTorch (Part 1): A Beginner's Guide to torch.profiler
Hugging Face mediumAdepttorch.profiler produces two artifacts: a statistical table showing where time goes and a Chrome/Perfetto trace showing when CPU and GPU events happen. A small 64x64 bf16 matmul+add is overhead-bound, with GPU time under 1% of CPU time, while 4096x4096 matrices shift the work to compute-bound GEMM kernels. The trace walkthrough explains a cold-start dead window of about 228 µs before aten::matmul dispatch, a CPU-GPU lane offset, gaps caused by profiler Activity Buffer Requests, and the dispatch chain from Python down to CUDA kernels. The practical advice is to warm up, use profiler schedules, and read Self versus total times carefully before turning to torch.compile.
- Testing race conditions with memory access tracing and stack-based delay injection
Google Project Zero hardMaster
MAccConc is a set of tools for exploring thread interleavings of multi-threaded Linux kernel test cases to confirm, regression-test and eventually fuzz race condition bugs. It records memory accesses via KASAN outline instrumentation fed through KCOV, finds communication points (overlapping accesses where at least one is a write), and identifies accesses stably across runs with count-augmented stack traces built from a new LLVM SanitizerCoverage function entry/exit feature. A new KCOV_SET_DI ioctl injects wait/wake actions at specific accesses, supporting both happens-before constraints and fully specified context-switch orderings. An automatic A-B-A interleaving tester, a terminal UI and a GUI are demonstrated on a dup-vs-close race.
- The case of the vanishing CPU: A Linux kernel debugging story
ClickHouse hardMaster
Intermittent, indefinite CPU saturation of ClickHouse Cloud pods, seen only on GCP, turned out to be a Linux kernel memory-management livelock. Pods sat just under their cgroup memory limit while every CPU spun in shrink_lruvec during memcg reclaim triggered by page-cache readahead on page faults. The investigation used gdb backtraces, bpftrace syscall latency histograms, perf top/stat, pidstat and an on-call runbook to reach a reproducible test case and a kernel fix, after which another kernel bug surfaced. One lesson along the way: signal-based user-space stack traces hide kernel time entirely, so gdb backtraces pointed the team at the wrong code.