Struct nu_system::ProcessInfo

source ·
pub struct ProcessInfo {
Show 15 fields pub pid: i32, pub command: String, pub ppid: i32, pub start_time: DateTime<Local>, pub cpu_info: CpuInfo, pub memory_info: MemoryInfo, pub disk_info: DiskInfo, pub user: SidName, pub groups: Vec<SidName>, pub priority: u32, pub thread: i32, pub interval: Duration, pub cmd: Vec<String>, pub environ: Vec<String>, pub cwd: PathBuf,
}

Fields§

§pid: i32§command: String§ppid: i32§start_time: DateTime<Local>§cpu_info: CpuInfo§memory_info: MemoryInfo§disk_info: DiskInfo§user: SidName§groups: Vec<SidName>§priority: u32§thread: i32§interval: Duration§cmd: Vec<String>§environ: Vec<String>§cwd: PathBuf

Implementations§

source§

impl ProcessInfo

source

pub fn pid(&self) -> i32

PID of process

Examples found in repository?
examples/sys_demo.rs (line 18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() {
    #[cfg(any(
        target_os = "android",
        target_os = "linux",
        target_os = "macos",
        target_os = "windows"
    ))]
    {
        let cores = std::thread::available_parallelism()
            .map(|p| p.get())
            .unwrap_or(1);
        for run in 1..=10 {
            for proc in nu_system::collect_proc(std::time::Duration::from_millis(100), false) {
                if proc.cpu_usage() > 0.00001 {
                    println!(
                        "{} - {} - {} - {} - {:.2}% - {}M - {}M - {} procs",
                        run,
                        proc.pid(),
                        proc.name(),
                        proc.status(),
                        proc.cpu_usage() / cores as f64,
                        proc.mem_size() / (1024 * 1024),
                        proc.virtual_size() / (1024 * 1024),
                        cores,
                    )
                }
            }
            std::thread::sleep(std::time::Duration::from_millis(1000));
        }
    }
}
source

pub fn ppid(&self) -> i32

Parent PID of process

source

pub fn name(&self) -> String

Name of command

Examples found in repository?
examples/sys_demo.rs (line 19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() {
    #[cfg(any(
        target_os = "android",
        target_os = "linux",
        target_os = "macos",
        target_os = "windows"
    ))]
    {
        let cores = std::thread::available_parallelism()
            .map(|p| p.get())
            .unwrap_or(1);
        for run in 1..=10 {
            for proc in nu_system::collect_proc(std::time::Duration::from_millis(100), false) {
                if proc.cpu_usage() > 0.00001 {
                    println!(
                        "{} - {} - {} - {} - {:.2}% - {}M - {}M - {} procs",
                        run,
                        proc.pid(),
                        proc.name(),
                        proc.status(),
                        proc.cpu_usage() / cores as f64,
                        proc.mem_size() / (1024 * 1024),
                        proc.virtual_size() / (1024 * 1024),
                        cores,
                    )
                }
            }
            std::thread::sleep(std::time::Duration::from_millis(1000));
        }
    }
}
source

pub fn command(&self) -> String

Full name of command, with arguments

source

pub fn environ(&self) -> Vec<String>

source

pub fn cwd(&self) -> String

source

pub fn status(&self) -> String

Get the status of the process

Examples found in repository?
examples/sys_demo.rs (line 20)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() {
    #[cfg(any(
        target_os = "android",
        target_os = "linux",
        target_os = "macos",
        target_os = "windows"
    ))]
    {
        let cores = std::thread::available_parallelism()
            .map(|p| p.get())
            .unwrap_or(1);
        for run in 1..=10 {
            for proc in nu_system::collect_proc(std::time::Duration::from_millis(100), false) {
                if proc.cpu_usage() > 0.00001 {
                    println!(
                        "{} - {} - {} - {} - {:.2}% - {}M - {}M - {} procs",
                        run,
                        proc.pid(),
                        proc.name(),
                        proc.status(),
                        proc.cpu_usage() / cores as f64,
                        proc.mem_size() / (1024 * 1024),
                        proc.virtual_size() / (1024 * 1024),
                        cores,
                    )
                }
            }
            std::thread::sleep(std::time::Duration::from_millis(1000));
        }
    }
}
source

pub fn cpu_usage(&self) -> f64

CPU usage as a percent of total

Examples found in repository?
examples/sys_demo.rs (line 14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() {
    #[cfg(any(
        target_os = "android",
        target_os = "linux",
        target_os = "macos",
        target_os = "windows"
    ))]
    {
        let cores = std::thread::available_parallelism()
            .map(|p| p.get())
            .unwrap_or(1);
        for run in 1..=10 {
            for proc in nu_system::collect_proc(std::time::Duration::from_millis(100), false) {
                if proc.cpu_usage() > 0.00001 {
                    println!(
                        "{} - {} - {} - {} - {:.2}% - {}M - {}M - {} procs",
                        run,
                        proc.pid(),
                        proc.name(),
                        proc.status(),
                        proc.cpu_usage() / cores as f64,
                        proc.mem_size() / (1024 * 1024),
                        proc.virtual_size() / (1024 * 1024),
                        cores,
                    )
                }
            }
            std::thread::sleep(std::time::Duration::from_millis(1000));
        }
    }
}
source

pub fn mem_size(&self) -> u64

Memory size in number of bytes

Examples found in repository?
examples/sys_demo.rs (line 22)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() {
    #[cfg(any(
        target_os = "android",
        target_os = "linux",
        target_os = "macos",
        target_os = "windows"
    ))]
    {
        let cores = std::thread::available_parallelism()
            .map(|p| p.get())
            .unwrap_or(1);
        for run in 1..=10 {
            for proc in nu_system::collect_proc(std::time::Duration::from_millis(100), false) {
                if proc.cpu_usage() > 0.00001 {
                    println!(
                        "{} - {} - {} - {} - {:.2}% - {}M - {}M - {} procs",
                        run,
                        proc.pid(),
                        proc.name(),
                        proc.status(),
                        proc.cpu_usage() / cores as f64,
                        proc.mem_size() / (1024 * 1024),
                        proc.virtual_size() / (1024 * 1024),
                        cores,
                    )
                }
            }
            std::thread::sleep(std::time::Duration::from_millis(1000));
        }
    }
}
source

pub fn virtual_size(&self) -> u64

Virtual memory size in bytes

Examples found in repository?
examples/sys_demo.rs (line 23)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() {
    #[cfg(any(
        target_os = "android",
        target_os = "linux",
        target_os = "macos",
        target_os = "windows"
    ))]
    {
        let cores = std::thread::available_parallelism()
            .map(|p| p.get())
            .unwrap_or(1);
        for run in 1..=10 {
            for proc in nu_system::collect_proc(std::time::Duration::from_millis(100), false) {
                if proc.cpu_usage() > 0.00001 {
                    println!(
                        "{} - {} - {} - {} - {:.2}% - {}M - {}M - {} procs",
                        run,
                        proc.pid(),
                        proc.name(),
                        proc.status(),
                        proc.cpu_usage() / cores as f64,
                        proc.mem_size() / (1024 * 1024),
                        proc.virtual_size() / (1024 * 1024),
                        cores,
                    )
                }
            }
            std::thread::sleep(std::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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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>,

§

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.