AppleTrace π
Discord
Repository: https://github.com/everettjf/appletrace
π Maintained as needed. AppleTrace captures your app's execution timeline β
manual sections, Swift macros, and/or every objc_msgSend β and renders it in
Perfetto, right in the browser. Version 2.0 adds a one-command appletrace CLI,
binary traces by default, async-safe Swift macros, and a rootless / roothide
jailbreak loader. See the CHANGELOG.

Table of Contents
π― What is AppleTrace?
AppleTrace is an iOS/macOS tracing toolkit. You instrument your app β with
manual APTBeginSection / APTEndSection markers, Swift @Traced macros, or by
hooking every objc_msgSend automatically β and AppleTrace records a timeline of
events into trace fragments in the app's sandbox. The appletrace command-line
tool pulls them off the device, merges them into a single trace.json, and opens
it in Perfetto to explore the call timeline,
durations, threads, and counters.

The trace visualization shows the method execution timeline and call relationships.
β¨ Key Features
- π Automatic method tracing β direct
objc_msgSend / objc_msgSendSuper2
rebinding on arm64 and arm64e captures Objective-C activity with no source
changes, including frameworks loaded later with dlopen.
- π§© Swift macros β
@Traced / @TraceAll instrument Swift at compile time
(final classes, structs, actors, protocol extensions). Names are qualified by
type (FeedViewModel.reload(force:)), and async functions get async spans,
so a call that resumes on another thread after await stays one slice.
- π― Manual sections β
APTBeginSection / APTEndSection (and the
APTBegin / APTEnd / APTScopeSection helpers) mark exactly the regions you
care about β the lowest-risk option, works on every OS version.
- π Rich event types β instant markers (
APTInstant), counter series
(APTCounter for memory, FPS, queue depth, β¦), and async/flow events
(APTAsyncBegin / APTAsyncEnd) that cross threads and dispatch queues.
- β‘ Built for the hot path β binary trace fragments by default,
(Class, SEL) name interning, pointer-cached name ids, and per-thread batched writing
keep malloc, string formatting and dispatch off the per-event path.
- πΎ Crash-tolerant capture β buffers drain to a memory-mapped file every
second, when the app enters the background, and at exit, so even a killed app
leaves a readable trace.
- π οΈ One-command workflow β
appletrace record launches the app on a
device, waits, stops it, pulls, merges, and opens Perfetto. No Python needed.
- π¦ Performance gates in CI β
appletrace summary reports per-span count,
total, self and p50/p95 times; appletrace diff compares them with a
baseline and exits non-zero when a span regressed.
- π Any app on a jailbroken device β an AppleTraceLoader tweak for rootless
and roothide jailbreaks, driven by
appletrace jb β¦ over SSH.
- π Runtime filtering β scope automatic tracing with class-prefix allow/deny
lists (
APPLETRACE_TRACE_CLASS_ALLOW / APPLETRACE_TRACE_CLASS_DENY).
Use Cases
- π Performance analysis β find hotspots and long methods on a real timeline.
- π Debugging β follow method execution flow across threads.
- π Learning β see how iOS/macOS frameworks actually dispatch.
- π‘οΈ Security research β analyze third-party app behavior on a jailbroken device.
β‘ Quick Start
git clone https://github.com/everettjf/AppleTrace.git
cd AppleTrace
swift build -c release --product appletrace # builds .build/release/appletrace
Prebuilt appletrace binaries, an appletrace.xcframework, and the jailbreak
packages are attached to each GitHub release.
Try the Demo App (fastest way to see a trace)
sample/AppleTraceSwiftDemo runs a curated, multi-threaded workload
(app-startup spans, parallel ImageDecoder / NetworkClient / DatabaseWriter
threads, async download arcs, Swift-concurrency @Traced async methods, and a
60-frame render loop with live FPS / memory counters).
open sample/AppleTraceSwiftDemo/AppleTraceSwiftDemo.xcodeproj # Run it on a device once to install it
# Then record it end to end β launch, wait, stop, pull, merge, open Perfetto:
swift run appletrace record --bundle-id com.everettjf.AppleTraceSwiftDemo \
--env APPLETRACE_AUTORUN=1 --open
On the Simulator, tap Generate Trace and run the `swift run appletrace open
` command the app shows.
Two samples are included:
| Sample |
Language |
Shows |
sample/AppleTraceSwiftDemo |
Swift |
withSpan + @Traced / @TraceAll macros (incl. async), counters / async spans, and the AppleTraceAuto SwiftTrace auto-hook |
sample/TraceAllMsgDemo |
Objective-C |
Manual APTBeginSection sections and the automatic objc_msgSend hook |
Mode A β Manual Instrumentation (recommended baseline)
#import <appletrace/appletrace.h>
- (void)yourMethod {
APTBegin; // section named "[ClassName yourMethod]"
// ... your code ...
APTEnd;
}
Mode B β Automatic objc_msgSend Hook (arm64 / arm64e)
APTInstallObjcMsgSendHook(); // or, from Swift: AppleTrace.installObjCMsgSendHook()
# β¦or without code changes, via environment variable (what `appletrace record --hook` sets):
export APPLETRACE_AUTO_HOOK_OBJC_MSGSEND=1
Capture & Visualize
# Development-signed app on a connected device:
swift run appletrace record --bundle-id com.example.MyApp --duration 15 --hook --open
# Or pull / merge / open separately:
swift run appletrace pull --bundle-id com.example.MyApp -o mytrace
swift run appletrace open mytrace
appletrace open hands the trace to ui.perfetto.dev
through a local page in your browser β the file is never uploaded. You can also
drag trace.json into Perfetto yourself.
π§ How It Works
Your app (instrumented) appletrace CLI (macOS) Browser
ββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββ ββββββββββββββββββ
β APTBeginSection / @Traced β β record / pull (devicectl,β β β
β APTInstant / APTCounter β ββββΊ β or SSH on jailbreak) β ββββΊ β ui.perfetto.devβ
β APTAsyncBegin / async spans β β merge β trace.json β β β
β objc_msgSend auto-hook β β open β local hand-off β β β
ββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββ ββββββββββββββββββ
per-thread batches β mmap'd X-complete collapse
<sandbox>/Library/appletracedata binary + text fragments
- Instrument β add manual markers or Swift macros, or install the
objc_msgSend hook.
- Capture β events accumulate in per-thread buffers, are shipped in order
to a serial writer, and land in memory-mapped binary fragments under
<app sandbox>/Library/appletracedata.
- Merge β
appletrace merge decodes the fragments and collapses
begin/end pairs into Perfetto X complete events.
- Visualize β
appletrace open loads trace.json into Perfetto.
π¦ Installation
Requirements
| Requirement |
Version |
Used for |
| macOS |
12+ |
Build environment and the appletrace CLI |
| Xcode |
16+ (Swift 6 toolchain) |
Package, framework, and samples |
| iOS / macOS deployment target |
iOS 15+ / macOS 12+ |
Apps that embed AppleTrace |
| Perfetto |
Web |
Visualization at ui.perfetto.dev |
| ldid, xz |
Optional |
Building the jailbreak packages |
| Python |
Optional, 3.9+ |
Legacy merge.py tooling and its tests |
Swift Package Manager
.package(url: "https://github.com/everettjf/appletrace.git", from: "2.1.0")
| Product |
What it is |
AppleTrace |
The C core + objc_msgSend hook, the Swift API, and the @Traced / @TraceAll macros |
AppleTraceAuto |
Optional SwiftTrace bridge (Simulator / macOS only) |
AppleTraceKit |
Fragment decoding and merging, for your own tooling |
appletrace |
The command-line tool |
Framework (Objective-C / Xcode)
Use the appletrace.xcframework from the release, or build the framework:
xcodebuild -project appletrace/appletrace.xcodeproj -scheme appletrace \
-configuration Release -sdk iphoneos build
The automatic hook supports arm64 and arm64e. arm64e replacements in
chained-fixup __auth_got slots are signed with the standard function-pointer
PAC schema. Simulator / Intel slices build a stub whose install call returns
NO.
π οΈ Usage
Manual Instrumentation
Objective-C
#import <appletrace/appletrace.h>
- (void)viewDidLoad {
APTBegin; // auto-named "[ClassName viewDidLoad]" (interned, no per-call allocation)
[super viewDidLoad];
APTEnd;
}
- (void)networkRequest {
APTBeginSection("network"); // explicit section name
// ... network code ...
APTEndSection("network");
}
C / C++
#include <appletrace/appletrace.h>
void saferCppFunction() {
APTScopeSection("processing"); // RAII: ends automatically at scope exit
APTScopeSection("inner"); // several per scope are fine
// ... C++ code ...
}
Tracing Swift (SwiftPM)
The objc_msgSend hook can't see Swift's static / vtable / witness dispatch, so
Swift is traced at the source level:
import AppleTrace
// Scoped span (closes even on throw / early return). String literals bind to a
// StaticString overload that passes the literal straight to the C core.
withSpan("loadFeed") { try? loadFeed() }
// Async work: an async span may begin and end on different threads.
let feed = try await withAsyncSpan("fetchFeed") { try await api.feed() }
// Annotate β the span name is qualified by type: "FeedViewModel.reload(force:)".
@TraceAll
final class FeedViewModel {
func reload(force: Bool) { /* traced */ }
func refresh() async throws { /* async span: survives thread hops at await */ }
@NotTraced func hotPath() { /* excluded */ }
}
@Traced("feed.decode") // explicit name
func decodeImage() { /* ... */ }
The runtime drains buffers every second, on backgrounding, and at exit; call
AppleTrace.flush() only when you read the trace in-process.
Want zero-annotation auto-tracing of a class hierarchy? The optional
AppleTraceAuto product bridges SwiftTrace:
import AppleTraceAuto
AppleTraceAuto.trace(aClass: FeedViewModel.self) // entry/exit β AppleTrace
AppleTraceAuto is Simulator / macOS only (SwiftTrace patches
pointer-authenticated vtable slots, unsafe on real devices β gate it with
#if targetEnvironment(simulator)), and it can't see final