perf-cpp can be build manually or included into CMake projects.
Note
Throughout the documentation, we use ./build as the build directory.
However, the build directory can be any directory of your choice (including .).
git clone https://github.com/jmuehlig/perf-cpp.git cd perf-cpp # Optional: switch to this development version git checkout v0.12.3
cmake . -B build
cmake --build buildTo install the library, specify the CMAKE_INSTALL_PREFIX:
# Generate Makefile cmake . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install/dir # Build cmake --build build # Install cmake --install build
The library will then be available for discovery via CMake and find_package (see below).
With -DGEN_PROCESSOR_EVENTS=1, the build process will try to read the processor-specific events from the event library (events/) and generate a source file (src/processor_specific_event_provider.cpp) that adds these events to every (the default and manually instantiated) perf::CounterDefinition (see also the documentation on hardware events).
With this option, processor-specific events can be used like built-in ones.
# Generate Makefile and source file for processor-specific events cmake . -B build -DGEN_PROCESSOR_EVENTS=1 # Build Library cmake --build build
Important
Depending on the underlying processor, the source file can grow very large and increase compilation time significantly.
Enable example compilation with -DBUILD_EXAMPLES=1 and build the examples target:
# Generate Makefile cmake . -B build -DBUILD_EXAMPLES=1 # Build Library and Examples cmake --build build --target examples
The example binaries will be located in build/examples/bin.
By default, perf-cpp is build as a static library.
You can request to build a shared library with -DBUILD_LIB_SHARED=1:
cmake . -B build -DBUILD_LIB_SHARED=1
cmake --build buildperf-cpp uses CMake as its build system, facilitating integration into additional CMake projects. Choose from the following methods:
Include ExternalProject in your CMakeLists.txt and define the project:
include(ExternalProject) ExternalProject_Add( perf-cpp-external GIT_REPOSITORY "https://github.com/jmuehlig/perf-cpp" GIT_TAG "v0.12.3" PREFIX "lib/perf-cpp" INSTALL_COMMAND cmake -E echo "" )
- Add
lib/perf-cpp/src/perf-cpp-external/includeto yourinclude_directories(). - Add
lib/perf-cpp/src/perf-cpp-external-buildto yourlink_directories().
Note: The directory lib/ can be any folder of your choice.
Include FetchContent in your CMakeLists.txt and define the project:
include(FetchContent) FetchContent_Declare( perf-cpp-external GIT_REPOSITORY "https://github.com/jmuehlig/perf-cpp" GIT_TAG "v0.12.3" ) FetchContent_MakeAvailable(perf-cpp-external)
- Add
perf-cppto your linked libraries. - Add
${perf-cpp-external_SOURCE_DIR}/include/to your include directories.
If perf-cpp is already installed on your system (see install instructions above), you can simply use find_package to link it with your project:
find_package(perf-cpp REQUIRED) target_link_libraries(perf-cpp::perf-cpp)