- A C++20-compatible compiler
- CMake
- Linux operating system
- Perf must be installed in the OS. (This is included by default in most cases.)
κProf uses the CMake build system. It is recommended to perform an out of tree build. It is assumed that the current directory is the source directory.
$ pwd
/path/to/kProf/
$ cmake -B build -S .
$ cmake --build buildIn case one wants to install this library, the following command must be run after the previous steps.
$ cmake --install buildAn optional demo is included in this code. In order to compile and run it, use the flag -DBUILD_DEMO=ON during building the code.
To include κProf in your source code, include the header kprof.hpp. This provides all the functionality in the kProf namespace.
- To initialize a counter, use
kProf::KProfEvent <objectName>. - When instrumenting the code, use
<objectName>.StartCounters()and<objectName>.StopCounters(). - Access and print reports with
<objectName>.GetReport(true)and<objectName>.PrintReport(). In case raw event counts are required (without κProf removing its overhead), passfalseto<objectName>.GetReport(). To print a specific report, pass it as an argument to<objectName>.PrintReport(). - In case the code is single-threaded, it is recommended to pin the resulting executable to a single core.
numactlis recommended. - Counter information can be provided at runtime by:
- Set the environment variable
KPROF_COUNTER_FILEto a CSV file containing the counter information.- The file formatting must be:
For example,label,counter_type,counter_spec
HW-instructions,PERF_TYPE_HARDWARE,PERF_COUNT_HW_INSTRUCTIONSis a valid line. Consult the manpage forperf_event_openfor possible values. - Set the environment variable
KPROF_COUNTER_CONFto valid set of counters.- The counters must be formatted as
label,type:val;for each counter, delimited by;. - Example:
KPROF_COUNTER_CONF=LLC-misses-intel,R:0x2E41for counting LLC misses on Intel architectures. - Hex codes must begin with
0xor0X. - Counter types must be
H,S,C, orRfor Hardware, software, cache, and raw pointers. Hex codes or decimals for event IDs must always be specified with typeR.
- The counters must be formatted as
- Provide a
std::stringargument pointing the CSV file when initializing thekProf::KProfEventobject.
- Set the environment variable
It is also possible to use kPRof as a dependency in your CMake project. Your executable/library needs to be linked to kProf.