Clone wiki

pyperfcounter / Home


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:

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.

Simple usage

import perfcounter, time
ctr = perfcounter.perfcounter('cpu-cycles', cpu=0)

lastval = 0
while True:
  val = ctr.get()
  print val - lastval
  lastval = val