From aa98faff1c586984857506c8add248ee304a7f81 Mon Sep 17 00:00:00 2001 From: Lonng Date: Wed, 4 Dec 2019 16:44:50 +0800 Subject: [PATCH] wrap num_cpus/pnet_datalink/cache_size crates Signed-off-by: Lonng --- Cargo.toml | 3 +++ src/sysinfo.rs | 30 +++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5b2af281e..1fda7e9bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,9 @@ cfg-if = "0.1" rayon = "^1.0" doc-comment = "0.3" walkdir = "2.2.9" +pnet_datalink = "0.23.0" +num_cpus = "1.11.1" +cache-size = "0.4.0" [target.'cfg(windows)'.dependencies] winapi = { version = "0.3", features = ["fileapi", "handleapi", "ioapiset", "minwindef", "pdh", "psapi", "synchapi", "sysinfoapi", "tlhelp32", "winbase", "winerror", "winioctl", "winnt"] } diff --git a/src/sysinfo.rs b/src/sysinfo.rs index 73df7b7cb..b8e9629c1 100644 --- a/src/sysinfo.rs +++ b/src/sysinfo.rs @@ -48,6 +48,8 @@ //#![deny(warnings)] #![allow(unknown_lints)] +extern crate num_cpus; + #[macro_use] extern crate cfg_if; #[cfg(not(target_os = "unknown"))] @@ -77,9 +79,14 @@ cfg_if! { } } +pub extern crate cache_size; +pub extern crate pnet_datalink as datalink; + pub use common::{AsU32, Pid, RefreshKind}; pub use io::IOLoad; pub use net::NICLoad; +pub use num_cpus::{get as get_logical_cores, get_physical as get_physical_cores}; + pub use sys::{ get_avg_load, get_cpu_frequency, Component, Disk, DiskType, NetworkData, Process, ProcessStatus, Processor, System, @@ -190,7 +197,7 @@ pub struct LoadAvg { /// Returns system wide configuration /// -/// # Note +/// # Notes /// /// Current only can be used in operating system mounted `procfs` pub fn get_sysctl_list() -> HashMap { @@ -253,4 +260,25 @@ mod test { fn test_io_load() { println!("test test_io_load: {:?}", ::IOLoad::snapshot()); } + + #[test] + fn test_get_cores() { + assert_ne!(::get_logical_cores(), 0, "expect none-zero logical core"); + assert_ne!(::get_physical_cores(), 0, "expect none-zero physical core"); + } + + #[test] + fn test_cache_size() { + let caches = vec![ + ("l1-cache-size", ::cache_size::l1_cache_size()), + ("l1-cache-line-size", ::cache_size::l1_cache_line_size()), + ("l2-cache-size", ::cache_size::l2_cache_size()), + ("l2-cache-line-size", ::cache_size::l2_cache_line_size()), + ("l3-cache-size", ::cache_size::l3_cache_size()), + ("l3-cache-line-size", ::cache_size::l3_cache_line_size()), + ]; + for c in caches { + assert_ne!(c.1.unwrap(), 0, "{} expect non-zero", c.0) + } + } }