办公效率

xctrace 命令行性能采集

用 Xcode 的命令行工具在无图形界面的环境中录制性能数据、导出 XML 并检测性能回归。

# xctrace CLI 参考

用于 Instruments 性能分析的命令行界面。无需 GUI 即可进行无头性能分析。

## 概览

`xctrace` 是 Instruments.app 背后的 CLI 工具。可用于:
- 在 CI/CD 流水线中自动进行性能分析
- 无需 GUI 收集追踪数据
- 通过 XML 导出以编程方式分析追踪数据
- 检测性能回退

**要求**:Xcode 12+(xctrace 12.0+)。本参考使用 Xcode 26.2 测试。

## 快速参考

```bash
# Record a 10-second CPU profile
xcrun xctrace record --instrument 'CPU Profiler' --attach 'MyApp' --time-limit 10s --output profile.trace

# Export to XML for analysis
xcrun xctrace export --input profile.trace --toc  # See available tables
xcrun xctrace export --input profile.trace --xpath '/trace-toc/run[@number="1"]/data/table[@schema="cpu-profile"]'

# List available instruments
xcrun xctrace list instruments

# List available templates
xcrun xctrace list templates
```

## 录制追踪数据

### 基本录制

```bash
# Using an instrument (recommended for CLI automation)
xcrun xctrace record --instrument 'CPU Profiler' --attach 'AppName' --time-limit 10s --output trace.trace

# Using a template (may fail on export in Xcode 26+)
xcrun xctrace record --template 'Time Profiler' --attach 'AppName' --time-limit 10s --output trace.trace
```

**注意**:在 Xcode 26+ 中,使用 `--instrument` 代替 `--template`,以确保可靠导出。使用模板生成的追踪数据在导出时可能出现“Document Missing Template Error”。

### 选择目标

```bash
# Attach to running process by name
xcrun xctrace record --instrument 'CPU Profiler' --attach 'MyApp' --time-limit 10s

# Attach to running process by PID
xcrun xctrace record --instrument 'CPU Profiler' --attach 12345 --time-limit 10s

# Profile all processes
xcrun xctrace record --instrument 'CPU Profiler' --all-processes --time-limit 10s

# Launch and profile
xcrun xctrace record --instrument 'CPU Profiler' --launch -- /path/to/app arg1 arg2

# Target specific device (simulator or physical)
xcrun xctrace record --instrument 'CPU Profiler' --device 'iPhone 17 Pro' --attach 'MyApp' --time-limit 10s
xcrun xctrace record --instrument 'CPU Profiler' --device 947DF45C-4ACB-4B3E-A043-DF2CD59A59B3 --all-processes --time-limit 10s
```

### 录制选项

| 标志 | 描述 |
|------|-------------|
| `--output <path>` | 输出 .trace 文件路径 |
| `--time-limit <time>` | 录制时长(例如 `10s`、`1m`、`500ms`) |
| `--no-prompt` | 跳过隐私警告(用于自动化) |
| `--append-run` | 将运行记录添加到现有追踪数据中 |
| `--run-name <name>` | 为录制运行命名 |

## 核心 Instruments

### CPU Profiler
对 CPU 进行采样以查找热点函数。

```bash
xcrun xctrace record --instrument 'CPU Profiler' --attach 'MyApp' --time-limit 10s --output cpu.trace
```

**架构**:`cpu-profile`
**列**:time, thread, process, core, thread-state, weight (cycles), stack

### Allocations
跟踪内存分配。

```bash
xcrun xctrace record --instrument 'Allocations' --attach 'MyApp' --time-limit 30s --output alloc.trace
```

**架构**:`allocations`
**用途**:查找内存增长、对象数量和分配模式

### Leaks
检测内存泄漏。

```bash
xcrun xctrace record --instrument 'Leaks' --attach 'MyApp' --time-limit 30s --output leaks.trace
```

**架构**:`leaks`
**用途**:检测未释放的内存和引用循环

### SwiftUI
分析 SwiftUI 视图的 body。

```bash
xcrun xctrace record --instrument 'SwiftUI' --attach 'MyApp' --time-limit 10s --output swiftui.trace
```

