当前位置: 首页 > Skill >

Xcode Build Analyzer

Xcode Build Analyzer

Xcode Build Analyzer

分析 Xcode 构建日志——耗时、警告、错误、慢编译和 DerivedData 中的构建历史。

1.2.0 2026.11.27 464
获取Skill文件查看使用说明
作 者:陆澄 许可证: 更新时间:2026.11.27
本文目录展开

Xcode Build Analyzer

Analyze Xcode build performance, warnings, errors, and history by reading DerivedData build logs on macOS.

Requirements

  • macOS only — reads from ~/Library/Developer/Xcode/DerivedData/
  • Xcode must be installed and have built at least one project
  • plutil, gunzip, sqlite3 (all pre-installed on macOS)
  • Full Disk Access may be required depending on the process running queries

Key paths

DERIVED_DATA=~/Library/Developer/Xcode/DerivedData

Each project has a folder named <ProjectName>-<hash> containing:

  • info.plist — project workspace path and last accessed date
  • Logs/Build/LogStoreManifest.plist — structured index of all builds (timing, status, warnings, errors)
  • Logs/Build/*.xcactivitylog — gzip-compressed SLF build logs with per-step timing and full compiler output

Important: All queries are read-only. Never modify DerivedData contents.

List all projects in DerivedData

for dir in ~/Library/Developer/Xcode/DerivedData/*-*; do
  [ -d "$dir" ] || continue
  NAME="$(basename "$dir" | sed 's/-[a-z]*$//')"
  WORKSPACE="$(plutil -extract WorkspacePath raw "$dir/info.plist" 2>/dev/null || echo "unknown")"
  LAST_ACCESS="$(plutil -extract LastAccessedDate raw "$dir/info.plist" 2>/dev/null || echo "unknown")"
  echo "$NAME | $WORKSPACE | Last accessed: $LAST_ACCESS"
done

Build history for a project

Parse the LogStoreManifest.plist for structured build data. This is the most reliable source — it contains timing, error/warning counts, and scheme info for every build without needing to decompress logs.

# Replace PROJECT_DIR with the project's DerivedData folder
# To find it: ls ~/Library/Developer/Xcode/DerivedData/ | grep -i "ProjectName"
PROJECT_DIR="$(ls -d ~/Library/Developer/Xcode/DerivedData/PROJECT_NAME-* 2>/dev/null | head -1)"
MANIFEST="$PROJECT_DIR/Logs/Build/LogStoreManifest.plist"

plutil -convert json -o - "$MANIFEST" 2>/dev/null | python3 -c "
import json, sys
from datetime import datetime, timezone, timedelta

data = json.load(sys.stdin)
EPOCH = datetime(2001, 1, 1, tzinfo=timezone.utc)
builds = []

for uid, log in data.get('logs', {}).items():
    start = log.get('timeStartedRecording', 0)
    stop = log.get('timeStoppedRecording', 0)
    duration = stop - start
    obs = log.get('primaryObservable', {})
    dt = EPOCH + timedelta(seconds=start)
    builds.append({
        'date': dt.strftime('%Y-%m-%d %H:%M'),
        'duration': f'{duration:.1f}s',
        'scheme': log.get('schemeIdentifier-schemeName', '?'),
        'status': obs.get('highLevelStatus', '?'),
        'errors': obs.get('totalNumberOfErrors', 0),
        'warnings': obs.get('totalNumberOfWarnings', 0),
        'analyzer': obs.get('totalNumberOfAnalyzerIssues', 0),
        'file': log.get('fileName', ''),
    })

builds.sort(key=lambda b: b['date'], reverse=True)
for b in builds:
    status = {'S': 'OK', 'W': 'Warnings', 'E': 'Error'}.get(b['status'], b['status'])
    print(f"{b['date']}  {b['duration']:>8s}  {status:<10s}  {b['errors']}E {b['warnings']}W {b['analyzer']}A  [{b['scheme']}]")
"

Replace PROJECT_NAME with the project name (case-insensitive grep match is fine).

Status codes: S = Succeeded, W = Succeeded with Warnings, E = Failed with Errors

Latest build summary (all projects)

for dir in ~/Library/Developer/Xcode/DerivedData/*-*; do
  [ -d "$dir" ] || continue
  MANIFEST="$dir/Logs/Build/LogStoreManifest.plist"
  [ -f "$MANIFEST" ] || continue
  NAME="$(basename "$dir" | sed 's/-[a-z]*$//')"

  plutil -convert json -o - "$MANIFEST" 2>/dev/null | python3 -c "
import json, sys
from datetime import datetime, timezone, timedelta

data = json.load(sys.stdin)
EPOCH = datetime(2001, 1, 1, tzinfo=timezone.utc)
name = '$NAME'
latest = None

for uid, log in data.get('logs', {}).items():
    start = log.get('timeStartedRecording', 0)
    if latest is None or start > latest[0]:
        latest = (start, log)

if latest:
    start, log = latest
    stop = log.get('timeStoppedRecording', 0)
    obs = log.get('primaryObservable', {})
    dt = EPOCH + timedelta(seconds=start)
    duration = stop - start
    status = {'S': 'OK', 'W': 'Warn', 'E': 'Err'}.get(obs.get('highLevelStatus', '?'), '?')
    print(f"{name:<30s} {dt.strftime('%Y-%m-%d %H:%M')}  {duration:>6.1f}s  {status:<5s} {obs.get('totalNumberOfErrors',0)}E {obs.get('totalNumberOfWarnings',0)}W")
" 2>/dev/null
done

Extract warnings and errors from a build log

# Find the latest xcactivitylog for a project
PROJECT_DIR="$(ls -d ~/Library/Developer/Xcode/DerivedData/PROJECT_NAME-* 2>/dev/null | head -1)"
LATEST_LOG="$(ls -t "$PROJECT_DIR/Logs/Build/"*.xcactivitylog 2>/dev/null | head -1)"

# Extract warnings
gunzip -c "$LATEST_LOG" 2>/dev/null | strings | grep -E ".swift:[0-9]+:[0-9]+: warning:" | sort -u

# Extract errors
gunzip -c "$LATEST_LOG" 2>/dev/null | strings | grep -E ".swift:[0-9]+:[0-9]+: error:" | sort -u

Warning summary (grouped by type)

PROJECT_DIR="$(ls -d ~/Library/Developer/Xcode/DerivedData/PROJECT_NAME-* 2>/dev/null | head -1)"
LATEST_LOG="$(ls -t "$PROJECT_DIR/Logs/Build/"*.xcactivitylog 2>/dev/null | head -1)"

gunzip -c "$LATEST_LOG" 2>/dev/null | strings 
  | grep -oE "warning: .*" 
  | sed 's/[.*//; s/'"'"'[^'"'"']*'"'"'//g' 
  | sort | uniq -c | sort -rn | head -20

