pyperfcounter is a ctypes-based Python wrapper of Linux's new performance counter subsystem
Currently you have to patch your kernel to get perfcounter support: http://people.redhat.com/mingo/perfcounters/
This wrapper is compatible with version 8 of the patch. It supports all architectures where perfcounters are supported: x86, x86_64 and ppc. Until glibc gets support for the perf_counter_open() syscall, this library uses the glibc raw syscall(2) interface.
It works on any Python version with ctypes support. Python 2.5 and later already have ctypes included.
import perfcounter, time ctr = perfcounter.perfcounter('cpu-cycles', cpu=0) lastval = 0 while True: time.sleep(1) val = ctr.get() print val - lastval lastval = val