You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
PapiCPP is a C++ wrapper for the Performance API (PAPI), providing an easy and convenient interface to access hardware performance counters. This library allows you to use PAPI's event and counter functionalities in a C++ friendly way, abstracting away low-level details and offering features like event sets, counter tracking, and printing event statistics.
Note:
The PAPI library is only available for Linux OS and its available functionality is hardware dependent.
Features
Easy-to-use interface for working with PAPI performance counters.
Template-based approach for event sets, allowing you to group and track multiple events at once.
Automatic event code to name resolution.
Stream output support for easy display of event data.
Exception handling for PAPI library errors.
Prerequisites
Before using PapiCPP, ensure that you have the PAPI library installed on your system. It is typically available through package managers on many Linux distributions or can be compiled from source.
PAPI version 5.x or later is required.
A C++17 compatible compiler.
Checking Available PAPI Preset Events
PAPI comes with preset events. Supported preset events will depend on your computers architecture.
To check available preset events, run the following:
papi_avail -a
Using PapiCPP
PAPI_CPP makes use of templates to allow you to pass in the preset event codes from the PAPI C library. Use these event codes with the C++papi::event_set wrapper class and it will handle all initialization, and de-initialization for the underlying PAPI code.
Some brief example code may look like the following:
#include<iostream>#include"papiCPP.h"intmain(int argc,char **argv) {// Count total instructions and cpu cyclespapi::event_set<PAPI_TOT_INS,PAPI_TOT_CYC> events;events.start_counters();// Start counting{// Code you want to profile}events.stop_counters();// Stop countingstd::cout << events << std::endl;// Print all events// Alternatively you can print specific events with// the .get or .at functionsstd::cout<<"Total IPC ="<< (double) events.get<PAPI_TOT_INS>().counter() / (double) events.get<PAPI_TOT_CYC>().counter()<< std::endl;return0;}