Mac OS X 中有 Instruments 工具来分析应用程序,包括硬件 PMU。默认是对 CPU 使用情况进行采样分析器。一些文档:https://en.wikipedia.org/wiki/Instruments_(软件) https://en.wikipedia.org/wiki/Instruments_(software) https://help.apple.com/instruments/mac/current/ https://help.apple.com/instruments/mac/current/它还有命令行变体:https://help.apple.com/instruments/mac/current/#/devb14ffaa5 https://help.apple.com/instruments/mac/current/#/devb14ffaa5
打开 /Applications/Utilities 中的终端。
instruments -t "Allocations" -D ~/Desktop/YourTraceFileName.trace PathToYourApp
Page https://gist.github.com/loderunner/36724cc9ee8db66db305 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 https://en.wikipedia.org/wiki/Apple_Developer_Tools#Shark
使用 Intel CPU,您可以尝试 Intel Vtune Profiler -https://software.intel.com/en-us/get-started-with-vtune-macos https://software.intel.com/en-us/get-started-with-vtune-macos https://software.intel.com/en-us/vtune https://software.intel.com/en-us/vtune
其他更开放的英特尔工具(部分弃用?)是https://github.com/opcm/pcm/ https://github.com/opcm/pcm/它有某种 OSX 支持。文件:https://software.intel.com/en-us/articles/intel-performance-counter-monitor https://software.intel.com/en-us/articles/intel-performance-counter-monitor。需要定制MacMSR驱动程序 https://github.com/opcm/pcm/tree/master/MacMSRDriver驱动程序(kext)。
perf stat
确实对事件进行计数,但我不确定如何使用仪器收集计数器。页https://www.robertpieta.com/counters-in-instruments/ https://www.robertpieta.com/counters-in-instruments/显示如何配置 Instruments GUI 以进行事件计数:
要配置计数器,请从仪器导航菜单中选择文件 -> 记录选项。
出于本文的目的,将选择按时间采样。使用+,您可以添加计数器可以计算当前连接到仪器的特定CPU上可用的特定事件。
因此,您至少可以指示 Instruments 工具随着时间的推移定期记录计数器值。该模式报告了一些问题:http://hmijailblog.blogspot.com/2015/09/using-intels-performance-counters-on-os.html http://hmijailblog.blogspot.com/2015/09/using-intels-performance-counters-on-os.html