Struct machine_info::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
sourceimpl Machine
impl Machine
sourcepub fn new() -> Machine
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();
sourcepub fn system_info(&mut self) -> SystemInfo
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())
sourcepub fn graphics_status(&self) -> Vec<GraphicsUsage>
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())
sourcepub fn track_process(&mut self, pid: i32) -> Result<()>
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)
sourcepub fn untrack_process(&mut self, pid: i32)
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)
sourcepub fn processes_status(&mut self) -> Vec<Process>
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));
}
sourcepub fn system_status(&mut self) -> Result<SystemStatus>
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));
}