Build step timing (find slow steps)

The xcactivitylog contains per-task TaskMetrics JSON with wall-clock duration in microseconds.

PROJECT_DIR="$(ls -d ~/Library/Developer/Xcode/DerivedData/PROJECT_NAME-* 2>/dev/null | head -1)"
LATEST_LOG="$(ls -t "$PROJECT_DIR/Logs/Build/"*.xcactivitylog 2>/dev/null | head -1)"

gunzip -c "$LATEST_LOG" 2>/dev/null | strings 
  | grep -o '{"wcDuration":[^}]*}' 
  | python3 -c "
import json, sys

tasks = []
for line in sys.stdin:
    try:
        m = json.loads(line.strip())
        tasks.append(m)
    except: pass

tasks.sort(key=lambda t: t.get('wcDuration', 0), reverse=True)
print(f'Total tasks: {len(tasks)}')
print(f'Top 10 slowest (wall-clock microseconds):')
for i, t in enumerate(tasks[:10]):
    wc = t['wcDuration']
    rss = t.get('maxRSS', 0)
    print(f'  {i+1}. {wc/1000:.1f}ms  (RSS: {rss/1024/1024:.1f}MB)')
"

DerivedData disk usage

echo "Total DerivedData size:"
du -sh ~/Library/Developer/Xcode/DerivedData/ 2>/dev/null