**架构**:`swiftui`
**用途**:查找过多的视图更新和 body 重新求值

### Swift Concurrency
分析 Actor 和 Task。

```bash
xcrun xctrace record --instrument 'Swift Tasks' --instrument 'Swift Actors' --attach 'MyApp' --time-limit 10s --output concurrency.trace
```

**架构**:`swift-task`、`swift-actor`
**用途**:任务调度、actor 隔离、异步性能

## 所有可用的 Instruments

```
Activity Monitor          Audio Client              Audio Server
Audio Statistics          CPU Counters              CPU Profiler
Core Animation Activity   Core Animation Commits    Core Animation FPS
Core Animation Server     Core ML                   Data Faults
Data Fetches              Data Saves                Disk I/O Latency
Disk Usage                Display                   Filesystem Activity
Filesystem Suggestions    Foundation Models         Frame Lifetimes
GCD Performance           GPU                       HTTP Traffic
Hangs                     Hitches                   Leaks
Location Energy Model     Metal Application         Metal GPU Counters
Metal Performance Overview Metal Resource Events    Network Connections
Neural Engine             Points of Interest        Power Profiler
Processor Trace           RealityKit Frames         RealityKit Metrics
Runloops                  Sampler                   SceneKit Application
Swift Actors              Swift Tasks               SwiftUI
System Call Trace         System Load               Thread States
Time Profiler             VM Tracker                Virtual Memory Trace
```

## 导出追踪数据

### 目录

```bash
# See all available data tables in a trace
xcrun xctrace export --input trace.trace --toc
```

输出结构:
```xml
<trace-toc>
    <run number="1">
        <info>
            <target>...</target>
            <summary>...</summary>
        </info>
        <processes>...</processes>
        <data>
            <table schema="cpu-profile" .../>
            <table schema="thread-info"/>
            <table schema="process-info"/>
        </data>
    </run>
</trace-toc>
```

### XPath 导出

```bash
# Export specific table by schema
xcrun xctrace export --input trace.trace --xpath '/trace-toc/run[@number="1"]/data/table[@schema="cpu-profile"]'

# Export process info
xcrun xctrace export --input trace.trace --xpath '/trace-toc/run[@number="1"]/data/table[@schema="process-info"]'

# Export thread info
xcrun xctrace export --input trace.trace --xpath '/trace-toc/run[@number="1"]/data/table[@schema="thread-info"]'
```

### CPU 性能分析架构

```xml
<schema name="cpu-profile">
    <col><mnemonic>time</mnemonic><name>Sample Time</name></col>
    <col><mnemonic>thread</mnemonic><name>Thread</name></col>
    <col><mnemonic>process</mnemonic><name>Process</name></col>
    <col><mnemonic>core</mnemonic><name>Core</name></col>
    <col><mnemonic>thread-state</mnemonic><name>State</name></col>
    <col><mnemonic>weight</mnemonic><name>Cycles</name></col>
    <col><mnemonic>stack</mnemonic><name>Backtrace</name></col>
</schema>
```

每行包含:
- `sample-time`:以纳秒为单位的时间戳
- `thread`:线程 ID 和名称
- `process`:进程名称和 PID
- `core`:CPU 核心编号
- `thread-state`:运行中、阻塞等
- `cycle-weight`:CPU 周期
- `backtrace`:包含函数名称的调用栈

## 进程发现

### 查找正在运行的模拟器应用

```bash
# List apps in booted simulator
xcrun simctl spawn booted launchctl list | grep UIKitApplication

# Output format: PID  Status  com.apple.UIKitApplication:com.bundle.id[xxxx][rb-legacy]
```

### 查找设备 UUID

```bash
# List booted simulators (JSON)
xcrun simctl list devices booted -j

# List all devices
xcrun simctl list devices
```

### 按名称查找进程

```bash
# Get PID of running app
pgrep -f "MyApp"

# List all processes with app name
ps aux | grep MyApp
```

## 自动化模式

### CI/CD 集成

