From 776dee32aca73ded5c0720afbe25ef2aae7b67f3 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Mon, 10 Mar 2025 21:36:30 +0100 Subject: Implement benchmarking --- perf-event/src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'perf-event/src') diff --git a/perf-event/src/lib.rs b/perf-event/src/lib.rs index 03ef643..d1478fe 100644 --- a/perf-event/src/lib.rs +++ b/perf-event/src/lib.rs @@ -453,6 +453,8 @@ impl<'a> Default for Builder<'a> { attrs.set_disabled(1); attrs.set_exclude_kernel(1); // don't count time in kernel attrs.set_exclude_hv(1); // don't count time in hypervisor + attrs.set_exclude_kernel(0); // don't count time in kernel + attrs.set_exclude_hv(0); // don't count time in hypervisor // Request data for `time_enabled` and `time_running`. attrs.read_format |= sys::bindings::PERF_FORMAT_TOTAL_TIME_ENABLED as u64 @@ -760,6 +762,11 @@ impl Group { /// Construct a new, empty `Group`. #[allow(unused_parens)] pub fn new() -> io::Result { + Self::new_with_pid_and_cpu(0, -1) + } + + /// Construct a new, empty `Group` with cpu and pid set. + pub fn new_with_pid_and_cpu(pid: i32, cpu: i32) -> io::Result { // Open a placeholder perf counter that we can add other events to. let mut attrs = perf_event_attr { size: std::mem::size_of::() as u32, @@ -780,7 +787,7 @@ impl Group { let file = unsafe { File::from_raw_fd(check_errno_syscall(|| { - sys::perf_event_open(&mut attrs, 0, -1, -1, 0) + sys::perf_event_open(&mut attrs, pid, cpu, -1, 0) })?) }; -- cgit v1.3.1