Skip to content

Commit

Permalink
Merge pull request #245 from GuillaumeGomez/nrc-vendor-up
Browse files Browse the repository at this point in the history
Implement load_average, CPU's frequency and vendor_id
  • Loading branch information
GuillaumeGomez authored Feb 5, 2020
2 parents 4ae1791 + cd68da3 commit aadbd04
Show file tree
Hide file tree
Showing 31 changed files with 2,458 additions and 1,084 deletions.
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ build = "build.rs"
cfg-if = "0.1"
rayon = "^1.0"
doc-comment = "0.3"
once_cell = "1.0"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["fileapi", "handleapi", "ioapiset", "minwindef", "pdh", "psapi", "synchapi", "sysinfoapi", "winbase", "winerror", "winioctl", "winnt", "oleauto", "wbemcli", "rpcdce", "combaseapi", "objidl", "objbase"] }
winapi = { version = "0.3", features = ["fileapi", "handleapi", "ifdef", "ioapiset", "minwindef", "pdh", "psapi", "synchapi", "sysinfoapi", "winbase", "winerror", "winioctl", "winnt", "oleauto", "wbemcli", "rpcdce", "combaseapi", "objidl", "objbase", "powerbase", "netioapi"] }
ntapi = "0.3"

[target.'cfg(not(any(target_os = "unknown", target_arch = "wasm32")))'.dependencies]
libc = "0.2"

[target.'cfg(unix)'.dependencies]
once_cell = "1.0"

[lib]
name = "sysinfo"
crate_type = ["rlib", "cdylib"]
Expand Down
76 changes: 41 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Support the following platforms:
* Linux
* Raspberry
* Android
* Mac OSX
* macOS
* Windows

It also compiles for Android but never been tested on it.
Expand Down Expand Up @@ -94,17 +94,19 @@ Here are the current results:
<details>

```text
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)
test bench_new ... bench: 375,774 ns/iter (+/- 7,119)
test bench_new_all ... bench: 10,308,642 ns/iter (+/- 422,803)
test bench_refresh_all ... bench: 2,824,911 ns/iter (+/- 169,153)
test bench_refresh_cpu ... bench: 13,630 ns/iter (+/- 702)
test bench_refresh_disks ... bench: 2,558 ns/iter (+/- 14)
test bench_refresh_disks_lists ... bench: 51,737 ns/iter (+/- 5,712)
test bench_refresh_memory ... bench: 12,006 ns/iter (+/- 277)
test bench_refresh_networks ... bench: 223,858 ns/iter (+/- 28,537)
test bench_refresh_networks_list ... bench: 232,934 ns/iter (+/- 34,344)
test bench_refresh_process ... bench: 78,925 ns/iter (+/- 12,421)
test bench_refresh_processes ... bench: 2,235,119 ns/iter (+/- 137,403)
test bench_refresh_system ... bench: 52,832 ns/iter (+/- 6,704)
test bench_refresh_temperatures ... bench: 25,079 ns/iter (+/- 2,258)
```
</details>

Expand All @@ -113,36 +115,40 @@ test bench_refresh_temperatures ... bench: 25,770 ns/iter (+/- 1,164)
<details>

```text
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)
test bench_new ... bench: 14,738,570 ns/iter (+/- 586,107)
test bench_new_all ... bench: 27,132,490 ns/iter (+/- 1,292,307)
test bench_refresh_all ... bench: 3,075,022 ns/iter (+/- 110,711)
test bench_refresh_cpu ... bench: 392 ns/iter (+/- 30)
test bench_refresh_disks ... bench: 41,778 ns/iter (+/- 954)
test bench_refresh_disks_lists ... bench: 113,942 ns/iter (+/- 4,240)
test bench_refresh_memory ... bench: 578 ns/iter (+/- 41)
test bench_refresh_networks ... bench: 38,178 ns/iter (+/- 3,718)
test bench_refresh_networks_list ... bench: 668,390 ns/iter (+/- 30,642)
test bench_refresh_process ... bench: 745 ns/iter (+/- 62)
test bench_refresh_processes ... bench: 1,179,581 ns/iter (+/- 188,119)
test bench_refresh_system ... bench: 1,230,542 ns/iter (+/- 64,231)
test bench_refresh_temperatures ... bench: 1,231,260 ns/iter (+/- 111,274)
```
</details>

**OSX**
**macOS**

<details>

```text
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)
test bench_new ... bench: 54,862 ns/iter (+/- 6,528)
test bench_new_all ... bench: 4,989,120 ns/iter (+/- 1,001,529)
test bench_refresh_all ... bench: 1,924,596 ns/iter (+/- 341,209)
test bench_refresh_cpu ... bench: 10,521 ns/iter (+/- 1,623)
test bench_refresh_disks ... bench: 945 ns/iter (+/- 95)
test bench_refresh_disks_lists ... bench: 29,315 ns/iter (+/- 3,076)
test bench_refresh_memory ... bench: 3,275 ns/iter (+/- 143)
test bench_refresh_networks ... bench: 200,670 ns/iter (+/- 28,674)
test bench_refresh_networks_list ... bench: 200,263 ns/iter (+/- 31,473)
test bench_refresh_process ... bench: 4,009 ns/iter (+/- 584)
test bench_refresh_processes ... bench: 790,834 ns/iter (+/- 61,236)
test bench_refresh_system ... bench: 335,144 ns/iter (+/- 35,713)
test bench_refresh_temperatures ... bench: 298,823 ns/iter (+/- 77,589)
```
</details>