echo ""
echo "Per project:"
for dir in ~/Library/Developer/Xcode/DerivedData/*-*; do
  [ -d "$dir" ] || continue
  NAME="$(basename "$dir" | sed 's/-[a-z]*$//')"
  SIZE="$(du -sh "$dir" 2>/dev/null | cut -f1)"
  echo "  $SIZE  $NAME"
done | sort -rh

Clean DerivedData for a project

Only suggest this when the user explicitly asks. This deletes the build cache and will force a full rebuild.

# Replace PROJECT_NAME with the project name
PROJECT_DIR="$(ls -d ~/Library/Developer/Xcode/DerivedData/PROJECT_NAME-* 2>/dev/null | head -1)"
echo "Will delete: $PROJECT_DIR ($(du -sh "$PROJECT_DIR" 2>/dev/null | cut -f1))"
echo "Run: rm -rf "$PROJECT_DIR""

Warning: Always confirm with the user before deleting. Suggest printing the size and path first.

Build trend (all builds for a project over time)

PROJECT_DIR="$(ls -d ~/Library/Developer/Xcode/DerivedData/PROJECT_NAME-* 2>/dev/null | head -1)"
MANIFEST="$PROJECT_DIR/Logs/Build/LogStoreManifest.plist"

plutil -convert json -o - "$MANIFEST" 2>/dev/null | python3 -c "
import json, sys
from datetime import datetime, timezone, timedelta

data = json.load(sys.stdin)
EPOCH = datetime(2001, 1, 1, tzinfo=timezone.utc)
builds = []

for uid, log in data.get('logs', {}).items():
    start = log.get('timeStartedRecording', 0)
    stop = log.get('timeStoppedRecording', 0)
    builds.append((start, stop - start))

builds.sort()
if builds:
    print(f'Builds tracked: {len(builds)}')
    durations = [d for _, d in builds]
    print(f'Fastest: {min(durations):.1f}s')
    print(f'Slowest: {max(durations):.1f}s')
    print(f'Average: {sum(durations)/len(durations):.1f}s')
    print(f'Median:  {sorted(durations)[len(durations)//2]:.1f}s')
    print()
    print('Timeline:')
    for start, dur in builds:
        dt = EPOCH + timedelta(seconds=start)
        bar = '█' * max(1, int(dur / max(durations) * 30))
        print(f'  {dt.strftime("%m/%d %H:%M")}  {dur:>6.1f}s  {bar}')
"

Concurrency issues (Swift 6 readiness)

Extract Swift concurrency warnings that will become errors in Swift 6:

PROJECT_DIR="$(ls -d ~/Library/Developer/Xcode/DerivedData/PROJECT_NAME-* 2>/dev/null | head -1)"
LATEST_LOG="$(ls -t "$PROJECT_DIR/Logs/Build/"*.xcactivitylog 2>/dev/null | head -1)"

gunzip -c "$LATEST_LOG" 2>/dev/null | strings 
  | grep -E "(data race|Sendable|actor-isolated|crossing into|concurrency)" 
  | grep "warning:" 
  | sort -u

CLI builds (xcodebuild)

Important: xcodebuild CLI builds do not write to LogStoreManifest.plist or generate .xcactivitylog files unless you pass -resultBundlePath. This means the build history section above will only show Xcode IDE builds.

To detect CLI builds, check the build product timestamps and DerivedData info:

for dir in ~/Library/Developer/Xcode/DerivedData/*-*; do
  [ -d "$dir" ] || continue
  NAME="$(basename "$dir" | sed 's/-[a-z]*$//')"
  WORKSPACE="$(plutil -extract WorkspacePath raw "$dir/info.plist" 2>/dev/null || echo "unknown")"

  # Detect if this is a worktree build (workspace path outside main project dir, e.g. /tmp/)
  SOURCE=""
  PROJ_DIR="$(dirname "$WORKSPACE")"
  if [ -d "$PROJ_DIR" ] && git -C "$PROJ_DIR" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
    BRANCH="$(git -C "$PROJ_DIR" branch --show-current 2>/dev/null)"
    IS_WORKTREE="$(git -C "$PROJ_DIR" rev-parse --is-inside-work-tree 2>/dev/null)"
    MAIN_WORKTREE="$(git -C "$PROJ_DIR" worktree list 2>/dev/null | head -1 | awk '{print $1}')"
    if [ "$PROJ_DIR" != "$MAIN_WORKTREE" ]; then
      SOURCE=" (worktree: $BRANCH @ $PROJ_DIR)"
    else
      SOURCE=" (branch: $BRANCH)"
    fi
  fi

  # Check Debug simulator product
  APP="$(ls -dt "$dir/Build/Products/Debug-iphonesimulator/"*.app 2>/dev/null | head -1)"
  if [ -n "$APP" ]; then
    MTIME="$(stat -f '%Sm' -t '%Y-%m-%d %H:%M' "$APP" 2>/dev/null)"
    VERSION=""
    PLIST="$APP/Info.plist"
    if [ -f "$PLIST" ]; then
      SHORT="$(plutil -extract CFBundleShortVersionString raw "$PLIST" 2>/dev/null)"
      BUILD="$(plutil -extract CFBundleVersion raw "$PLIST" 2>/dev/null)"
      VERSION=" v${SHORT}(${BUILD})"
    fi
    echo "$NAME | Last build: $MTIME |$VERSION | $(basename "$APP")$SOURCE"
  fi

  # Check Release product
  APP="$(ls -dt "$dir/Build/Products/Release-iphoneos/"*.app 2>/dev/null | head -1)"
  if [ -n "$APP" ]; then
    MTIME="$(stat -f '%Sm' -t '%Y-%m-%d %H:%M' "$APP" 2>/dev/null)"
    echo "$NAME | Last release: $MTIME | $(basename "$APP")$SOURCE"
  fi
done

Worktrees: When building from a git worktree, Xcode creates a separate DerivedData entry (different hash) because the workspace path differs. The script above detects worktree builds by checking the git state of the workspace path and shows the branch name and worktree location.

Combined build history (IDE + CLI)

To get a complete picture of all builds (both Xcode IDE and CLI), run both the LogStoreManifest parser and the build product check. The manifest gives detailed history for IDE builds; the product timestamps give the latest CLI build per configuration.

echo "=== IDE Builds (from LogStoreManifest) ==="
for dir in ~/Library/Developer/Xcode/DerivedData/*-*; do
  [ -d "$dir" ] || continue
  MANIFEST="$dir/Logs/Build/LogStoreManifest.plist"
  [ -f "$MANIFEST" ] || continue
  NAME="$(basename "$dir" | sed 's/-[a-z]*$//')"

  plutil -convert json -o - "$MANIFEST" 2>/dev/null | python3 -c "
import json, sys
from datetime import datetime, timezone, timedelta

data = json.load(sys.stdin)
EPOCH = datetime(2001, 1, 1, tzinfo=timezone.utc)
name = '$NAME'

for uid, log in sorted(data.get('logs', {}).items(), key=lambda x: x[1].get('timeStartedRecording', 0), reverse=True):
    start = log.get('timeStartedRecording', 0)
    stop = log.get('timeStoppedRecording', 0)
    obs = log.get('primaryObservable', {})
    dt = EPOCH + timedelta(seconds=start)
    duration = stop - start
    status = {'S': 'OK', 'W': 'Warn', 'E': 'Err'}.get(obs.get('highLevelStatus', '?'), '?')
    scheme = log.get('schemeIdentifier-schemeName', '?')
    print(f'  {name:<25s} {dt.strftime("%Y-%m-%d %H:%M")}  {duration:>6.1f}s  {status:<5s} [{scheme}]  (IDE)')
" 2>/dev/null
done

echo ""
echo "=== CLI Builds (from build products) ==="
for dir in ~/Library/Developer/Xcode/DerivedData/*-*; do
  [ -d "$dir" ] || continue
  NAME="$(basename "$dir" | sed 's/-[a-z]*$//')"
  for APP in "$dir/Build/Products/"*/*.app; do
    [ -d "$APP" ] || continue
    MTIME="$(stat -f '%Sm' -t '%Y-%m-%d %H:%M' "$APP" 2>/dev/null)"
    CONFIG="$(basename "$(dirname "$APP")")"
    echo "  $NAME  $MTIME  [$CONFIG]  $(basename "$APP")  (CLI)"
  done 2>/dev/null
