Skip to content

Commit 0f44f4a

Browse files
committed
PerfEvent: add option to set the inherit bit
The inherit bit allows extending perf scope to the new child processes.
1 parent 0cd620a commit 0f44f4a

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

aya/src/programs/perf_event.rs

+7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ pub enum PerfEventScope {
6666
/// process id
6767
pid: u32,
6868
},
69+
/// one process, any cpu, including child processes
70+
OneProcessIncludingChildren {
71+
/// process id
72+
pid: u32,
73+
},
6974
/// one process, one cpu
7075
OneProcessOneCpu {
7176
/// cpu id
@@ -157,6 +162,7 @@ impl PerfEvent {
157162
PerfEventScope::OneProcessAnyCpu { pid } => (pid as i32, -1),
158163
PerfEventScope::OneProcessOneCpu { cpu, pid } => (pid as i32, cpu as i32),
159164
PerfEventScope::AllProcessesOneCpu { cpu } => (-1, cpu as i32),
165+
PerfEventScope::OneProcessIncludingChildren { pid } => (pid as i32, -1),
160166
};
161167
let fd = perf_event_open(
162168
perf_type as u32,
@@ -167,6 +173,7 @@ impl PerfEvent {
167173
sample_frequency,
168174
false,
169175
0,
176+
matches!(scope, PerfEventScope::OneProcessIncludingChildren { .. })
170177
)
171178
.map_err(|(_code, io_error)| SyscallError {
172179
call: "perf_event_open",

aya/src/sys/perf_event.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ pub(crate) fn perf_event_open(
2525
sample_frequency: Option<u64>,
2626
wakeup: bool,
2727
flags: u32,
28+
inherit: bool,
2829
) -> SysResult<OwnedFd> {
2930
let mut attr = unsafe { mem::zeroed::<perf_event_attr>() };
3031

3132
attr.config = config;
3233
attr.size = mem::size_of::<perf_event_attr>() as u32;
3334
attr.type_ = perf_type;
3435
attr.sample_type = PERF_SAMPLE_RAW as u64;
35-
// attr.inherits = if pid > 0 { 1 } else { 0 };
36+
attr.set_inherit(if inherit { 1 } else { 0 });
3637
attr.__bindgen_anon_2.wakeup_events = u32::from(wakeup);
3738

3839
if let Some(frequency) = sample_frequency {
@@ -55,6 +56,7 @@ pub(crate) fn perf_event_open_bpf(cpu: c_int) -> SysResult<OwnedFd> {
5556
None,
5657
true,
5758
PERF_FLAG_FD_CLOEXEC,
59+
false,
5860
)
5961
}
6062

xtask/public-api/aya.txt

+4
Original file line numberDiff line numberDiff line change
@@ -3989,6 +3989,8 @@ pub aya::programs::perf_event::PerfEventScope::CallingProcessOneCpu
39893989
pub aya::programs::perf_event::PerfEventScope::CallingProcessOneCpu::cpu: u32
39903990
pub aya::programs::perf_event::PerfEventScope::OneProcessAnyCpu
39913991
pub aya::programs::perf_event::PerfEventScope::OneProcessAnyCpu::pid: u32
3992+
pub aya::programs::perf_event::PerfEventScope::OneProcessIncludingChildren
3993+
pub aya::programs::perf_event::PerfEventScope::OneProcessIncludingChildren::pid: u32
39923994
pub aya::programs::perf_event::PerfEventScope::OneProcessOneCpu
39933995
pub aya::programs::perf_event::PerfEventScope::OneProcessOneCpu::cpu: u32
39943996
pub aya::programs::perf_event::PerfEventScope::OneProcessOneCpu::pid: u32
@@ -5214,6 +5216,8 @@ pub aya::programs::PerfEventScope::CallingProcessOneCpu
52145216
pub aya::programs::PerfEventScope::CallingProcessOneCpu::cpu: u32
52155217
pub aya::programs::PerfEventScope::OneProcessAnyCpu
52165218
pub aya::programs::PerfEventScope::OneProcessAnyCpu::pid: u32
5219+
pub aya::programs::PerfEventScope::OneProcessIncludingChildren
5220+
pub aya::programs::PerfEventScope::OneProcessIncludingChildren::pid: u32
52175221
pub aya::programs::PerfEventScope::OneProcessOneCpu
52185222
pub aya::programs::PerfEventScope::OneProcessOneCpu::cpu: u32
52195223
pub aya::programs::PerfEventScope::OneProcessOneCpu::pid: u32

0 commit comments

Comments
 (0)