```bash
#!/bin/bash
# performance-test.sh

APP_NAME="MyApp"
TRACE_DIR="./traces"
TIME_LIMIT="30s"

# Boot simulator if needed
xcrun simctl boot "iPhone 17 Pro" 2>/dev/null || true

# Wait for app to launch
sleep 5

# Record CPU profile
xcrun xctrace record \
    --instrument 'CPU Profiler' \
    --device "iPhone 17 Pro" \
    --attach "$APP_NAME" \
    --time-limit "$TIME_LIMIT" \
    --no-prompt \
    --output "$TRACE_DIR/cpu.trace"

# Export for analysis
xcrun xctrace export \
    --input "$TRACE_DIR/cpu.trace" \
    --xpath '/trace-toc/run[@number="1"]/data/table[@schema="cpu-profile"]' \
    > "$TRACE_DIR/cpu-profile.xml"

# Parse and check thresholds
# (Use xmllint, python, or custom tool to parse XML)
```

### 前后对比

```bash
# Record baseline
xcrun xctrace record --instrument 'CPU Profiler' --attach 'MyApp' --time-limit 10s --output baseline.trace

# Make changes, rebuild app

# Record after changes
xcrun xctrace record --instrument 'CPU Profiler' --attach 'MyApp' --time-limit 10s --output after.trace

# Export both for comparison
xcrun xctrace export --input baseline.trace --xpath '...' > baseline.xml
xcrun xctrace export --input after.trace --xpath '...' > after.xml
```

## 故障排查

### 导出时出现“Document Missing Template Error”

**原因**:在 Xcode 26+ 中录制时使用了 `--template` 标志
**修复**:改用 `--instrument`:
```bash
# Instead of
xcrun xctrace record --template 'Time Profiler' ...

# Use
xcrun xctrace record --instrument 'CPU Profiler' ...
```

### “Unable to attach to process”

**原因**:
1. 进程未运行
2. 权限不足
3. 系统完整性保护阻止了操作

**修复**:
```bash
# Verify process exists
pgrep -f "AppName"

# For simulator apps, verify simulator is booted
xcrun simctl list devices booted

# Try with --all-processes instead of --attach
xcrun xctrace record --instrument 'CPU Profiler' --all-processes --time-limit 5s
```

### 导出的追踪数据为空

**原因**:录制时间过短,或录制期间没有活动
**修复**:增加 `--time-limit`,或确保录制期间应用处于活跃使用状态

### 符号化问题

回溯中显示原始地址(例如 `0x18f17ed94`),而不是函数名称。

**修复**:确保 dSYM 可用:
```bash
# Symbolicate trace (if needed)
xcrun xctrace symbolicate --input trace.trace --dsym /path/to/App.dSYM
```

## 限制

1. **隐私限制**:某些 instrument 需要在系统偏好设置中授予隐私权限
2. **设备支持**:对实体设备进行性能分析需要启用开发者模式
3. **后台应用**:对后台应用的性能分析有限
4. **导出格式**:仅支持 XML(不支持 JSON 导出)
5. **模板与 Instrument**:在 Xcode 26+ 中,模板可能无法正常导出

## 资源

**技能**:axiom-performance-profiling, axiom-memory-debugging, axiom-swiftui-performance

**文档**:/xcode/instruments, /os/logging/recording-performance-data

同类提示词

办公效率· n8n 工作流的对话模型

商品照片转棚拍广告生图指令

上传商品照片并提供说明文字,分析材质、配色和原图问题,写出保留商品外观的棚拍广告生图指令。

=你是一位专业产品摄影师和广告创意总监。分析上传的产品图片及其配文:{{ $('Telegram Trigger Received').item.json.message.caption }} 你的任务是创建一段详细的图像生成提示词,将这张产品照片转化为高端、商业级的广告视觉作品。 分析要求: 1. **产品识别**:识别产品类型、尺寸、类别、材质、配色和关键特征 2. **当前状态评估**:指出当前的光线、背景、构图和质量问题 3. **目标美学**:根据产品类别确定理想的广告风格(奢侈品、科技、食品、时尚等) 输出(严格使用 JSON 格式):
办公效率· n8n 工作流的对话模型

Veo 3营销视频分镜指令

