瀏覽代碼

Support pid filtering in debugfs

Dan Everton 3 年之前
父節點
當前提交
606c3267c4
共有 3 個文件被更改,包括 8 次插入6 次删除
  1. 1 2
      aya/src/programs/probe.rs
  2. 1 1
      aya/src/programs/trace_point.rs
  3. 6 3
      aya/src/sys/perf_event.rs

+ 1 - 2
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,

+ 1 - 1
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<LinkRef, ProgramError> {
         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,

+ 6 - 3
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<pid_t>) -> SysResult {
     let mut attr = unsafe { mem::zeroed::<perf_event_attr>() };
 
     attr.size = mem::size_of::<perf_event_attr>() 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,
     })