Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions AGENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This reference is for AI agents and contributors working inside the AppleTrace r
## Repository Map
- `appletrace/` — Core framework sources (`appletrace.xcodeproj`, Objective-C runtime hooks, exported headers).
- `loader/` — Loader/packaging project plus `resign.sh` for re-signing the embedded `appletrace.framework`.
- `sample/ManualSectionDemo` and `sample/TraceAllMsgDemo` — Objective-C Xcode samples that show manual instrumentation and automatic `objc_msgSend` tracing.
- `sample/TraceAllMsgDemo` — Objective-C Xcode sample showing both manual instrumentation (`APTBeginSection`) and automatic `objc_msgSend` tracing.
- `sample/AppleTraceSwiftDemo` — Swift sample (SwiftUI) that consumes the local SwiftPM package and demonstrates both Swift routes: the `@Traced`/`@TraceAll`/`withSpan` macros and the `AppleTraceAuto` SwiftTrace bridge. Build with `-destination` only (no `-sdk`, which would force the macro plugin onto the wrong SDK).
- `springboard/AppleTraceSpringBoard` — Additional loader project for SpringBoard-focused experiments.
- `hookzz/` — Legacy embedded HookZz dependency (the current `objc_msgSend` hook uses a direct symbol rebind instead).
Expand All @@ -27,8 +27,8 @@ This reference is for AI agents and contributors working inside the AppleTrace r
- Optional: `python3 -m pip install -r requirements.txt` for local test tooling.
- Visualization is browser-based at [ui.perfetto.dev](https://ui.perfetto.dev); nothing to download.
2. **Build instrumentation**
- For manual tracing, open `appletrace/appletrace.xcodeproj`, build the framework, and embed it into your target (see `sample/ManualSectionDemo`).
- For automatic tracing, build the dynamic library (see `sample/TraceAllMsgDemo`). This mode runs on arm64 under LLDB.
- For Objective-C (manual sections and/or the `objc_msgSend` hook), open `appletrace/appletrace.xcodeproj`, build the framework, and embed it into your target (see `sample/TraceAllMsgDemo`).
- For Swift, add the SwiftPM package and use the `@Traced`/`@TraceAll`/`withSpan` macros (see `sample/AppleTraceSwiftDemo`).
3. **Collect data**
- Run the instrumented app; trace segments are written to `<app sandbox>/Library/appletracedata`.
- Pull the folder from the Simulator or device.
Expand Down
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,16 @@ python3 -m pip install -r requirements.txt

### Try the Demo App (fastest way to see a trace)

`sample/ManualSectionDemo` is a self-contained showcase. Open it in Xcode,
`sample/AppleTraceSwiftDemo` is a self-contained showcase. Open it in Xcode,
run it on a Simulator (or device), and tap **Generate Trace** — it runs a
curated, multi-threaded workload (app-startup sections, parallel
curated, multi-threaded workload (app-startup spans, parallel
`ImageDecoder` / `NetworkClient` / `DatabaseWriter` threads, async download
arcs, a 60-frame render loop with live FPS / memory counters) and writes a
complete trace. The screen then shows the on-disk trace directory and the
exact commands to merge and open it in Perfetto.

```bash
open sample/ManualSectionDemo/ManualSectionDemo.xcodeproj # then Run + tap "Generate Trace"
open sample/AppleTraceSwiftDemo/AppleTraceSwiftDemo.xcodeproj # then Run + tap "Generate Trace"

# The app prints the trace directory; merge it and open Perfetto:
python3 merge.py -d "<trace directory shown in the app>" # → trace.json
Expand All @@ -130,13 +130,12 @@ app container first (Xcode ▸ *Window ▸ Devices and Simulators ▸ Download
Container*, or `xcrun devicectl device copy from …`) — the app shows the full
command.

Three samples are included:
Two samples are included:

| Sample | Language | Shows |
|--------|----------|-------|
| `sample/ManualSectionDemo` | Objective-C | Manual `APTBeginSection` sections, counters, async, threads |
| `sample/AppleTraceSwiftDemo` | Swift | `@Traced` / `@TraceAll` / `withSpan` macros **and** the `AppleTraceAuto` SwiftTrace auto-hook |
| `sample/TraceAllMsgDemo` | Objective-C | Automatic `objc_msgSend` hook |
| `sample/AppleTraceSwiftDemo` | Swift | `withSpan` + `@Traced` / `@TraceAll` macros, counters / async, **and** the `AppleTraceAuto` SwiftTrace auto-hook |
| `sample/TraceAllMsgDemo` | Objective-C | Manual `APTBeginSection` sections **and** the automatic `objc_msgSend` hook |

The Swift demo consumes the local SwiftPM package, so open it from the repo
root (`open sample/AppleTraceSwiftDemo/AppleTraceSwiftDemo.xcodeproj`) and Xcode
Expand Down Expand Up @@ -233,8 +232,8 @@ xcodebuild -project appletrace/appletrace.xcodeproj -scheme appletrace \
> deliberately fails to compile for arm64e. Build a plain arm64 slice.

Embed the resulting `appletrace.framework` into your target (see
`sample/ManualSectionDemo` for manual mode and `sample/TraceAllMsgDemo` for the
auto-hook). For injecting into third-party apps, see the `loader/` project and
`sample/TraceAllMsgDemo` for both manual sections and the auto-hook). For
injecting into third-party apps, see the `loader/` project and
run `loader/resign.sh` after swapping in a rebuilt framework.

---
Expand Down Expand Up @@ -452,8 +451,8 @@ AppleTrace/
│ └── appletrace/src/ # Framework source + objc_msgSend hook
├── loader/ # Dynamic library loader + resign.sh
├── sample/
│ ├── ManualSectionDemo/ # Manual instrumentation demo
│ └── TraceAllMsgDemo/ # Automatic objc_msgSend hook demo
│ ├── AppleTraceSwiftDemo/ # Swift demo: macros + SwiftTrace auto-hook
│ └── TraceAllMsgDemo/ # Objective-C demo: manual + objc_msgSend hook
├── scripts/ # CLI + smoke/stress test scripts
│ └── appletrace_cli.py # Merge + open-in-Perfetto CLI
├── docs/ # Binary format & batching design notes
Expand Down
21 changes: 10 additions & 11 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ python3 -m pip install -r requirements.txt

### 体验 Demo App(最快看到一条 trace)

`sample/ManualSectionDemo` 是一个开箱即用的示例。用 Xcode 打开,在模拟器
`sample/AppleTraceSwiftDemo` 是一个开箱即用的示例。用 Xcode 打开,在模拟器
(或真机)上运行,点击 **Generate Trace** 按钮——它会跑一段精心设计的多线程
工作负载(App 启动 section、并行的 `ImageDecoder` / `NetworkClient` /
工作负载(App 启动 span、并行的 `ImageDecoder` / `NetworkClient` /
`DatabaseWriter` 线程、async 下载弧、带实时 FPS / 内存 counter 的 60 帧渲染
循环)并写出一条完整的 trace。界面随后会显示磁盘上的 trace 目录,以及合并并在
Perfetto 中打开它的完整命令。

```bash
open sample/ManualSectionDemo/ManualSectionDemo.xcodeproj # 运行后点击 "Generate Trace"
open sample/AppleTraceSwiftDemo/AppleTraceSwiftDemo.xcodeproj # 运行后点击 "Generate Trace"

# App 会显示 trace 目录;合并它并打开 Perfetto:
python3 merge.py -d "<App 中显示的 trace 目录>" # → trace.json
Expand All @@ -123,13 +123,12 @@ sh go.sh "<App 中显示的 trace 目录>"
Devices and Simulators ▸ Download Container*,或 `xcrun devicectl device
copy from …`)——App 内会显示完整命令。

仓库内含三个示例
仓库内含两个示例

| 示例 | 语言 | 演示内容 |
|------|------|---------|
| `sample/ManualSectionDemo` | Objective-C | 手动 `APTBeginSection`、counter、async、多线程 |
| `sample/AppleTraceSwiftDemo` | Swift | `@Traced` / `@TraceAll` / `withSpan` 宏,**以及** `AppleTraceAuto` 的 SwiftTrace 自动 hook |
| `sample/TraceAllMsgDemo` | Objective-C | 自动 `objc_msgSend` hook |
| `sample/AppleTraceSwiftDemo` | Swift | `withSpan` + `@Traced` / `@TraceAll` 宏、counter / async,**以及** `AppleTraceAuto` 的 SwiftTrace 自动 hook |
| `sample/TraceAllMsgDemo` | Objective-C | 手动 `APTBeginSection` section **以及**自动 `objc_msgSend` hook |

Swift demo 依赖本地 SwiftPM 包,从仓库根目录打开
(`open sample/AppleTraceSwiftDemo/AppleTraceSwiftDemo.xcodeproj`),Xcode 会自动
Expand Down Expand Up @@ -224,8 +223,8 @@ xcodebuild -project appletrace/appletrace.xcodeproj -scheme appletrace \
> AppleTrace **仅支持 arm64**。arm64e 不在范围内:自动 hook 需要重绑定经过指针认证的
> GOT 表项,因此 hook 源码在 arm64e 下会刻意编译失败。请构建纯 arm64 slice。

把生成的 `appletrace.framework` 嵌入你的目标(手动模式见 `sample/ManualSectionDemo`,
自动 hook 见 `sample/TraceAllMsgDemo`)。注入第三方 App 见 `loader/` 工程,替换重新
把生成的 `appletrace.framework` 嵌入你的目标(手动 section 与自动 hook 都见
`sample/TraceAllMsgDemo`)。注入第三方 App 见 `loader/` 工程,替换重新
构建的 framework 后运行 `loader/resign.sh`。

---
Expand Down Expand Up @@ -435,8 +434,8 @@ AppleTrace/
│ └── appletrace/src/ # framework 源码 + objc_msgSend hook
├── loader/ # 动态库 loader + resign.sh
├── sample/
│ ├── ManualSectionDemo/ # 手动埋点示例
│ └── TraceAllMsgDemo/ # 自动 objc_msgSend hook 示例
│ ├── AppleTraceSwiftDemo/ # Swift 示例:宏 + SwiftTrace 自动 hook
│ └── TraceAllMsgDemo/ # OC 示例:手动 + objc_msgSend hook
├── scripts/ # CLI + smoke/压测脚本
│ └── appletrace_cli.py # 合并 + 打开 Perfetto 的 CLI
├── docs/ # 二进制格式与批量写入设计说明
Expand Down
9 changes: 4 additions & 5 deletions Tutorial/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ <h3>Swift Package (for Swift, and the cleanest path for new projects)</h3>
]</code></pre></div>

