Skip to content

ShawnZhong/perf_control.hpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

perf_control.hpp

Control perf recording dynamically during program execution.

This header-only library provides a simple interface to enable or disable perf event recording at specific points in the code, allowing for targeted performance analysis.

Usage

PerfControl pc({"perf", "record"});
pc.enable();
// do something
pc.disable();

Example

Consider the following example:

PerfControl perf({"perf", "record"});
foo();
perf.enable();
bar(); // Only record this
perf.disable();
foo();

$ g++ example.cpp -o example

$ ./example
Events disabled
Events enabled
Events disabled
[ perf record: Woken up 4 times to write data ]
[ perf record: Captured and wrote 0.057 MB perf.data (939 samples) ]

$ perf report
# Overhead  Command  Shared Object     Symbol                                        
# ........  .......  ................  ..............................................
#
    96.48%  example  example           [.] bar

The function foo() is not recorded by perf, while bar() is captured.

About

Control perf recording dynamically during program execution.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published