Mac OS上是否有类似于perf stat的工具?我想对一个CLI命令执行相同的操作,但搜索并没有得到结果。
Mac OS上是否有类似于perf stat的工具?我想对一个CLI命令执行相同的操作,但搜索并没有得到结果。
Open Terminal, in /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
另一个更开放的Intel工具(部分已弃用?)是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导航菜单中选择文件 ->录制选项。 为了本文的目的,将选择按时间采样。使用+您可以添加特定事件,计数器可以计算连接到Instruments的特定CPU上可用的事件。
因此,至少可以指示Instruments工具定期隔一段时间记录计数器值。有些问题报告了该模式:http://hmijailblog.blogspot.com/2015/09/using-intels-performance-counters-on-os.html
我对缺乏与perf stat -r
等效的CLI感到失望,所以我刚刚写了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
这里不包含高级执行计数器,只有挂钟统计数据。
perf
的一个次要功能(perf stat -r
重复计数),而不是主要功能(硬件性能事件)。 - Peter Cordes