<h3>Framework embedding (Objective-C / C / C++)</h3>
<p>Open <code>appletrace/appletrace.xcodeproj</code>, build the framework, and embed <code>appletrace.framework</code> into your target. See <code>sample/ManualSectionDemo</code> for a working setup.</p>
<p>Open <code>appletrace/appletrace.xcodeproj</code>, build the framework, and embed <code>appletrace.framework</code> into your target. See <code>sample/TraceAllMsgDemo</code> for a working setup.</p>
</section>

<!-- MANUAL -->
Expand Down Expand Up @@ -282,12 +282,11 @@ <h3>Binary fragments (optional, smaller &amp; faster)</h3>
<!-- DEMOS -->
<section id="demos">
<h2>Demo Apps</h2>
<p>Three runnable samples, each a complete reference:</p>
<p>Two runnable samples, each a complete reference:</p>
<table>
<tr><th>Sample</th><th>Language</th><th>Demonstrates</th></tr>
<tr><td><code>sample/ManualSectionDemo</code></td><td>Objective-C</td><td>Manual sections, counters, async, threads</td></tr>
<tr><td><code>sample/AppleTraceSwiftDemo</code></td><td>Swift</td><td><code>@Traced</code>/<code>@TraceAll</code>/<code>withSpan</code> + the <code>AppleTraceAuto</code> hook</td></tr>
<tr><td><code>sample/TraceAllMsgDemo</code></td><td>Objective-C</td><td>Automatic <code>objc_msgSend</code> hook</td></tr>
<tr><td><code>sample/AppleTraceSwiftDemo</code></td><td>Swift</td><td><code>withSpan</code> + <code>@Traced</code>/<code>@TraceAll</code> macros, counters/async, and the <code>AppleTraceAuto</code> hook</td></tr>
<tr><td><code>sample/TraceAllMsgDemo</code></td><td>Objective-C</td><td>Manual <code>APTBeginSection</code> sections and the automatic <code>objc_msgSend</code> hook</td></tr>
</table>
<p>Each guided app has a <strong>Generate Trace</strong> button, shows the trace directory, and prints the exact merge/Perfetto commands. The Swift demo consumes the local package, so open it from the repo so Xcode resolves the products automatically.</p>
</section>
Expand Down
7 changes: 3 additions & 4 deletions Tutorial/zh.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ <h3>Swift Package(Swift 项目,也是新项目最干净的方式)</h3>
]</code></pre></div>

