Simple PMU

Simple PMU is simple way to count cycles (and a few other events)
inside programs on Intel x86 CPUs.
It aims to be a replacement for RDTSC, which is not really
reliable anymore on modern systems due to Turbo mode and cpu frequency scaling.
See this presentation
for an tutorial.
For more details see the manual.