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.
PerfControl pc({"perf", "record"});
pc.enable();
// do something
pc.disable();Consider the following example:
Lines 7 to 12 in eb99420
$ 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 [.] barThe function foo() is not recorded by perf, while bar() is captured.