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

Fix some issues causing errors in TiKV on my machine #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl IOLoad {
.split_whitespace()
.map(|w| w.parse().unwrap_or_default())
.collect::<Vec<f64>>();
if parts.len() != 11 {
if parts.len() < 11 {
continue;
}
let load = IOLoad {
Expand Down
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, 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;
13 changes: 13 additions & 0 deletions src/linux/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have a test to cover it in CI?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet.

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();
Expand Down
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, 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;
6 changes: 6 additions & 0 deletions src/mac/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/sysinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,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};
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, 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;
5 changes: 5 additions & 0 deletions src/unknown/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 6 additions & 0 deletions src/windows/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down