src/tools/procfs.rs: simplify read_cpuinfo()

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
This commit is contained in:
Christian Ebner 2019-04-12 11:52:42 +02:00 committed by Dietmar Maurer
parent 63bd6a9f5a
commit cc93bacb72
1 changed files with 6 additions and 11 deletions

View File

@ -189,17 +189,12 @@ pub fn read_cpuinfo() -> Result<ProcFsCPUInfo, Error> {
let mut content_iter = content.split(":"); let mut content_iter = content.split(":");
match (content_iter.next(), content_iter.next()) { match (content_iter.next(), content_iter.next()) {
(Some(key), Some(value)) => { (Some(key), Some(value)) => {
let mut key_iter = key.split_whitespace(); match key.trim_end() {
match (key_iter.next(), key_iter.next()) { "processor" => cpuinfo.cpus += 1,
(Some("processor"), None) => "model name" => cpuinfo.model = value.trim().to_string(),
cpuinfo.cpus += 1, "cpu MHz" => cpuinfo.mhz = value.trim().parse::<f64>()?,
(Some("model"), Some("name")) => "flags" => cpuinfo.hvm = value.contains(" vmx ") || value.contains(" svm "),
cpuinfo.model = value.trim().to_string(), "physical id" => {
(Some("cpu"), Some("MHz")) =>
cpuinfo.mhz = value.trim().parse::<f64>()?,
(Some("flags"), None) =>
cpuinfo.hvm = value.contains(" vmx ") || value.contains(" svm "),
(Some("physical"), Some("id")) => {
let id = value.trim().parse::<u8>()?; let id = value.trim().parse::<u8>()?;
socket_ids.insert(id); socket_ids.insert(id);
}, },