tags:

views:

43

answers:

1

I'm looking to sample the hardware event "instructions retired" or "exclusive instructions retired" from an intel chip from a C# application.

Specifically, I need to sample this number at the beginning and end of a function call, so running a profiling run using cpu counters in visual studio 2010 according to this article:

http://msdn.microsoft.com/en-us/library/bb385772.aspx

does not help. Using CPU counters and running a sampling profile, you can get the total # of instructions retired for your entire application. I can't re-assembly this application to only call just this function, so i need to be more specific about the "start" and "end" of this instructions retired sample.

Does anyone know of some assembly instruction that will read the instructions retired hardware event? Presumably, if this was available, I could somehow call this assembly instruction directly from the beginning and end of my C# method.

A: 

PAPI is a very promising lead, however, I believe they discontinued support for Windows (and therefore .NET C#) quite a few years ago.

On the windows front, Visual Studio 2010 Premium comes with performance explorer. If you run any project or binary in instrumentation mode, you can get access to hardware events such as instructions retired.

The results can be somewhat mixed and inconsistent depending external factors, but it integrates with Visual Studio nicely and you get detailed counts (avg, maximum, total) on a per method/module level.

Intel V-tune performance analyzer also exposes these natively. I haven't played with this tool yet but it might be a more flexible API than what Visual Studio 2010 exposes.

Fred Wang