From 62e5b43451c31b9edca4fa5c5df8dd9e441c0949 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Wed, 16 Apr 2025 12:37:18 +0200 Subject: Inherit energy counters --- perf-event/src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'perf-event/src') diff --git a/perf-event/src/lib.rs b/perf-event/src/lib.rs index d1478fe..e09de18 100644 --- a/perf-event/src/lib.rs +++ b/perf-event/src/lib.rs @@ -533,6 +533,25 @@ impl<'a> Builder<'a> { self } + /// Set whether this counter is inherited by new threads. + /// + /// When this flag is set, this counter observes activity in new threads + /// created by any thread already being observed. + /// + /// By default, the flag is unset: counters are not inherited, and observe + /// only the threads specified when they are created. + /// + /// This flag cannot be set if the counter belongs to a `Group`. Doing so + /// will result in an error when the counter is built. This is a kernel + /// limitation. + pub fn inherit_thread(mut self, inherit: bool) -> Builder<'a> { + let flag = if inherit { 1 } else { 0 }; + self.attrs.set_inherit(flag); + self.attrs.set_inherit_stat(flag); + self.attrs.set_inherit_thread(flag); + self + } + /// Count events of the given kind. This accepts an [`Event`] value, /// or any type that can be converted to one, so you can pass [`Hardware`], /// [`Software`] and [`Cache`] values directly. -- cgit v1.3.1