From 2c160cdf79cf065484b9e8ef99c117b45fde778a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Sun, 3 Sep 2023 12:02:57 -0300 Subject: [PATCH] src: traits: Add governor function for CpuExt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- src/traits.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/traits.rs b/src/traits.rs index c41280df3..4e738dc66 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -5,8 +5,8 @@ use crate::{ sys::{Component, Cpu, Disk, Process}, }; use crate::{ - CpuRefreshKind, DiskKind, DiskUsage, Disks, Group, LoadAvg, Networks, NetworksIter, Pid, - ProcessRefreshKind, ProcessStatus, RefreshKind, Signal, User, + CpuRefreshKind, DiskKind, DiskUsage, Disks, GovernorKind, Group, LoadAvg, Networks, + NetworksIter, Pid, ProcessRefreshKind, ProcessStatus, RefreshKind, Signal, User, }; use std::collections::HashMap; @@ -570,6 +570,20 @@ pub trait CpuExt: Debug { /// } /// ``` fn frequency(&self) -> u64; + + /// Returns the CPU's governor. + /// + /// ```no_run + /// use sysinfo::{CpuExt, GovernorKind, System, SystemExt, RefreshKind, CpuRefreshKind}; + /// + /// let s = System::new_with_specifics( + /// RefreshKind::new().with_cpu(CpuRefreshKind::everything()), + /// ); + /// for cpu in s.cpus() { + /// println!("{}", cpu.governor()); + /// } + /// ``` + fn governor(&self) -> GovernorKind; } /// Contains all the methods of the [`System`][crate::System] type. @@ -1069,6 +1083,18 @@ pub trait SystemExt: Sized + Debug + Default + Send + Sync { /// ``` fn global_cpu_info(&self) -> &Cpu; + /// Returns the CPUs governor being used. + /// + /// ```no_run + /// use sysinfo::{CpuRefreshKind, CpuExt, RefreshKind, System, SystemExt}; + /// + /// let s = System::new_with_specifics( + /// RefreshKind::new().with_cpu(CpuRefreshKind::everything()), + /// ); + /// println!("{}%", s.global_cpu_info().cpu_usage()); + /// ``` + fn governor(&self) -> GovernorKind; + /// Returns the list of the CPUs. /// /// By default, the list of CPUs is empty until you call [`SystemExt::refresh_cpu`] or