Writing performance monitor counter values ​​(PM events) on OS X without tools

Xcode Instruments has a tool called Counters that provides low-level counter information provided by the CPU, such as the number of instructions executed or the number of misses in the cache:

screenshot of Counters tool in Instruments

This is similar to Linux syscall perf_event_open introduced in Linux 2.6.32. On Linux, I can use perf_event_open , then start / stop profiling around the section of my code that interests me. I would like to write down the same type of statistics in OS X: counting instructions (etc.), that a certain piece of code and getting the result in automatic mode. (I do not want to use the graphical interface of tools for data analysis.)

Are there any APIs that allow this (for example: using dtrace or similar)? From some searches, it sounds as if the private AppleProfileFamily.framework might have the necessary interceptors, but it's unclear how to link or use it.

+51
profiling instruments macos
Sep 12 '15 at 7:57
source share
1 answer

On GNU / Linux, I use Intel PCM to monitor CPU usage. I'm not sure if this works well on OSX, but as far as I know, the source code includes the MacMSRDriver directory. I do not have any OSX device, never check it.

If this source is compiled on your device, just run:

pcm.x -r -- your_program your_program_parameter

or if you want advanced profiling, use pcm-core.x instead, or you can create your own code based on pcm-core.cpp

+1
Jun 29 '16 at 2:43 on
source share



All Articles