2

I would like to measure branch prediction fails on Xcode for Intel processors on Mac OS X, with the obvious intent of speed optimization.

Is there a way to program XCode's Instruments in order to achieve this?

I have already checked, and this information is unfortunately not present in Xcode documentation. I suspect this could be achieved with some custom setting.

The purpose is identifying optimization problems such as this one: Why is it faster to process a sorted array than an unsorted array?

I am aware that an Intel commercial solution exists, for Intel Processors running on Linux and Windows. On OS X you can apparently only monitor a remote Intel processor running on a Linux or Windows system.

Rather than a commercial tool, I would prefer a way to set/program Xcode and Apple tools to gain at least a minimum of visibility on this issue.

Community
  • 1
  • 1
Michele Giuseppe Fadda
  • 1,302
  • 1
  • 17
  • 26
  • 2
    I don't know about XCode, but Cachegrind can do it. http://valgrind.org/docs/manual/cg-manual.html –  Nov 26 '15 at 14:13
  • 2
    I found out that an OS X compatible version of Cachegrind exists, looks promising. I will compile it and try it out. On another side, I noticed that the Counters instruments in Xcode profiling tools (which is deeply undocumented) seems to allow "counting" what looks to be exactly branch prediction failures. – Michele Giuseppe Fadda Dec 10 '15 at 11:56

2 Answers2

5

For anyone else struggling with this, in Instruments 9.2:

  • Select Counters
  • Go to File>Recording Options
  • Select "Sample by: Events"
  • Choose an event name (see docs), in this case "BR_MISP_RETIRED.CONDITIONAL":

Screenshot of Recording Options in Instruments

that other guy
  • 116,971
  • 11
  • 170
  • 194
2

There are hardware performance counters (PMC) in XCode's Instuments:

https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/MeasuringCPUUse.html

There are hidden by default branch events in Window > Manage PM Events, according to http://meandmark.com/blog/2011/10/event-profiler-and-counters-instruments/

osgx
  • 90,338
  • 53
  • 357
  • 513