<h3>嵌入 framework(Objective-C / C / C++)</h3>
<p>打开 <code>appletrace/appletrace.xcodeproj</code> 构建 framework,把 <code>appletrace.framework</code> 嵌入你的 target。可参考 <code>sample/ManualSectionDemo</code>。</p>
<p>打开 <code>appletrace/appletrace.xcodeproj</code> 构建 framework,把 <code>appletrace.framework</code> 嵌入你的 target。可参考 <code>sample/TraceAllMsgDemo</code>。</p>
</section>

<section id="manual">
Expand Down Expand Up @@ -261,9 +261,8 @@ <h3>二进制片段(可选,更小更快)</h3>
<h2>示例 App</h2>
<table>
<tr><th>示例</th><th>语言</th><th>演示</th></tr>
<tr><td><code>sample/ManualSectionDemo</code></td><td>Objective-C</td><td>手动 section、counter、async、多线程</td></tr>
<tr><td><code>sample/AppleTraceSwiftDemo</code></td><td>Swift</td><td><code>@Traced</code>/<code>@TraceAll</code>/<code>withSpan</code> + <code>AppleTraceAuto</code> hook</td></tr>
<tr><td><code>sample/TraceAllMsgDemo</code></td><td>Objective-C</td><td>自动 <code>objc_msgSend</code> hook</td></tr>
<tr><td><code>sample/AppleTraceSwiftDemo</code></td><td>Swift</td><td><code>withSpan</code> + <code>@Traced</code>/<code>@TraceAll</code> 宏、counter/async,以及 <code>AppleTraceAuto</code> hook</td></tr>
<tr><td><code>sample/TraceAllMsgDemo</code></td><td>Objective-C</td><td>手动 <code>APTBeginSection</code> section 与自动 <code>objc_msgSend</code> hook</td></tr>
</table>
<p>每个引导式 App 都有 <strong>Generate Trace</strong> 按钮,显示 trace 目录并打印合并/Perfetto 命令。Swift demo 依赖本地包,请从仓库内打开,让 Xcode 自动解析 product。</p>
</section>
Expand Down
Loading
Loading