Expand Down
37 changes: 28 additions & 9 deletions benches/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extern crate sysinfo;
extern crate test;

use sysinfo::SystemExt;
use sysinfo::get_current_pid;

#[bench]
fn bench_new(b: &mut test::Bencher) {
Expand All @@ -12,9 +13,16 @@ fn bench_new(b: &mut test::Bencher) {
});
}

#[bench]
fn bench_new_all(b: &mut test::Bencher) {
b.iter(|| {
sysinfo::System::new_all();
});
}

#[bench]
fn bench_refresh_all(b: &mut test::Bencher) {
let mut s = sysinfo::System::new();
let mut s = sysinfo::System::new_all();

b.iter(move || {
s.refresh_all();
Expand All @@ -23,7 +31,7 @@ fn bench_refresh_all(b: &mut test::Bencher) {

#[bench]
fn bench_refresh_system(b: &mut test::Bencher) {
let mut s = sysinfo::System::new();
let mut s = sysinfo::System::new_all();

s.refresh_system();
b.iter(move || {
Expand All @@ -35,6 +43,7 @@ fn bench_refresh_system(b: &mut test::Bencher) {
fn bench_refresh_processes(b: &mut test::Bencher) {
let mut s = sysinfo::System::new();

s.refresh_processes(); // to load the whole processes list a first time.
b.iter(move || {
s.refresh_processes();
});
Expand All @@ -45,36 +54,46 @@ fn bench_refresh_process(b: &mut test::Bencher) {
let mut s = sysinfo::System::new();

s.refresh_all();
let pid = *s.get_process_list().iter().take(1).next().unwrap().0;
// to be sure it'll exist for at least as long as we run
let pid = get_current_pid().expect("failed to get current pid");
b.iter(move || {
s.refresh_process(pid);
});
}

#[bench]
fn bench_refresh_disks(b: &mut test::Bencher) {
let mut s = sysinfo::System::new();
let mut s = sysinfo::System::new_all();

b.iter(move || {
s.refresh_disks();
});
}

#[bench]
fn bench_refresh_disk_lists(b: &mut test::Bencher) {
fn bench_refresh_disks_lists(b: &mut test::Bencher) {
let mut s = sysinfo::System::new();

b.iter(move || {
s.refresh_disk_list();
s.refresh_disks_list();
});
}

#[bench]
fn bench_refresh_network(b: &mut test::Bencher) {
fn bench_refresh_networks(b: &mut test::Bencher) {
let mut s = sysinfo::System::new_all();

b.iter(move || {
s.refresh_networks();
});
}

#[bench]
fn bench_refresh_networks_list(b: &mut test::Bencher) {
let mut s = sysinfo::System::new();

b.iter(move || {
s.refresh_network();
s.refresh_networks_list();
});
}

Expand All @@ -98,7 +117,7 @@ fn bench_refresh_cpu(b: &mut test::Bencher) {

#[bench]
fn bench_refresh_temperatures(b: &mut test::Bencher) {
let mut s = sysinfo::System::new();
let mut s = sysinfo::System::new_all();

b.iter(move || {
s.refresh_temperatures();
Expand Down
18 changes: 9 additions & 9 deletions examples/src/simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ bool process_loop(pid_t pid, CProcess process, void *data) {
int main() {
CSystem system = sysinfo_init();
sysinfo_refresh_all(system);
printf("total memory: %ld\n", sysinfo_get_total_memory(system));
printf("free memory: %ld\n", sysinfo_get_free_memory(system));
printf("used memory: %ld\n", sysinfo_get_used_memory(system));
printf("total swap: %ld\n", sysinfo_get_total_swap(system));
printf("free swap: %ld\n", sysinfo_get_free_swap(system));
printf("used swap: %ld\n", sysinfo_get_used_swap(system));
printf("network income: %ld\n", sysinfo_get_network_income(system));
printf("network outcome: %ld\n", sysinfo_get_network_outcome(system));
printf("total memory: %ld\n", sysinfo_get_total_memory(system));
printf("free memory: %ld\n", sysinfo_get_free_memory(system));
printf("used memory: %ld\n", sysinfo_get_used_memory(system));
printf("total swap: %ld\n", sysinfo_get_total_swap(system));
printf("free swap: %ld\n", sysinfo_get_free_swap(system));
printf("used swap: %ld\n", sysinfo_get_used_swap(system));
printf("networks income: %ld\n", sysinfo_get_networks_income(system));
printf("networks outcome: %ld\n", sysinfo_get_networks_outcome(system));
unsigned int len = 0, i = 0;
float *procs = NULL;
sysinfo_get_processors_usage(system, &len, &procs);
while (i < len) {
printf("Processor #%d usage: %f\n", i, procs[i]);
printf("Processor #%d usage: %f%%\n", i, procs[i]);
i += 1;
}
free(procs);
Expand Down
Loading

0 comments on commit aadbd04

Please sign in to comment.