done

Notes

  • LogStoreManifest.plist is the fastest way to get build history — no decompression needed
  • xcactivitylog files are gzip-compressed SLF (Structured Log Format); use gunzip -c + strings for quick extraction
  • Core Data timestamps: seconds since 2001-01-01 (+ 978307200 to convert to Unix epoch)
  • Build logs are kept until DerivedData is cleaned — Xcode may prune very old logs
  • The highLevelStatus field: S = success, W = warnings, E = errors
  • TaskMetrics wcDuration is in microseconds; maxRSS is in bytes
  • All operations are read-only — never modify DerivedData while Xcode is running

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,040
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,033
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,021
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,021
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,019
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,016
Skill 文件
  • SKILL.md
    • Xcode Build Analyzer
    • Requirements
    • Key paths
    • List all projects in DerivedData
    • Build history for a project
    • Latest build summary (all projects)
    • Extract warnings and errors from a build log
    • Warning summary (grouped by type)
    • Build step timing (find slow steps)
    • DerivedData disk usage
    • Clean DerivedData for a project
    • Build trend (all builds for a project over time)
    • Concurrency issues (Swift 6 readiness)
    • CLI builds (xcodebuild)
      • Combined build history (IDE + CLI)
    • Notes
  • 项目或源文件

相关 Skill

