From 0e28ac5b1698f02947626b544423ef056a8aedaf Mon Sep 17 00:00:00 2001 From: Chengdong Li Date: Tue, 19 Mar 2024 15:42:35 +0800 Subject: [PATCH] set `disabled` attribute to be 0 if an event has a group leader. --- src/perf_event/counting/group/inner.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/perf_event/counting/group/inner.rs b/src/perf_event/counting/group/inner.rs index b5cff3e..06c4bd0 100644 --- a/src/perf_event/counting/group/inner.rs +++ b/src/perf_event/counting/group/inner.rs @@ -43,9 +43,17 @@ impl Inner { &mut self, pid: pid_t, cpu: i32, - perf_event_attr: &PerfEventAttr, + perf_event_attr: &mut PerfEventAttr, ) -> io::Result { let group_fd = self.leader().map(|it| it.file.as_raw_fd()).unwrap_or(-1); + + // When creating an event group, typically the group leader is initialized with disabled set to 1 + // and any child events are initialized with disabled set to 0. + // Despite disabled being 0, the child events will not start until the group leader is enabled. + if group_fd != -1 { + perf_event_attr.set_disabled(0); + } + let fd = unsafe { perf_event_open_wrapped(perf_event_attr, pid, cpu, group_fd, 0) }?; let member = Counter { file: unsafe { File::from_raw_fd(fd) },