Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add governor information #1057

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
src: traits: Add governor function for CpuExt
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
patrickelectric committed Sep 3, 2023
commit 09e3fa6e255f350bcd49478ea8efb3d654dee2aa
30 changes: 28 additions & 2 deletions src/traits.rs
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should return an Option in case this information hasn't been retrieved yet.

}

/// 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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this from SystemExt, it should only be on CpuExt.


/// Returns the list of the CPUs.
///
/// By default, the list of CPUs is empty until you call [`SystemExt::refresh_cpu`] or