Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement load_average, CPU's frequency and vendor_id #245

Merged
merged 58 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
7300479
add functions get_cpu_frequency/get_avg_load
lonng Dec 3, 2019
b33d66e
support retrieve network statistics
lonng Dec 3, 2019
776ff78
support retrieve block device IO statistics
lonng Dec 3, 2019
1f52533
support retrieve system wide configuration list
lonng Dec 3, 2019
97922cb
wrap num_cpus/pnet_datalink/cache_size crates
lonng Dec 4, 2019
b57d44d
Fix io issue with modern Linux versions
Jan 22, 2020
1473e52
Add get_vendor_id function
Jan 22, 2020
159022d
Clean up linux new methods
GuillaumeGomez Jan 26, 2020
751c348
Clean up mac interface
GuillaumeGomez Jan 26, 2020
347ca38
Clean up weird mac API
GuillaumeGomez Jan 26, 2020
029d071
Add new methods for windows
GuillaumeGomez Jan 26, 2020
2101ee4
Implement API for unknown as well
GuillaumeGomez Jan 26, 2020
7512696
rename load_avg method
GuillaumeGomez Jan 26, 2020
564ab54
Add new methods into examples as well
GuillaumeGomez Jan 26, 2020
4e04017
Handle CTRL+D in example
GuillaumeGomez Jan 26, 2020
338e3ed
windows
GuillaumeGomez Jan 26, 2020
d05a3a4
Remove unneeded dependencies and unused functions
GuillaumeGomez Jan 26, 2020
e70594d
remove windows warnings
GuillaumeGomez Jan 26, 2020
f8d766a
Add code examples
GuillaumeGomez Jan 26, 2020
a3bf93f
Clean up simple.rs
GuillaumeGomez Jan 28, 2020
13b9154
Add frequency and vendor id on windows
GuillaumeGomez Jan 28, 2020
40c6c8a
Add get_brand method for processor
GuillaumeGomez Jan 28, 2020
68d64df
Add brand for linux
GuillaumeGomez Jan 28, 2020
7bd812a
Add brand for mac
GuillaumeGomez Jan 28, 2020
4682a42
Add brand for windows
GuillaumeGomez Jan 28, 2020
34fea68
fmt
GuillaumeGomez Jan 28, 2020
d7b4a35
Add brand command and rename proc to procs
GuillaumeGomez Jan 28, 2020
f53b7bc
Add get_brand for unknown
GuillaumeGomez Jan 28, 2020
983c87b
remove too general io and net files
GuillaumeGomez Jan 29, 2020
b1277ba
Rework network interface
GuillaumeGomez Jan 29, 2020
ab059a7
Update to new Networks type
GuillaumeGomez Jan 30, 2020
383f944
speed up networks refresh
GuillaumeGomez Jan 30, 2020
3a74384
Implement new Networks system on mac
GuillaumeGomez Jan 31, 2020
23256e8
Improve network example
GuillaumeGomez Jan 31, 2020
2ab3bf4
replace .insert by .insert_with
GuillaumeGomez Jan 31, 2020
42067a7
Fix doc
GuillaumeGomez Jan 31, 2020
bebc32b
Update c_interface
GuillaumeGomez Jan 31, 2020
7965eda
fix C example
GuillaumeGomez Jan 31, 2020
0277a0a
Start network refactoring on windows
GuillaumeGomez Feb 2, 2020
2333ca7
Greatly rework network API
GuillaumeGomez Feb 2, 2020
4da4d6e
Fix windows network part and remove software interfaces
GuillaumeGomez Feb 3, 2020
1dabf92
Improve network display in example
GuillaumeGomez Feb 3, 2020
b16d9c9
Add load average support for windows
GuillaumeGomez Feb 4, 2020
1691e9f
Remove duplicate calls on refresh
GuillaumeGomez Feb 4, 2020
b3f6c3c
Add networks_list entry for RefreshKind
GuillaumeGomez Feb 4, 2020
088bf1d
renaming for some methods
GuillaumeGomez Feb 4, 2020
d4d47f1
Update docs and benchmarks
GuillaumeGomez Feb 4, 2020
73dbc0e
Update benchmarks results for windows
GuillaumeGomez Feb 4, 2020
bb7388f
Fix mac errors
GuillaumeGomez Feb 4, 2020
ceae8b3
Update benchmark results for macos
GuillaumeGomez Feb 4, 2020
0a639fd
Add missing parts for unknown targets
GuillaumeGomez Feb 4, 2020
1021355
small cleanup
GuillaumeGomez Feb 4, 2020
1cc6b88
Implement IntoIterator on Networks
GuillaumeGomez Feb 4, 2020
a9e2eb9
Improve doc examples with removal of .iter() call
GuillaumeGomez Feb 4, 2020
9c6e411
Update linux benchmarks results
GuillaumeGomez Feb 4, 2020
f91999f
Don't read network compressed packets on linux for the moment
GuillaumeGomez Feb 4, 2020
83f86a7
Update linux benchmarks
GuillaumeGomez Feb 4, 2020
cd68da3
Update C interface
GuillaumeGomez Feb 5, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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