Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Record values of Performance Monitor Counters (PM events) on OS X without Instruments

In Xcode's Instruments, there is a tool called Counters that exposes low-level counter information provided by the CPU, such as the number of instructions executed or number of cache misses:

screenshot of Counters tool in Instruments

This is similar to the 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 I'm interested in. I'd like to record the same type of stats on OS X: counting the instructions (etc.) that a certain piece of code takes, and getting the result in an automated fashion. (I don't want to use the Instruments GUI to analyze the data.)

Are there any APIs that allow this (ex: using dtrace or similar)? From some searching it sounds like the private AppleProfileFamily.framework might have the necessary hooks, but it's unclear how to go about linking to or using it.

like image 658
Sophie Alpert Avatar asked Sep 12 '15 07:09

Sophie Alpert


People also ask

How do I add counters to Performance Monitor?

In the navigation pane, expand Monitoring Tools, and then choose Performance Monitor. In the console pane toolbar, choose the Add button. In the Add Counters window, in the Select counters from computer drop-down list, choose the computer that is running Business Central Server.

How do I view performance counters?

You can view performance counters using the Microsoft Windows Reliability and Performance Monitor application. Click Start > Run. In the Open field, enter perfmon , and then click OK. From Monitoring Tools, select Performance Monitor.

What do performance counters measure in Performance Monitor?

Performance monitor Performance counters are bits of code that monitor, count, or measure events in software, which allow us to see patterns from a high-level view. They are registered with the operating system during installation of the software, allowing anyone with the proper permissions to view them.


1 Answers

In GNU/Linux I use Intel's PCM to monitor CPU utilization. I'm not sure if this works fine on OSX, but as far as I know the source-code is including the MacMSRDriver directory. I have no any OSX device, never test it anyway.

In case this source 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 build your own code based on pcm-core.cpp

like image 185
Max Rafiandy Avatar answered Sep 23 '22 21:09

Max Rafiandy