@@ -32,8 +32,12 @@ namespace perf {
32
32
33
33
const Feature PerfListener::feature = Feature::PERF;
34
34
35
- PerfListener::PerfListener (uint64_t instructionCountLimit)
36
- : perfFd_(-1 ), instructionCountLimit_(instructionCountLimit) {}
35
+ PerfListener::PerfListener (
36
+ uint64_t instructionCountLimit,
37
+ uint64_t samplingFactor)
38
+ : instructionCountLimit_(instructionCountLimit)
39
+ , samplingFactor_{std::max<uint64_t >(1ULL , samplingFactor)}
40
+ , perfFd_{-1 } {}
37
41
38
42
PerfListener::~PerfListener () {
39
43
// TODO: handle closing perfFd in move assignement / constructor as well
@@ -72,7 +76,6 @@ void PerfListener::onPostForkParent(pid_t childPid) {
72
76
TRACE ();
73
77
74
78
childPid_ = childPid;
75
- // TODO: fix this // What fix?
76
79
struct perf_event_attr attrs {};
77
80
memset (&attrs, 0 , sizeof (attrs));
78
81
attrs.type = PERF_TYPE_HARDWARE;
@@ -83,8 +86,9 @@ void PerfListener::onPostForkParent(pid_t childPid) {
83
86
attrs.exclude_hv = 1 ;
84
87
attrs.disabled = 1 ;
85
88
attrs.enable_on_exec = 1 ;
89
+ attrs.inherit = 1 ;
86
90
if (instructionCountLimit_ != 0 ) {
87
- attrs.sample_period = instructionCountLimit_;
91
+ attrs.sample_period = instructionCountLimit_ / samplingFactor_ ;
88
92
attrs.wakeup_events = 1 ;
89
93
}
90
94
// Apparently older (3.13) kernel versions doesn't support
0 commit comments