百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

perf-cpp

> 数据库
开源

直接从 C++ 应用程序中轻量级记录和采样性能计数器,针对特定代码段。

191 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

直接从 C++ 应用程序中轻量级记录和采样性能计数器,针对特定代码段。

perf-cpp: Hardware Performance Monitoring for C++

Quick Start | Building | Documentation | System Requirements

perf-cpp lets you profile specific parts of your code, not the entire program.

Tools like Linux Perf, Intel® VTune™, and AMD uProf profile everything: application startup, configuration parsing, data loading, and all your helper functions. perf-cpp is different: place start() and stop() around exactly the code you want to measure. Profile one sorting algorithm, or count cache misses in a single hash table lookup. Wrap two memory allocators separately, and you get a fair comparison.

Features

Built around Linux's perf subsystem, perf-cpp supports counting and sampling hardware events for specific code blocks:

  • Record hardware events like perf stat, but only around the code you care about (documentation)
  • Calculate metrics like cycles per instruction or cache miss ratios from the counters (documentation)
  • Read counter values without stopping the counter for low-overhead measurements in tight loops (documentation)
  • Sample instructions and memory accesses like perf record and perf mem record, but targeted at specific functions (documentation)
  • Export and visualize results: write samples to CSV, generate flame graphs, or correlate memory accesses with specific data structures
  • Mix built-in events like cycles and cache misses with processor-specific PMU events (documentation)

See the examples and full documentation for details.

Quick Start

Record Hardware Event Statistics

…

cpp #include

// Create the sampler auto sampler = perf::Sampler{};

// Specify when a sample is recorded: every 50,000th cycle sampler.trigger("cycles", perf::Period{50000U});

// Specify what data is included in a sample: time, CPU ID, instruction sampler.values() .timestamp(true) .cpu_id(true) .logical_instruction_pointer(true);

// Run the workload sampler.start(); code_to_profile(); // [!NOTE]

See the sampling guide for what data you can record. Also check out the sampling on multiple CPUs/threads guide for parallel sampling.

Building

perf-cpp can be built as a static or shared library.

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

[!NOTE] See the building guide for CMake integration and build options.

Documentation

The full documentation is available at jmuehlig.github.io/perf-cpp.

See also: Examples | Changelog

System Requirements

  • GCC 11 or newer, or Clang 14 or newer, with C++17 support.
  • CMake version 3.10 or higher.
  • Linux Kernel 4.0 or newer (some features require a newer kernel).
  • perf_event_paranoid setting: Adjust as needed to allow access to performance counters (see the perf paranoid documentation).
  • Python 3, if you use processor-specific hardware event generation.

Contributing

Contributions are welcome. Open an issue or submit a pull request.

To build and run the tests:

bash
cmake . -B build -DBUILD_TESTS=ON
cmake --build build --target tests
./build/bin/tests

[!NOTE] Most tests require access to hardware performance counters via perf_event_open. If your system restricts access (e.g., in containers or VMs), some tests will fail. See the perf paranoid documentation.

For questions or feedback: [email protected].


Related Projects

Other profiling tools:

  • PAPI monitors CPU counters, GPUs, I/O, and more.
  • Likwid is a set of command-line tools for benchmarking with an extensive wiki.
  • PerfEvent is a lightweight wrapper for performance counters.
  • Intel's Instrumentation and Tracing Technology lets you control Intel VTune Profiler from your code.
  • Want to go lower-level? Use perf_event_open directly.

Resources on Profiling

Academic Papers

  • Quantitative Evaluation of Intel PEBS Overhead for Online System-Noise Analysis (2017)
  • Analyzing memory accesses with modern processors (2020)
  • On the Precision of Precise Event Based Sampling (2020)
  • CachePerf: A Unified Cache Miss Classifier via Hybrid Hardware Sampling (2022)
  • Precise Event Sampling on AMD Versus Intel: Quantitative and Qualitative Comparison (2023)
  • Efficient Cross-platform Multiplexing of Hardware Performance Counters via Adaptive Grouping (2024)
  • Multi-level Memory-Centric Profiling on ARM Processors with ARM SPE (2024)
  • Breaking the Cycle - A Short Overview of Memory-Access Sampling Differences on Modern x86 CPUs (2025)

Blog Posts

  • C2C - False Sharing Detection in Linux Perf (2016)
  • PMU counters and profiling basics (2018)
  • Advanced profiling topics. PEBS and LBR (2018)
  • The Linux perf Event Scheduling Algorithm (2019)
  • Performance Speed Limits (2019)
  • Detect false sharing with Data Address Profiling (2019)
  • Data-type profiling for perf (2023)
  • Analyze cache behavior with Perf C2C on Arm (2023)
  • How Small Can a Measured Region Be Before perf Counters Lie? (2026)

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++cppcpp17instruction-based-samplinglibrary

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库