Mac OS 的 Perf stat 等效项?

Eri*_*ing 7 macos profiling performancecounter perf intel-pmu

Mac OS 上有等效的性能统计吗?我想对 CLI 命令做同样的事情,但谷歌搜索没有产生任何结果。

osg*_*sgx 4

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
Run Code Online (Sandbox Code Playgroud)

页面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

使用英特尔 CPU,您可以尝试英特尔 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确实对事件进行计数,但我不确定如何使用仪器收集计数器。页面https://www.robertpieta.com/counters-in-instruments/显示了如何配置 Instruments GUI 以进行事件计数:

要配置计数器,请从仪器导航菜单中选择文件 -> 记录选项。出于本文的目的,将选择按时间采样。使用+,您可以添加计数器可以计算当前连接到仪器的特定CPU上可用的特定事件。

因此,您至少可以指示 Instruments 工具随着时间的推移定期记录计数器值。该模式报告了一些问题:http://hmijailblog.blogspot.com/2015/09/using-intels-performance-counters-on-os.html