This reference is for AI agents and contributors working inside the AppleTrace repository. It summarizes how the project is organized, how to run and verify changes, and the expectations for contributions.
- AppleTrace instruments iOS apps so you can analyze performance hotspots with Chrome's tracing viewer.
- Developers can either add manual
APTBeginSection/APTEndSectionmarkers or hook everyobjc_msgSendvia HookZz (arm64 only). merge.py,scripts/appletrace_cli.py, Catapult'strace2html, and the helpergo.shscript transform sandbox data intotrace.jsonandtrace.html.- Releases bundle a loader tweaked for arm64, but the source can be rebuilt via the included Xcode projects.
appletrace/— Core framework sources (appletrace.xcodeproj, Objective-C runtime hooks, exported headers).loader/— Loader/packaging project plusresign.shfor re-signing the embeddedappletrace.framework.sample/ManualSectionDemoandsample/TraceAllMsgDemo— Xcode samples that show manual instrumentation and HookZz-based tracing.springboard/AppleTraceSpringBoard— Additional loader project for SpringBoard-focused experiments.hookzz/— Embedded HookZz dependency used to hookobjc_msgSend.go.sh,merge.py,scripts/appletrace_cli.py,get_catapult.sh— Scripts for merging trace files, converting them with Catapult, and downloading Catapult.sampledata/— Ready-made traces (trace.html) for verifying the visualization pipeline.release/— Notes and artifacts for the prebuilt loader (arm64 only).image/,wechat.png— Documentation assets.
- Clone & prerequisites
git clone https://github.com/everettjf/AppleTrace.git- Install Xcode, Python 3, Chrome, LLDB, and
ldid(for re-signing loader builds). - Optional:
python3 -m pip install -r requirements.txtfor local test tooling. - Run
sh get_catapult.shonce to fetch Catapult (catapult/tracing/bin/trace2htmlmust exist before generating HTML reports).
- Build instrumentation
- For manual tracing, open
appletrace/appletrace.xcodeproj, build the framework, and embed it into your target (seesample/ManualSectionDemo). - For automatic tracing, build the HookZz-based dynamic library (see
sample/TraceAllMsgDemo). This mode must run on arm64 under LLDB.
- For manual tracing, open
- Collect data
- Run the instrumented app; trace segments are written to
<app sandbox>/Library/appletracedata. - Pull the folder from the Simulator or device.
- Run the instrumented app; trace segments are written to
- Process traces
- Quick path:
sh go.sh <path-to-appletracedata>to run merge +trace2htmland open Chrome. - Manual path:
python3 merge.py -d <path>followed bypython3 catapult/tracing/bin/trace2html <path>/trace.json --output=<path>/trace.html. - Unified path:
python3 scripts/appletrace_cli.py all <path-to-appletracedata> --open.
- Quick path:
- Automated coverage exists for the Python trace merge pipeline:
python3 -m pytest tests
- Runtime and loader validation is still manual:
- Run the sample projects and confirm the generated
trace.json/trace.html. - Inspect traces in Chrome to ensure new instrumentation appears as expected.
- When touching the loader or HookZz code, test on a real arm64 device under LLDB.
- Run the sample projects and confirm the generated
- No dedicated Objective-C lint/format pipeline exists. Follow existing Objective-C/C/C++/Python conventions in the repo (clang/Xcode defaults, 4-space indentation in Python).
- Keep public headers tidy and update comments where behavior changes.
- Frameworks: Use
appletrace.xcodeprojtargets. Make sure exported headers remain inappletrace.framework. - Loader: After swapping in a rebuilt framework (
loader/AppleTraceLoader/Package/Library/Frameworks/appletrace.framework), runloader/resign.shto re-sign withldid. - Catapult: Keep the downloaded Catapult copy in sync if
trace2htmlchanges; document updates in README/AGENT when bumping instructions. - Deliverables: The
release/folder is arm64-only; highlight this in release notes and README when publishing new binaries.
- Prefer concise Objective-C with explicit
APTBeginSectionmarkers; avoid introducing new macros unless necessary. - Keep Objective-C source under
appletrace/src; Python utilities now live both at repo root (merge.py) and underscripts/for higher-level workflows. - Use descriptive section names inside traces to keep Chrome timelines meaningful.
- Use LLDB breakpoints around the HookZz injection points (
appletrace/src/objc/hook_objc_msgSend.m) when troubleshooting automatic tracing. - Inspect intermediate
trace.appletracefiles before merging to ensure data is written. - Open
chrome://tracingwithtrace.jsonto verify event ordering before generating HTML. - Compare against
sampledata/trace.htmlif output looks incorrect.
- Keep changes scoped: avoid mixing instrumentation updates with tooling refactors or documentation tweaks.
- Maintain compatibility with existing arm64-only assumption unless explicitly widening platform support.
- Update README/AGENT/wiki when changing workflows, scripts, or dependencies.
- Never remove diagnostic scripts (
merge.py,go.sh) without providing replacements. - Preserve existing assets (images, sample traces) so documentation stays accurate.
- Build the relevant Xcode targets (framework, loader, and/or samples) and ensure they run on device or Simulator.
- Run
python3 -m pytest testswhen touching Python tooling. - Run
python3 merge.py -d <path>(orsh go.sh <path>) against fresh trace data to confirm the pipeline still works. - Update
README.md/AGENT.mdif instructions changed; keep images/links in sync. - Re-sign loader artifacts with
loader/resign.shif the embedded framework changed. - Document manual testing performed (devices, iOS versions, Simulator).
- Ensure no unrelated files or formatting-only changes are included.