GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • jmuehlig/perf-cpp
  • Home
  • Building
  • What are Performance Counters?
  • Basics
  • Live Events
  • Multi-Thread, -Core & -Process
  • Metrics
  • Customizing Events
  • Basics
  • Multi-Thread & Multi-Core
  • Symbols & Flamegraphs
  • CSV Export
  • Perf Report

This view

  • Original page
  • New address

GeezerVison is showing jmuehlig.github.io — perf-cpp

perf-cpp: Hardware Performance Monitoring for C++¶

perf-cpp lets you measure hardware performance counters for specific parts of your code — not the entire program. Place start() and stop() around exactly the code you care about.

Tip

New to performance counters? Start with What are Hardware Performance Counters?

Count Hardware Events¶

Count instructions, cycles, cache misses, and more while your code runs:

#include <perfcpp/event_counter.hpp>

auto event_counter = perf::EventCounter{};
event_counter.add({"seconds", "instructions", "cycles", "cache-misses"});

event_counter.start();
code_to_profile(); /// <-- your code here
event_counter.stop();

const auto result = event_counter.result();
for (const auto [event_name, value] : result)
{
    std::cout << event_name << ": " << value << std::endl;
}
seconds:      0.0955897
instructions: 5.92087e+07
cycles:       4.70254e+08
cache-misses: 1.35633e+07

→ Recording event statistics in detail

Sample Instructions and Memory Accesses¶

Record snapshots every N events — capturing instruction pointers, timestamps, memory addresses, cache levels, and more:

#include <perfcpp/sampler.hpp>

auto sampler = perf::Sampler{};
sampler.trigger("cycles", perf::Period{50000U});
sampler.values()
    .timestamp(true)
    .cpu_id(true)
    .logical_instruction_pointer(true);

sampler.start();
code_to_profile(); /// <-- your code here
sampler.stop();

const auto samples = sampler.result();
samples.to_csv("samples.csv");

→ Sampling in detail

Next Steps¶

  • Record events for a code region → Recording
  • Find where events happen → Sampling
  • Measure across threads or cores → Parallel Recording / Parallel Sampling
  • Combine counters into ratios (CPI, miss rates) → Metrics
  • Generate flamegraphs → Symbols & Flamegraphs

Building¶

git clone https://github.com/jmuehlig/perf-cpp.git
cd perf-cpp
cmake . -B build
cmake --build build

→ Build options and CMake integration

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.