83 releases

new 0.10.5 Jan 17, 2020
0.10.3 Dec 16, 2019
0.9.6 Nov 7, 2019
0.9.1 Jul 26, 2019
0.0.2 Jul 25, 2015

#4 in Unix APIs

Download history 6180/week @ 2019-10-04 4282/week @ 2019-10-11 4094/week @ 2019-10-18 3452/week @ 2019-10-25 3482/week @ 2019-11-01 4676/week @ 2019-11-08 5598/week @ 2019-11-15 4736/week @ 2019-11-22 5739/week @ 2019-11-29 6544/week @ 2019-12-06 7822/week @ 2019-12-13 5373/week @ 2019-12-20 4688/week @ 2019-12-27 6214/week @ 2020-01-03 6254/week @ 2020-01-10

22,842 downloads per month
Used in 20 crates (15 directly)

MIT license

250KB
6.5K SLoC

sysinfo Build status

A system handler to interact with processes.

Support the following platforms:

  • Linux
  • Raspberry
  • Android
  • Mac OSX
  • Windows

It also compiles for Android but never been tested on it.

Running on Raspberry

It'll be difficult to build on Raspberry. A good way-around is to be build on Linux before sending it to your Raspberry:

rustup target add armv7-unknown-linux-gnueabihf
cargo build --target=armv7-unknown-linux-gnueabihf

Code example

You have an example into the examples folder. Just run cargo run inside the examples folder to start it. Otherwise, here is a little code sample:

use sysinfo::{NetworkExt, System, SystemExt};

let mut sys = System::new();

// We display the disks:
println!("=> disk list:");
for disk in sys.get_disks() {
    println!("{:?}", disk);
}

// Network data:
println!("input data : {} B", sys.get_network().get_income());
println!("output data: {} B", sys.get_network().get_outcome());

// Components temperature:
for component in sys.get_components_list() {
    println!("{:?}", component);
}

// Memory information:
println!("total memory: {} KiB", sys.get_total_memory());
println!("used memory : {} KiB", sys.get_used_memory());
println!("total swap  : {} KiB", sys.get_total_swap());
println!("used swap   : {} KiB", sys.get_used_swap());

// Number of processors
println!("NB processors: {}", sys.get_processor_list().len());

// To refresh all system information:
sys.refresh_all();

C interface

It's possible to use this crate directly from C. Take a look at the Makefile and at the examples/src/simple.c file.

To build the C example, just run:

> make
> ./simple
# If needed:
> LD_LIBRARY_PATH=target/release/ ./simple

Benchmarks

You can run the benchmarks locally with rust nightly by doing:

> cargo bench

Here are the current results:

Linux

test bench_new                  ... bench:  10,437,759 ns/iter (+/- 531,424)
test bench_refresh_all          ... bench:   2,658,946 ns/iter (+/- 189,612)
test bench_refresh_cpu          ... bench:      13,429 ns/iter (+/- 537)
test bench_refresh_disk_lists   ... bench:      50,688 ns/iter (+/- 8,032)
test bench_refresh_disks        ... bench:       2,582 ns/iter (+/- 226)
test bench_refresh_memory       ... bench:      12,015 ns/iter (+/- 537)
test bench_refresh_network      ... bench:      23,661 ns/iter (+/- 617)
test bench_refresh_process      ... bench:      56,157 ns/iter (+/- 2,445)
test bench_refresh_processes    ... bench:   2,486,534 ns/iter (+/- 121,187)
test bench_refresh_system       ... bench:      53,739 ns/iter (+/- 6,793)
test bench_refresh_temperatures ... bench:      25,770 ns/iter (+/- 1,164)

Windows

test bench_new                  ... bench:  61,548,071 ns/iter (+/- 196,093,742)
test bench_refresh_all          ... bench:   2,541,951 ns/iter (+/- 482,285)
test bench_refresh_cpu          ... bench:         460 ns/iter (+/- 478)
test bench_refresh_disk_lists   ... bench:     152,940 ns/iter (+/- 8,330)
test bench_refresh_disks        ... bench:      55,597 ns/iter (+/- 9,629)
test bench_refresh_memory       ... bench:       2,130 ns/iter (+/- 486)
test bench_refresh_network      ... bench:         212 ns/iter (+/- 216)
test bench_refresh_process      ... bench:          38 ns/iter (+/- 33)
test bench_refresh_processes    ... bench:   2,175,034 ns/iter (+/- 315,585)
test bench_refresh_system       ... bench:       2,508 ns/iter (+/- 224)
test bench_refresh_temperatures ... bench:           1 ns/iter (+/- 0)

OSX

test bench_new                  ... bench:   4,713,851 ns/iter (+/- 1,080,986)
test bench_refresh_all          ... bench:   1,639,098 ns/iter (+/- 191,147)
test bench_refresh_cpu          ... bench:      10,651 ns/iter (+/- 1,635)
test bench_refresh_disk_lists   ... bench:      29,327 ns/iter (+/- 3,104)
test bench_refresh_disks        ... bench:         942 ns/iter (+/- 79)
test bench_refresh_memory       ... bench:       3,417 ns/iter (+/- 654)
test bench_refresh_network      ... bench:      34,497 ns/iter (+/- 2,681)
test bench_refresh_process      ... bench:       4,272 ns/iter (+/- 549)
test bench_refresh_processes    ... bench:     782,977 ns/iter (+/- 30,958)
test bench_refresh_system       ... bench:     336,008 ns/iter (+/- 43,015)
test bench_refresh_temperatures ... bench:     294,323 ns/iter (+/- 41,612)

Donations

If you appreciate my work and want to support me, you can do it here:

Become a patron

Dependencies

~1.5MB
~29K SLoC