Skip to content

Commit

Permalink
src: traits: Add governor function for CpuExt
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric committed Sep 3, 2023
1 parent 430e029 commit 2c160cd
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2c160cd

Please sign in to comment.