Git Product home page Git Product logo

perflib's Introduction

perflib

Description: a python library for accessing CPU performance counters on linux.

Prerequisites

sudo apt-get install build-essential
sudo apt-get install linux-tools-generic

Installation from pip

pip install perflib

Installation from source

./autogen.sh
./configure

make -j
make install

Example

import perflib

print(perflib.__name__)
print(perflib.__doc__)
print(perflib.__version__)

# print the available performance counters
print(perflib.get_available_counters())

# create a new performance counter object
# will record the performance for *this* process across all CPUs
p = perflib.PerfCounter(counter_name='LIBPERF_COUNT_HW_INSTRUCTIONS')

p.start()
# do computation here...
p.stop()

print('The number of instructions that were executed:', p.getval())

p.reset() # do this to *zero* out the counter for a fresh start

p.start()
# do computation here...
p.stop()

Calibration

import perflib
import numpy as np

p = perflib.PerfCounter(counter_name='LIBPERF_COUNT_HW_INSTRUCTIONS')

N = 10000
for _ in range(N):
    p.start()
    p.stop()
    vals.append(p.getval())
    p.reset()

vals = np.asarray(vals)

print('min', np.min(vals))
print('max', np.max(vals))
print('median', np.median(vals))
print('mean', np.mean(vals))
print('stdev', np.std(vals))

# prints ...
# min 1899
# max 19398
# median 1965
# mean 1983.2009
# stdev 269.0817

Available counters

python
>>> import perflib
>>> counters = perflib.get_available_counters()
>>> print( '\n'.join(counters) )
LIBPERF_COUNT_SW_CPU_CLOCK
LIBPERF_COUNT_SW_TASK_CLOCK
LIBPERF_COUNT_SW_CONTEXT_SWITCHES
LIBPERF_COUNT_SW_CPU_MIGRATIONS
LIBPERF_COUNT_SW_PAGE_FAULTS
LIBPERF_COUNT_SW_PAGE_FAULTS_MIN
LIBPERF_COUNT_SW_PAGE_FAULTS_MAJ
LIBPERF_COUNT_HW_CPU_CYCLES
LIBPERF_COUNT_HW_INSTRUCTIONS
LIBPERF_COUNT_HW_CACHE_REFERENCES
LIBPERF_COUNT_HW_CACHE_MISSES
LIBPERF_COUNT_HW_BRANCH_INSTRUCTIONS
LIBPERF_COUNT_HW_BRANCH_MISSES
LIBPERF_COUNT_HW_BUS_CYCLES
LIBPERF_COUNT_HW_CACHE_L1D_LOADS
LIBPERF_COUNT_HW_CACHE_L1D_LOADS_MISSES
LIBPERF_COUNT_HW_CACHE_L1D_STORES
LIBPERF_COUNT_HW_CACHE_L1I_LOADS_MISSES
LIBPERF_COUNT_HW_CACHE_LL_LOADS
LIBPERF_COUNT_HW_CACHE_LL_LOADS_MISSES
LIBPERF_COUNT_HW_CACHE_LL_STORES
LIBPERF_COUNT_HW_CACHE_LL_STORES_MISSES
LIBPERF_COUNT_HW_CACHE_DTLB_LOADS
LIBPERF_COUNT_HW_CACHE_DTLB_LOADS_MISSES
LIBPERF_COUNT_HW_CACHE_DTLB_STORES
LIBPERF_COUNT_HW_CACHE_DTLB_STORES_MISSES
LIBPERF_COUNT_HW_CACHE_ITLB_LOADS
LIBPERF_COUNT_HW_CACHE_ITLB_LOADS_MISSES
LIBPERF_COUNT_HW_CACHE_BPU_LOADS
LIBPERF_COUNT_HW_CACHE_BPU_LOADS_MISSES

perflib's People

Contributors

jremmons avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.