更多
service-qa-coach service-qa-coach Review support quality for chat, email, phone, social DM, or marketplace service teams. Use when a team needs a QA scorecard, failure-mode analysis, coaching plan, calibration checklist, or service-improvement brief without live ticketing, CRM, or contact-center system access.
高中数学作业批改助手 高中数学作业批改助手 >图片识别 直接读取学生手写作答照片,识别公式、符号、步骤 🧮 自动推导 根据题目自动生成参考答案和评分细则,无需教师预设 📊 逐步给分 每个关键步骤独立评分,体现过程分 📝 结构化报告 输出含识别内容、参考答案、逐步评分、改进建议的完整报告 🗂 批量批改 支持一次性批改多道题,最终汇总得分表
Vibration Analysis Vibration Analysis 分析来自CMS趋势、RMS/峰值、频谱及SCADA报警的风机传动链(主轴、齿轮箱、发电机)振动数据。
Traditional Bone Tool Making Basics Traditional Bone Tool Making Basics Use when you need custom, durable, repairable tools like awls, needles, scrapers, harpoons, or fishing hooks made from local animal bones or antlers and comm...
音频混音工具 音频混音工具 名称:Sound Mixing Tool(标识 sound-mixing-tool) 短简介(≤60字):音乐/音效响度精确对齐 + 融合混音工作流:用 ffmpeg 两段式 loudnorm 把多组素材 LUFS 偏差压到 <0.10,再最小干预融合、导出可进引擎的独立分轨。 标签/关键词:音频混音 响度匹配 LUFS ffmpeg 游戏音频 音效设计 Wwise FMOD 分轨导出 后期处理 触发词:混音 · 响度匹配 · LUFS 对齐 · MIX 版本 · 音乐音效分轨 · 融合 · 不打架 · 不能盖住 适用场景 :游戏音频集成、影视短视频配乐、播客后期