Skip to content

Commit

Permalink
Remove unnecessary code
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Cameron <[email protected]>
  • Loading branch information
nrc committed Feb 15, 2020
1 parent eefc23a commit 2e70ddd
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ pub use self::component::Component;
pub use self::disk::Disk;
pub use self::network::{NetworkData, Networks};
pub use self::process::{Process, ProcessStatus};
pub use self::processor::{get_avg_load, get_cpu_frequency, Processor};
pub use self::processor::Processor;
pub use self::system::System;
21 changes: 0 additions & 21 deletions src/linux/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use std::fs::File;
use std::io::Read;

use LoadAvg;
use ProcessorExt;

/// Struct containing values to compute a CPU usage.
Expand Down Expand Up @@ -229,7 +228,6 @@ pub fn get_raw_times(p: &Processor) -> (u64, u64) {
(p.new_values.total_time(), p.old_values.total_time())
}

/// get_cpu_frequency returns the CPU frequency in MHz
pub fn get_cpu_frequency() -> u64 {
// /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
let mut s = String::new();
Expand Down Expand Up @@ -288,22 +286,3 @@ pub fn get_vendor_id_and_brand() -> (String, String) {
}
(vendor_id.unwrap_or_default(), brand.unwrap_or_default())
}

/// get_avg_load returns the system load average value.
pub fn get_avg_load() -> LoadAvg {
let mut s = String::new();
if let Err(_) = File::open("/proc/loadavg").and_then(|mut f| f.read_to_string(&mut s)) {
return LoadAvg::default();
}
let loads = s
.trim()
.split(' ')
.take(3)
.map(|val| val.parse::<f64>().unwrap())
.collect::<Vec<f64>>();
LoadAvg {
one: loads[0],
five: loads[1],
fifteen: loads[2],
}
}
2 changes: 1 addition & 1 deletion src/mac/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ pub use self::component::Component;
pub use self::disk::Disk;
pub use self::network::{NetworkData, Networks};
pub use self::process::{Process, ProcessStatus};
pub use self::processor::{get_avg_load, get_cpu_frequency, Processor};
pub use self::processor::Processor;
pub use self::system::System;
32 changes: 1 addition & 31 deletions src/mac/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl ProcessorExt for Processor {
}
}

pub fn get_cpu_frequency() -> u64 {
fn get_cpu_frequency() -> u64 {
let mut speed: u64 = 0;
let mut len = std::mem::size_of::<u64>();
unsafe {
Expand Down Expand Up @@ -242,33 +242,3 @@ pub fn get_vendor_id_and_brand() -> (String, String) {
get_sysctl_str(b"machdep.cpu.vendor\0"),
)
}

/// get_cpu_frequency returns the CPU frequency in MHz
pub fn get_cpu_frequency() -> u64 {
let mut speed: u64 = 0;
let mut len = std::mem::size_of::<u64>();
unsafe {
ffi::sysctlbyname(
"hw.cpufrequency".as_ptr() as *const c_char,
&mut speed,
&mut len,
std::ptr::null_mut(),
0,
);
}
speed /= 1000000;
speed
}

/// get_avg_load returns the system load average value.
pub fn get_avg_load() -> LoadAvg {
let loads = vec![0f64; 3];
unsafe {
ffi::getloadavg(loads.as_ptr() as *const f64, 3);
}
LoadAvg {
one: loads[0],
five: loads[1],
fifteen: loads[2],
}
}
15 changes: 2 additions & 13 deletions src/sysinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ pub extern crate pnet_datalink as datalink;
pub use common::{AsU32, DiskType, NetworksIter, 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 num_cpus::get_physical as get_physical_cores;
pub use sys::{
get_avg_load, get_cpu_frequency, Component, Disk, NetworkData, Networks, Process,
Component, Disk, NetworkData, Networks, Process,
ProcessStatus, Processor, System,
};
pub use traits::{
Expand Down Expand Up @@ -280,16 +280,6 @@ mod test {
);
}

#[test]
fn test_get_cpu_frequency() {
println!("test get_cpu_frequency: {}", ::get_cpu_frequency());
}

#[test]
fn test_get_avg_load() {
println!("test get_avg_load: {:?}", ::get_avg_load());
}

#[test]
fn test_nic_load() {
println!("test test_nic_load: {:?}", ::NICLoad::snapshot());
Expand All @@ -302,7 +292,6 @@ mod test {

#[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");
}

Expand Down
2 changes: 1 addition & 1 deletion src/unknown/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ pub use self::component::Component;
pub use self::disk::Disk;
pub use self::network::{NetworkData, Networks};
pub use self::process::{Process, ProcessStatus};
pub use self::processor::{get_avg_load, get_cpu_frequency, Processor};
pub use self::processor::Processor;
pub use self::system::System;
9 changes: 0 additions & 9 deletions src/unknown/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,3 @@ impl ProcessorExt for Processor {
""
}
}

pub fn get_cpu_frequency() -> u64 {
0
}

/// get_avg_load returns the system load average value.
pub fn get_avg_load() -> LoadAvg {
LoadAvg::default()
}
2 changes: 1 addition & 1 deletion src/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ pub use self::component::Component;
pub use self::disk::Disk;
pub use self::network::{NetworkData, Networks};
pub use self::process::{Process, ProcessStatus};
pub use self::processor::{get_avg_load, get_cpu_frequency, Processor};
pub use self::processor::Processor;
pub use self::system::System;

0 comments on commit 2e70ddd

Please sign in to comment.