填写视频需求、营销目标、图像描述和画幅,生成包含场景、运镜、动作、灯光与结尾的结构化制片指令。

=# Veo3 视频生成系统提示词 你是一名专业的视频提示词工程师,擅长为 Veo3 视频生成撰写细致、富有电影感的提示词。你的角色是分析用户输入,将其转化为全面的视频生成指令,以产出高质量、引人入胜的内容。 ## 输入分析 你将收到以下用户输入: - **AI Videos instructions**:视频生成的核心用户请求 - **Campaign objectives**:营销活动目标和说明 - **Images Description**:用户提供的视觉背景信息 - **Aspect Ratio**:要求的视频尺寸比例 ## 输出格式 你
可填 21 项
办公效率· n8n 工作流的对话模型

保留原品的社媒广告视觉方案

提供商品图和配文,生成保留原品外观的广告生图说明,广告文字仅从配文提取,缺项留空。

={ "system_prompt": "你是一位顶尖创意总监,专攻爆款产品广告,拥有15年以上奢侈品牌广告活动经验。将产品图片转化为商业级广告,让浏览者停下滑动并促进转化。", "instructions": { "core_rules": [ "保持原始产品100%不变——不得修改、替换或扭曲", "只提取和使用用户配文中提供的文字", "如果配文中没有相关文字,文字字段留空——绝不生成AI广告语", "专注于高端视觉强化和商业摄影技巧", "制作适合在Instagram展
办公效率· Claude Fable 5.2

用代码制作长纪录片流程

从题材调研、脚本和样帧审核开始,按章节生成三维分镜、旁白、环境声与可复现渲染。

<inputs> 向我询问: 1. 我的主题 2. 目标视频时长 3. 我是否已有脚本 如果我只给你一个主题,先研究该主题并撰写脚本。 开始制作任何内容之前,先向我展示: - 完整脚本 - 章节拆分 - 前 60 seconds 的分镜计划 - 6 张展示预期视觉方向的静帧 在我认可视觉效果之前,不要渲染完整视频。 </inputs> <story> 按照高品质 YouTube 纪录片的方式来写,不要写成 AI 科普解说。 故事必须始终向前推进。 每个部分都需要包含以下内容之一: - 一个新问题 - 一个揭示 - 一个矛盾 - 一个后果 - 一条证据
办公效率

同场景表情变化九宫格自拍

上传主角照片,可选搭档参考图或设定,并填写服装、背景或姿势偏好,生成同一布光和构图的九张变化。

# photo-booth ## 何时使用此 skill - 当用户希望根据参考图制作大头贴宫格、表情宫格、情侣自拍宫格、同步姿势组图或多种人像变体时使用。 - 当请求制作 3x3 宫格,且主体、房间、服装、构图和布光保持一致,仅表情或细微姿势发生变化时触发。 ## 必需输入 - 主要人物的主参考图。 - 可选的伴侣或角色参考图。 - 如果未提供伴侣参考图,需提供期望的伴侣设定。 - 用户指定的服装、背景、摄影时代、姿势清单或氛围。 如果缺少主参考图,请用户附上。如果伴侣设定或预期风格不明确,提出一个有针对性的问题。 ## 连续性规则 -
需参考图
办公效率· Claude Code / 动效编程

单镜头立体落地页飞越动画

提供落地页链接、品牌名、标志和两段收尾文案,可选配乐,制作卡片随镜头掠过而浮起的连续飞越短片。

<inputs> 向我索取:我的落地页链接、品牌名称和标志、由两部分组成的结尾文案(一句陈述,后接一小段斜体文字),以及一条 15 second 音轨(可选)。 </inputs> <direction> 以 60fps 对我的落地页进行 14.5 second 3D 飞越拍摄,1440x1152。页面平放在明亮的摄影棚地面上(中央为 #f9fbfb,角落为 #f2f3f6),周围有柔和宽阔的阴影,圆角为 24px。全程使用一个连续镜头,绝不切镜:镜头从首屏上方低处开始,以恒定速度沿页面向后滑行,同时朝页面上方看去;然后垂直升至正上方,将整个页面呈现为
✓