Perf stat equivalent for Mac OS?
Asked Answered
C

2

7

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.

Caston answered 6/4, 2020 at 21:15 Comment(0)
E
4

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

Effusion answered 9/4, 2020 at 23:10 Comment(0)
L
0

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

This doesn't contain advanced execution counters, just wall clock statistics.

Luisaluise answered 30/5, 2020 at 18:46 Comment(2)
Is that just measuring wall-clock time? No performance counters, not even user vs. sys time? That addresses only one of the minor features of perf (perf stat -r repeat count), not the major point (HW performance events)Matney
You're right @PeterCordes. My specific use case doesn't demand advanced counters. I edited the post to clarify.Luisaluise

© 2022 - 2024 — McMap. All rights reserved.