Mac OS 上是否有等效的性能统计信息?我想对 CLI 命令做同样的事情,而谷歌搜索并没有产生任何结果。
2 回答
Mac OS X 中有 Instruments 工具来分析应用程序,包括硬件 PMU。默认是对 CPU 使用率进行采样分析器。一些文档:https://en.wikipedia.org/wiki/Instruments_(software) https://help.apple.com/instruments/mac/current/ 它还有命令行变体:https://help.apple。 com/instruments/mac/current/#/devb14ffaa5
在 /Applications/Utilities 中打开终端。
instruments -t "Allocations" -D ~/Desktop/YourTraceFileName.trace PathToYourApp
页面https://gist.github.com/loderunner/36724cc9ee8db66db305提到了工具sample
(“包含在标准 Mac OS X 安装中”)。
此外,还提到了旧版本的 Mac OS X(10.7 之前)和 Xcode 的 Shark 工具:https ://en.wikipedia.org/wiki/Apple_Developer_Tools#Shark
使用 Intel CPU,您可以尝试 Intel Vtune 分析器 - https://software.intel.com/en-us/get-started-with-vtune-macos https://software.intel.com/en-us/vtune
其他更开放的英特尔工具(部分弃用?)是https://github.com/opcm/pcm/,它具有某种 OSX 支持。文档:https ://software.intel.com/en-us/articles/intel-performance-counter-monitor 。需要自定义MacMSRDriver驱动程序 (kext)。
perf stat
确实计算事件,我不确定如何使用 Instruments 收集计数器。页面https://www.robertpieta.com/counters-in-instruments/显示了如何配置 Instruments GUI 以进行事件计数:
要配置计数器,请从 Instruments 导航菜单中选择 File -> Recording Options。就本文而言,将选择按时间抽样。使用 + 您可以添加计数器可以在当前连接到仪器的特定 CPU 上计算可用的特定事件。
因此,您至少可以指示 Instruments 工具随着时间的推移定期记录计数器值。该模式报告了一些问题:http: //hmijailblog.blogspot.com/2015/09/using-intels-performance-counters-on-os.html
我对缺少等效的 CLI 感到失望perf stat -r
,所以我只是写了https://github.com/cdr/timer。
像这样工作:
$ timer -n 4 -q sleep 1s
--- config
command sleep 1s
iterations 4
parallelism 1
--- percentiles
0 (fastest) 1.004
25 (1st quantile) 1.004
50 (median) 1.006
75 (3rd quantile) 1.008
100th (slowest) 1.008
--- summary
mean 1.006
stddev 0.002
这不包含高级执行计数器,仅包含挂钟统计信息。