Skip to main content

perf event wrapper for python

Project description

Performance Counters api for python

Table of contents

What are the performance counters

Performance counters are special hardware registers available on most modern CPUs. These registers count the number of certain types of events: such as instructions executed, cache misses suffered, or branches mis-predicted without slowing down the kernel or applications. These registers can also trigger interrupts when a threshold number of events have passed and can thus be used to profile the code that runs on that CPU.

Reading Performance counters

  • Instructions
    • rdmsr: Reads the contents of a 64-bit model specific register (MSR) specified in the ECX register into registers EDX:EAX. This instruction must be executed at privilege level 0 or in real-address mode

    • rdpmc: Is slightly faster that the equivelent rdmsr instruction. rdpmc can also be configured to allow access to the counters from userspace, without being priviledged.

  • From Userspace (Linux) : The Linux Performance Counter subsystem provides an abstraction of these hardware capabilities. It provides per task and per CPU counters, counter groups, and it provides event capabilities on top of those. It provides "virtual" 64-bit counters, regardless of the width of the underlying hardware counters. Performance counters are accessed via special file descriptors. There's one file descriptor per virtual counter used. The special file descriptor is opened via the perf_event_open() system call. These system call do not use rdpmc but rdpmc is not necessarily faster than other methods for reading event values.

Python API

This module provide a high-level abstraction API to Linux perf events without overhead while executing

How it works:

Using perfmon library python wrapper to perform the system calls and configure the structures to create the file descriptors.

The file descriptors are passed to the workload module develop on c++ which start the target application and read from the file descriptors

Installation

sudo apt install python-dev swig libpfm4-dev
pip install performance-features

Usage

List events

from profiler import *

print(get_supported_pmus())
print(get_supported_events())

Sampling events

from profiler import *

try:
    events= [['PERF_COUNT_HW_INSTRUCTIONS'],
            ['PERF_COUNT_HW_BRANCH_INSTRUCTIONS','PERF_COUNT_HW_BRANCH_MISSES'],
            ['PERF_COUNT_SW_PAGE_FAULTS']]
    perf= Profiler(program_args= ['/bin/ls','/'], events_groups=events)
    data= perf.run(sample_period= 0.01)
    print(data)
except RuntimeError as e:
    print(e.args[0])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

performance_features-0.1.1.tar.gz (38.5 kB view details)

Uploaded Source

File details

Details for the file performance_features-0.1.1.tar.gz.

File metadata

  • Download URL: performance_features-0.1.1.tar.gz
  • Upload date:
  • Size: 38.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.7

File hashes

Hashes for performance_features-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c51e34284367ed9aab96ce8328c2dd2deca3187089fca4a41a45734cd9e33a6c
MD5 f341a5c3f1ccf5ef9d17eb1742fcf1bf
BLAKE2b-256 07c5fc33608055d63ee48160cec6d0c5dd200a80a3a07fd2c264f8607ed3304d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page