Install “perf” on Mac

MacOS

Question or issue on macOS:

I need the “perf” utility to monitor the program on my Mac. I know linux comes with it, but is it available on Mac?

I am working on a OSX 10.9 Mavericks and tried “port search” for perf or linux-tools, but I couldn’t get any results.

How to solve this problem?

Solution no. 1:

As @Sami Laine said in his comment, the Linux perf tool is dependent on Linux specific code. It relies on the perf_event_open system call which is not standardized.

Note: Maybe you could search how MacOSX users are using recent hardware performance counters.

Solution no. 2:

On MacOS you can use the “Instruments” application to profile your code. I like to use the “Time Profiler” which will show you how much time your application is its various parts during execution. I haven’t used perf myself, but from talks/videos that I’ve seen this seems to be the most common use.

To use the “Time Profiler”:

  1. Run Instruments, select Time Profiler
  2. At the top left, select your target (executable)
  3. Hit the Record button on the top left and let it run for a little
    while.
  4. Pause or Stop the execution and drill down on your calls in the main
    window.

Hope this helps.

Solution no. 3:

On OSX you can use sample together with filtercalltree.

Solution no. 4:

Check out Google Perf Tool

If you dont have brew installed:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null

If you have brew installed:

brew install google-perftools

Reference: https://github.com/gperftools/gperftools

Hope this helps!