Perf stat equivalent for Mac OS?

北城余情 提交于 2021-01-24 07:13:28

问题


Is there a perf stat equivalent on Mac OS? I would like to do the same thing for a CLI command and googling is not yielding anything.


回答1:


There was Instruments tool in Mac OS X to profile applications including with hardware PMU. Default is to do sampling profiler for CPU usage. Some docs: https://en.wikipedia.org/wiki/Instruments_(software) https://help.apple.com/instruments/mac/current/ It also has command line variant: https://help.apple.com/instruments/mac/current/#/devb14ffaa5

Open Terminal, in /Applications/Utilities.

instruments -t "Allocations" -D ~/Desktop/YourTraceFileName.trace PathToYourApp

Page https://gist.github.com/loderunner/36724cc9ee8db66db305 mentions tool sample ("included in a standard Mac OS X installation").

Also, Shark tool is mentioned for older versions of Mac OS X (before 10.7) and Xcode: https://en.wikipedia.org/wiki/Apple_Developer_Tools#Shark

With Intel CPU you can try Intel Vtune profiler - https://software.intel.com/en-us/get-started-with-vtune-macos https://software.intel.com/en-us/vtune

Other and more open intel tool (partially deprecated?) is https://github.com/opcm/pcm/ which has some kind of OSX support. Docs: https://software.intel.com/en-us/articles/intel-performance-counter-monitor. Requires custom MacMSRDriver driver (kext).

perf stat does counting for events, and I'm not sure how to collect counters with Instruments. Page https://www.robertpieta.com/counters-in-instruments/ shows how to configure Instruments GUI for event counting:

To configure Counters, select File -> Recording Options from the Instruments navigation menu. For the purposes of this post, sampling by Time will be selected. Using the + you are able to add specific events that Counters can count available on the particular CPU currently connected to Instruments.

So, you at least can instruct Instruments tool to do recording of counter values periodically over time. Some problems are reported for that mode: http://hmijailblog.blogspot.com/2015/09/using-intels-performance-counters-on-os.html




回答2:


I was disappointed by the lack of a CLI equivalent to perf stat -r, so I just wrote up https://github.com/cdr/timer.

Works like:

$ 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


来源:https://stackoverflow.com/questions/61069109/perf-stat-equivalent-for-mac-os

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!