Removed unnecesarry detection of frequency sensor types

This commit is contained in:
Ilya Zlobintsev
2020-10-21 11:36:16 +03:00
parent d6b4e7c25a
commit e642648671
2 changed files with 4 additions and 21 deletions

View File

@@ -9,5 +9,4 @@ edition = "2018"
[dependencies]
bincode = "1.3"
serde = { version = "1.0", features = ["derive"] }
vulkano = "0.19"
glob = "0.3"
vulkano = "0.19"

View File

@@ -1,33 +1,17 @@
use glob::glob;
use std::{collections::HashMap, fs, path::PathBuf};
use std:: {fs, path::PathBuf};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct HWMon {
hwmon_path: PathBuf,
freqs: HashMap<String, u8>,
}
impl HWMon {
pub fn new(hwmon_path: &PathBuf) -> HWMon {
let mut freqs: HashMap<String, u8> = HashMap::new();
for entry in glob(&format!("{}/freq*_label", hwmon_path.to_str().unwrap())).expect("Couldnt read glob pattern")
{
let entry = entry.unwrap();
let filename = entry.file_name().unwrap().to_str().unwrap();
let index = filename.chars().nth(4).unwrap().to_digit(10).unwrap() as u8;
let label = fs::read_to_string(hwmon_path.join(&format!("freq{}_label", index)))
.unwrap()
.trim()
.to_string();
freqs.insert(label, index);
}
println!("{:?}", freqs);
HWMon {
hwmon_path: hwmon_path.clone(),
freqs,
}
}
@@ -39,13 +23,13 @@ impl HWMon {
}
pub fn get_mem_freq(&self) -> i32 {
let filename = self.hwmon_path.join(format!("freq{}_input", self.freqs.get("mclk").unwrap()));
let filename = self.hwmon_path.join("freq2_input");
fs::read_to_string(filename).unwrap().trim().parse::<i32>().unwrap() / 1000 / 1000
}
pub fn get_gpu_freq(&self) -> i32 {
let filename = self.hwmon_path.join(format!("freq{}_input", self.freqs.get("sclk").unwrap()));
let filename = self.hwmon_path.join("freq1_input");
fs::read_to_string(filename).unwrap().trim().parse::<i32>().unwrap() / 1000 / 1000
}