diff --git a/aya/src/programs/probe.rs b/aya/src/programs/probe.rs index 6ae5c353..bb92cc4c 100644 --- a/aya/src/programs/probe.rs +++ b/aya/src/programs/probe.rs @@ -151,9 +151,8 @@ fn create_as_trace_point( ), }; - // TODO: pid and cpu handling let tpid = read_sys_fs_trace_point_id(event_type, &event_alias)?; - let fd = perf_event_open_trace_point(tpid).map_err(|(_code, io_error)| { + let fd = perf_event_open_trace_point(tpid, pid).map_err(|(_code, io_error)| { ProgramError::SyscallError { call: "perf_event_open".to_owned(), io_error, diff --git a/aya/src/programs/trace_point.rs b/aya/src/programs/trace_point.rs index 5d128ac4..eba4833c 100644 --- a/aya/src/programs/trace_point.rs +++ b/aya/src/programs/trace_point.rs @@ -69,7 +69,7 @@ impl TracePoint { /// `/sys/kernel/debug/tracing/events`. pub fn attach(&mut self, category: &str, name: &str) -> Result { let id = read_sys_fs_trace_point_id(category, name)?; - let fd = perf_event_open_trace_point(id).map_err(|(_code, io_error)| { + let fd = perf_event_open_trace_point(id, None).map_err(|(_code, io_error)| { ProgramError::SyscallError { call: "perf_event_open".to_owned(), io_error, diff --git a/aya/src/sys/perf_event.rs b/aya/src/sys/perf_event.rs index 7f065036..346fea2b 100644 --- a/aya/src/sys/perf_event.rs +++ b/aya/src/sys/perf_event.rs @@ -93,17 +93,20 @@ pub(crate) fn perf_event_open_probe( }) } -pub(crate) fn perf_event_open_trace_point(id: u32) -> SysResult { +pub(crate) fn perf_event_open_trace_point(id: u32, pid: Option) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; attr.size = mem::size_of::() as u32; attr.type_ = PERF_TYPE_TRACEPOINT as u32; attr.config = id as u64; + let cpu = if pid.is_some() { -1 } else { 0 }; + let pid = pid.unwrap_or(-1); + syscall(Syscall::PerfEventOpen { attr, - pid: -1, - cpu: 0, + pid, + cpu, group: -1, flags: PERF_FLAG_FD_CLOEXEC, })