Skip to content

Commit

Permalink
wrap num_cpus/pnet_datalink/cache_size crates
Browse files Browse the repository at this point in the history
Signed-off-by: Lonng <[email protected]>
  • Loading branch information
lonng committed Dec 4, 2019
1 parent 2bbec60 commit aa98faf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
30 changes: 29 additions & 1 deletion src/sysinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
//#![deny(warnings)]
#![allow(unknown_lints)]

extern crate num_cpus;

#[macro_use]
extern crate cfg_if;
#[cfg(not(target_os = "unknown"))]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<String, String> {
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit aa98faf

Please sign in to comment.