用 spindump 抓取系统卡顿报告

系统整体卡顿时,用 spindump 对所有进程做采样,看卡住时每个程序在做什么。

macOSspindump 卡顿转储性能诊断中风险
运行 sudo spindump -notarget 10 -file /tmp/spindump-report.txt,对整个系统采样 10 秒并生成报告。

01命令

命令
$ sudo spindump -notarget 10 -file /tmp/spindump-report.txt

02作用说明

spindump 是 macOS 自带的全系统采样器:在指定时长内记录所有用户态进程的调用栈并按 CPU 占用排序,适合整机发顿、或某个进程悄悄吃满 CPU 的场景。-notarget 表示采样整个系统而不是等待某个无响应应用;不加该参数时它会等待并分析指定的卡死程序。macOS 在发生严重卡顿时也会自动触发 spindump,报告存放在 /Library/Logs/DiagnosticReports。

03风险

风险中风险
使用条件Requires administrator (sudo) privileges.
!注意: spindump 必须 root 运行,会采样所有进程,生成的文件可能包含文件路径和命令参数等敏感信息,请妥善保管。繁忙系统的 10 秒采样会产生很大的文本文件,提交 bug 时只贴相关进程的部分即可。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • Technical Note TN2124: Mac OS X Debugging Magic
    Apple · vendor-doc · 2026-09-17
    依据: Apple's debugging guide describing spindump-style system-wide stack sampling for diagnosing stalls.
  • spindump(8) macOS man page
    unix.com · technical · 2026-09-17
    依据: Man page for spindump: samples the whole system and reports stack traces for user-space processes, run as root.

最后验证: 2026-09-18 · 分类: 开发者

06相关方案