---
title: "Magic-trace: Diagnosing tricky performance issues easily with Intel Processor Trace"
description: "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."
url: "https://swe.quest/articles/magic-trace-diagnosing-tricky-performance-issues-easily-with-intel-processor-bf89d988f02b1230"
canonical: "https://blog.janestreet.com/magic-trace/"
source: "Jane Street Tech Blog"
published: "2022-01-11"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 14
tags: ["performance","hardware","linux","debugging","functional-programming"]
---

# Magic-trace: Diagnosing tricky performance issues easily with Intel Processor Trace

A post on [Jane Street Tech Blog](https://swe.quest/sources/jane-street.md), published 2022-01-11, 14 min read, Deep dive. Original: [https://blog.janestreet.com/magic-trace/](https://blog.janestreet.com/magic-trace/)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Hardware](https://swe.quest/tags/hardware.md) (Infrastructure)
- [Linux](https://swe.quest/tags/linux.md) (Infrastructure)
- [Debugging](https://swe.quest/tags/debugging.md) (Engineering practices)
- [Functional programming](https://swe.quest/tags/functional-programming.md) (Languages)

## Prerequisites

- CPU profiling and tracing concepts ([easy posts on Hardware](https://swe.quest/tags/hardware.md?difficulty=easy))
- Linux perf tooling ([easy posts on Linux](https://swe.quest/tags/linux.md?difficulty=easy))
- function inlining

## Keywords

magic-trace, Intel Processor Trace, perf\_event\_open, libipt, Perfetto, OCaml, hardware breakpoints

## Related posts

- [Reverse debugging at scale](https://swe.quest/articles/reverse-debugging-at-scale-38ad4795201fdcca.md): Meta Engineering · 2021-04-27 · Hard · 7 min read · Debugging, Developer tools, Hardware, Linux, Performance engineering
  Meta continuously records Intel Processor Trace (Intel PT) data for all running processes in production, keeping it in a bounded circular buffer.
- [What the interns have wrought, 2022 edition](https://swe.quest/articles/what-the-interns-have-wrought-2022-edition-0f4dcf7e53f3e8d4.md): Jane Street Tech Blog · 2022-08-25 · Medium · 8 min read · Functional programming, Testing, Performance engineering, Developer tools, Engineering culture
  Three 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%.
- [Profiling in PyTorch (Part 1): A Beginner's Guide to torch.profiler](https://swe.quest/articles/profiling-in-pytorch-part-1-a-beginner-s-guide-to-torch-profiler-de0c791495fa22c4.md): Hugging Face · 2026-05-29 · Medium · 27 min read · Performance engineering, Machine learning, Python, Debugging
  torch.profiler produces two artifacts: a statistical table showing where time goes and a Chrome/Perfetto trace showing when CPU and GPU events happen.
- [Testing race conditions with memory access tracing and stack-based delay injection](https://swe.quest/articles/testing-race-conditions-with-memory-access-tracing-and-stack-based-delay-a9851e9c2152e266.md): Google Project Zero · 2026-09-08 · Hard · 16 min read · Concurrency, Linux, Vulnerability research, Testing, Debugging
  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.
- [The case of the vanishing CPU: A Linux kernel debugging story](https://swe.quest/articles/the-case-of-the-vanishing-cpu-a-linux-kernel-debugging-story-3db1aa1b81ec8319.md): ClickHouse · 2025-03-05 · Hard · 32 min read · Linux, Memory management, Debugging, Performance engineering, Incidents & postmortems
  Intermittent, indefinite CPU saturation of ClickHouse Cloud pods, seen only on GCP, turned out to be a Linux kernel memory-management livelock.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
