Mac OS的Perf stat等效工具是什么?

7

Mac OS上是否有类似于perf stat的工具?我想对一个CLI命令执行相同的操作,但搜索并没有得到结果。

2个回答

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

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


-1

我对缺乏与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

这里不包含高级执行计数器,只有挂钟统计数据。


5
只测量挂钟时间吗?没有性能计数器,甚至没有用户与系统时间的区分吗?这只涉及perf的一个次要功能(perf stat -r 重复计数),而不是主要功能(硬件性能事件)。 - Peter Cordes
你说得对,@PeterCordes。我的具体用例不需要高级计数器。我编辑了帖子以澄清。 - Ammar Bandukwala

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接