27

Shark, Apple's profiler which let you configure custom performance counters, is no longer supported in OSX Mountain Lion since it can't run a 32-bit kernel. Instruments.app, Apple's replacement for Shark, doesn't seem to support reading performance counters such as L1 cache hits/misses**. Is there anyway to actually setup and read performance counters on OS X? Even if there is no application, is there some user-land API to do this?

**Instruments.app does seem to have an interface for performance counters, but on my Retina MacBook Pro, the PM Events window lists no events, and indicates "Device: Unknown." Are there any other alternatives to Instruments?

user1775117
  • 333
  • 1
  • 4
  • 7

1 Answers1

40

Yes. It's there, but difficult to find and clumsy to use (ver.4.5).

  • Launch Instruments.
  • You are greeted by the Wizard
  • Choose "Blank" template for OS X
  • Press cmd+L to display the Library
  • Add "Counters" instrument to your Instruments document
  • Press cmd+shf+P -- you are presented with the PM Events floating window.
  • Let's evaluate "Divide Operations executed" -- Add "Divide Operations executed" to the PM Events window's search field.
  • Now set the "State" of "Divide Operations executed" to "Visible"
  • Now back to the main document window, press cmd+I to display the info popover of the "Counters" instrument.
  • Press the + button
  • Set the new Counter's event to "Divide Operations executed"
  • Begin sampling...
  • End sampling...

You will see the results in Instruments' table columns. Of course, there are many events you could record -- So find the L1 cache events you are interested in and add them instead of divides.

Also be prepared for system freezes (one happened while writing this up).

justin
  • 101,751
  • 13
  • 172
  • 222
  • This looks like the right solution. However, on my Retina MacBook Pro, the PM Events window is empty, and it notes "Device: Unknown Processor." I am not the first to see this [problem](http://lists.apple.com/archives/xcode-users/2012/Jan/msg00048.html). – user1775117 Oct 26 '12 at 04:19
  • @user1775117 "Unknown Processor" also appears to be quite an unusual problem (judging by low number of google results) -- I assure you, the window is populated on my Sandy Bridge MBP. In any event, if you want or (in this case) need to dig deeper -- this is largely built on DTrace, which you can try using from the command line or as a custom instrument. – justin Oct 26 '12 at 05:35
  • 11
    In Instruments 6.1, `cmd`+`shf`+`P` no longer works. Instead, open the Record Settings tab of the Detail view on the side, and hit the `+` button below the "Events and Formulas" view. – thakis Sep 08 '15 at 00:28
  • @thakis maybe you know how to get it in version 7.2 ? I can't either find `Record settings` in Detailed view – user1016265 Jan 11 '16 at 08:57
  • 3
    @user1016265 use the "Counters" template and access the Record Settings by View > Inspectors > Show Record Settings – justin Jan 31 '16 at 06:06
  • 9
    "you are greeted by the wizard" is one of the most weird things to write in a tutorial when taken out of context. – noɥʇʎԀʎzɐɹƆ May 31 '16 at 19:58
  • You also need to disable system integrity: `csrutil disable` https://www.macbartender.com/system-item-setup/ – Dorian Oct 30 '16 at 16:00