Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PerfEvent: add option to set the inherit bit #807

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions aya/src/programs/perf_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ pub enum PerfEventScope {
/// process id
pid: u32,
},
/// one process, any cpu, including child processes
OneProcessIncludingChildren {
/// process id
pid: u32,
},
/// one process, one cpu
OneProcessOneCpu {
/// cpu id
Expand Down Expand Up @@ -157,6 +162,7 @@ impl PerfEvent {
PerfEventScope::OneProcessAnyCpu { pid } => (pid as i32, -1),
PerfEventScope::OneProcessOneCpu { cpu, pid } => (pid as i32, cpu as i32),
PerfEventScope::AllProcessesOneCpu { cpu } => (-1, cpu as i32),
PerfEventScope::OneProcessIncludingChildren { pid } => (pid as i32, -1),
};
let fd = perf_event_open(
perf_type as u32,
Expand All @@ -167,6 +173,7 @@ impl PerfEvent {
sample_frequency,
false,
0,
matches!(scope, PerfEventScope::OneProcessIncludingChildren { .. }),
)
.map_err(|(_code, io_error)| SyscallError {
call: "perf_event_open",
Expand Down
4 changes: 3 additions & 1 deletion aya/src/sys/perf_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ pub(crate) fn perf_event_open(
sample_frequency: Option<u64>,
wakeup: bool,
flags: u32,
inherit: bool,
) -> SysResult<OwnedFd> {
let mut attr = unsafe { mem::zeroed::<perf_event_attr>() };

attr.config = config;
attr.size = mem::size_of::<perf_event_attr>() as u32;
attr.type_ = perf_type;
attr.sample_type = PERF_SAMPLE_RAW as u64;
// attr.inherits = if pid > 0 { 1 } else { 0 };
attr.set_inherit(if inherit { 1 } else { 0 });
attr.__bindgen_anon_2.wakeup_events = u32::from(wakeup);

if let Some(frequency) = sample_frequency {
Expand All @@ -55,6 +56,7 @@ pub(crate) fn perf_event_open_bpf(cpu: c_int) -> SysResult<OwnedFd> {
None,
true,
PERF_FLAG_FD_CLOEXEC,
false,
)
}

Expand Down
4 changes: 4 additions & 0 deletions xtask/public-api/aya.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3989,6 +3989,8 @@ pub aya::programs::perf_event::PerfEventScope::CallingProcessOneCpu
pub aya::programs::perf_event::PerfEventScope::CallingProcessOneCpu::cpu: u32
pub aya::programs::perf_event::PerfEventScope::OneProcessAnyCpu
pub aya::programs::perf_event::PerfEventScope::OneProcessAnyCpu::pid: u32
pub aya::programs::perf_event::PerfEventScope::OneProcessIncludingChildren
pub aya::programs::perf_event::PerfEventScope::OneProcessIncludingChildren::pid: u32
pub aya::programs::perf_event::PerfEventScope::OneProcessOneCpu
pub aya::programs::perf_event::PerfEventScope::OneProcessOneCpu::cpu: u32
pub aya::programs::perf_event::PerfEventScope::OneProcessOneCpu::pid: u32
Expand Down Expand Up @@ -5214,6 +5216,8 @@ pub aya::programs::PerfEventScope::CallingProcessOneCpu
pub aya::programs::PerfEventScope::CallingProcessOneCpu::cpu: u32
pub aya::programs::PerfEventScope::OneProcessAnyCpu
pub aya::programs::PerfEventScope::OneProcessAnyCpu::pid: u32
pub aya::programs::PerfEventScope::OneProcessIncludingChildren
pub aya::programs::PerfEventScope::OneProcessIncludingChildren::pid: u32
pub aya::programs::PerfEventScope::OneProcessOneCpu
pub aya::programs::PerfEventScope::OneProcessOneCpu::cpu: u32
pub aya::programs::PerfEventScope::OneProcessOneCpu::pid: u32
Expand Down