Struct Machine

Source
pub struct Machine { /* private fields */ }
Expand description

Represents a machine. Currently you can monitor global CPU/Memory usage, processes CPU usage and the Nvidia GPU usage. You can also retrieve information about CPU, disks…

Implementations§

Source§

impl Machine

Source

pub fn new() -> Machine

Creates a new instance of Machine. If not graphic card it will warn about it but not an error Example

use machine_info::Machine;
let m = Machine::new();
Source

pub fn system_info(&mut self) -> SystemInfo

Retrieves full information about the computer Example

use machine_info::Machine;
let m = Machine::new();
println!("{:?}", m.system_info())
Source

pub fn graphics_status(&self) -> Vec<GraphicsUsage>

The current usage of all graphic cards (if any) Example

use machine_info::Machine;
let m = Machine::new();
println!("{:?}", m.graphics_status())
Source

pub fn track_process(&mut self, pid: i32) -> Result<()>

To calculate the CPU usage of a process we have to keep track in time the process so first we have to register the process. You need to know the PID of your process and use it as parameters. In case you provide an invalid PID it will return error Example

use machine_info::Machine;
let m = Machine::new();
let process_pid = 3218;
m.track_process(process_pid)
Source

pub fn untrack_process(&mut self, pid: i32)

Once we dont need to track a process it is recommended to not keep using resources on it. You should know the PID of your process. If the PID was not registered before, it will just do nothing Example

use machine_info::Machine;
let m = Machine::new();
let process_pid = 3218;
m.track_process(process_pid)
m.untrack_process(process_pid)
Source

pub fn processes_status(&mut self) -> Vec<Process>

The CPU usage of all tracked processes since the last call. So if you call it every 10 seconds, you will get the CPU usage during the last 10 seconds. More calls will make the value more accurate but also more expensive Example

use machine_info::Machine;
use std::{thread, time};
 
let m = Machine::new();
m.track_process(3218)
m.track_process(4467)
loop {   
  let status = m.processes_status();
  println!("{:?}", status);
  thread::sleep(time::Duration::from_millis(1000));
}
 
Source

pub fn system_status(&mut self) -> Result<SystemStatus>

The CPU and memory usage. For the CPU, it is the same as for processes_status. For the memory it returs the amount a this moment Example

use machine_info::Machine;
use std::{thread, time};
 
let m = Machine::new();
m.track_process(3218)
m.track_process(4467)
loop {   
  let status = m.system_status();
  println!("{:?}", status);
  thread::sleep(time::Duration::from_millis(1000));
}
 

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.