For the VS Profiler:
To view a list of a list of all CPU counters that are supported on the current platform
In Performance Explorer, right-click the performance session and then click Properties.
Do one of the following:
- Click Sampling, and then select Performance counter from the Sample event list. The CPU counters are listed in Available performance counters.
Note Click Cancel to return to the previous sampling configuration.
-or-
- Select CPU Counters, and then select Collect CPU Counters. The CPU counters are listed in Available counters.
Note Click Cancel to return to the previous counter collection configuration.
You can't access the full CPU counters from your program, because: https://stackoverflow.com/a/8800266/613130
You can use RDPMC instruction or __readpmc MSVC compiler intrinsic, which is the same thing.
However, Windows prohibits user-mode applications to execute this instruction by setting CR4.PCE to 0. Presumably, this is done because the meaning of each counter is determined by MSR registers, which are only accessible in kernel mode. In other words, unless you're a kernel-mode module (e.g. a device driver), you are going to get "privileged instruction" trap if you attempt to execute this instruction.
(RDPMC is the instruction that returns the CPU counters)
I'll add that normally the number of instructions executed is quite useless. What is important is the CPU time that was used to execute some code. Each instruction has a different CPU time, so even knowing the number of them, you wouldn't know the number of CPU cycles/time used.
If you want to know the CPU cycles used for some instructions, then you can use the ASM instruction RDTSC/RDTSCP. Using it in C# is complex and quite time-consuming (so using it is slow enough that it often compromises the measuring you are trying to do). If you are interested, I wrote a response about it some days ago: https://stackoverflow.com/a/29646856/613130