diff --git a/src/linux/mod.rs b/src/linux/mod.rs index 913a1c977..6ce307c97 100644 --- a/src/linux/mod.rs +++ b/src/linux/mod.rs @@ -15,5 +15,5 @@ pub use self::component::Component; pub use self::disk::{Disk, DiskType}; pub use self::network::NetworkData; pub use self::process::{Process, ProcessStatus}; -pub use self::processor::{get_avg_load, get_cpu_frequency, Processor}; +pub use self::processor::{get_avg_load, get_cpu_frequency, get_vendor_id, Processor}; pub use self::system::System; diff --git a/src/linux/processor.rs b/src/linux/processor.rs index 94d6e10c9..3fc0273d3 100644 --- a/src/linux/processor.rs +++ b/src/linux/processor.rs @@ -277,6 +277,19 @@ pub fn get_cpu_frequency() -> u64 { .unwrap_or_default() } +/// Returns the brand/vendor string for the first CPU (which should be the same for all CPUs). +pub fn get_vendor_id() -> String { + let mut s = String::new(); + if let Err(_) = File::open("/proc/cpuinfo").and_then(|mut f| f.read_to_string(&mut s)) { + return String::new(); + } + + s.split('\n').find(|line| line.starts_with("vendor_id\t")) + .and_then(|line| line.split(':').last()) + .map(|s| s.trim().to_owned()) + .unwrap_or_default() +} + /// get_avg_load returns the system load average value. pub fn get_avg_load() -> LoadAvg { let mut s = String::new(); diff --git a/src/mac/mod.rs b/src/mac/mod.rs index 4cccbc57b..7bc9da3d0 100644 --- a/src/mac/mod.rs +++ b/src/mac/mod.rs @@ -16,5 +16,5 @@ pub use self::component::Component; pub use self::disk::{Disk, DiskType}; pub use self::network::NetworkData; pub use self::process::{Process, ProcessStatus}; -pub use self::processor::{get_avg_load, get_cpu_frequency, Processor}; +pub use self::processor::{get_avg_load, get_cpu_frequency, get_vendor_id, Processor}; pub use self::system::System; diff --git a/src/mac/processor.rs b/src/mac/processor.rs index 5ff7e2fc6..62db4fb29 100644 --- a/src/mac/processor.rs +++ b/src/mac/processor.rs @@ -116,6 +116,12 @@ pub fn get_cpu_frequency() -> u64 { speed } +/// Returns the brand/vendor string for the first CPU (which should be the same for all CPUs). +pub fn get_vendor_id() -> String { + // TODO: support Mac + "".to_owned() +} + /// get_avg_load returns the system load average value. pub fn get_avg_load() -> LoadAvg { let loads = vec![0f64; 3]; diff --git a/src/sysinfo.rs b/src/sysinfo.rs index 19744bde3..da4b2dfcd 100644 --- a/src/sysinfo.rs +++ b/src/sysinfo.rs @@ -89,7 +89,7 @@ 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, + get_avg_load, get_cpu_frequency, get_vendor_id, Component, Disk, DiskType, NetworkData, Process, ProcessStatus, Processor, System, }; pub use traits::{ComponentExt, DiskExt, NetworkExt, ProcessExt, ProcessorExt, SystemExt}; @@ -264,7 +264,7 @@ pub fn get_sysctl_list() -> HashMap { #[cfg(test)] mod test { - use traits::{ProcessExt, SystemExt}; + use super::*; #[test] fn check_memory_usage() { @@ -307,6 +307,11 @@ mod test { #[test] fn test_cache_size() { + eprintln!("{}", get_vendor_id()); + if get_vendor_id() == "AuthenticAMD" { + return; + } + let caches = vec![ ("l1-cache-size", ::cache_size::l1_cache_size()), ("l1-cache-line-size", ::cache_size::l1_cache_line_size()), diff --git a/src/unknown/mod.rs b/src/unknown/mod.rs index 913a1c977..6ce307c97 100644 --- a/src/unknown/mod.rs +++ b/src/unknown/mod.rs @@ -15,5 +15,5 @@ pub use self::component::Component; pub use self::disk::{Disk, DiskType}; pub use self::network::NetworkData; pub use self::process::{Process, ProcessStatus}; -pub use self::processor::{get_avg_load, get_cpu_frequency, Processor}; +pub use self::processor::{get_avg_load, get_cpu_frequency, get_vendor_id, Processor}; pub use self::system::System; diff --git a/src/unknown/processor.rs b/src/unknown/processor.rs index cfe09dfd8..7c719064f 100644 --- a/src/unknown/processor.rs +++ b/src/unknown/processor.rs @@ -26,6 +26,11 @@ pub fn get_cpu_frequency() -> u64 { 0 } +/// Returns the brand/vendor string for the first CPU (which should be the same for all CPUs). +pub fn get_vendor_id() -> String { + "".to_owned() +} + /// get_avg_load returns the system load average value. pub fn get_avg_load() -> LoadAvg { LoadAvg::default() diff --git a/src/windows/mod.rs b/src/windows/mod.rs index 1191e49c4..f6bbda86f 100644 --- a/src/windows/mod.rs +++ b/src/windows/mod.rs @@ -34,5 +34,5 @@ pub use self::component::Component; pub use self::disk::{Disk, DiskType}; pub use self::network::NetworkData; pub use self::process::{Process, ProcessStatus}; -pub use self::processor::{get_avg_load, get_cpu_frequency, Processor}; +pub use self::processor::{get_avg_load, get_cpu_frequency, get_vendor_id, Processor}; pub use self::system::System; diff --git a/src/windows/processor.rs b/src/windows/processor.rs index 5b99f23eb..5e79aa70f 100644 --- a/src/windows/processor.rs +++ b/src/windows/processor.rs @@ -294,6 +294,12 @@ pub fn get_cpu_frequency() -> u64 { 0 } +/// Returns the brand/vendor string for the first CPU (which should be the same for all CPUs). +pub fn get_vendor_id() -> String { + // TODO: support windows + "".to_owned() +} + /// get_avg_load returns the system load average value. pub fn get_avg_load() -> LoadAvg { LoadAvg::default()