feat: display info about throttling (#274)

* feat: add throttling info

* fix: empty throttling text
This commit is contained in:
Ilya Zlobintsev 2024-02-24 18:51:12 +02:00 committed by GitHub
parent 54370e9b22
commit 487b35ec18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 56 additions and 0 deletions

View File

@ -19,6 +19,7 @@ use lact_schema::{
PciInfo, PmfwInfo, PowerState, PowerStates, PowerStats, VoltageStats, VramStats, PciInfo, PmfwInfo, PowerState, PowerStates, PowerStats, VoltageStats, VramStats,
}; };
use pciid_parser::Database; use pciid_parser::Database;
use std::collections::BTreeMap;
use std::{ use std::{
borrow::Cow, borrow::Cow,
cell::RefCell, cell::RefCell,
@ -309,9 +310,38 @@ impl GpuController {
.get_pcie_clock_levels() .get_pcie_clock_levels()
.ok() .ok()
.and_then(|levels| levels.active), .and_then(|levels| levels.active),
throttle_info: self.get_throttle_info(),
} }
} }
#[cfg(not(feature = "libdrm_amdgpu_sys"))]
fn get_throttle_info(&self) -> Option<BTreeMap<String, Vec<String>>> {
None
}
#[cfg(feature = "libdrm_amdgpu_sys")]
fn get_throttle_info(&self) -> Option<BTreeMap<String, Vec<String>>> {
use libdrm_amdgpu_sys::AMDGPU::ThrottlerType;
self.drm_handle
.as_ref()
.and_then(|drm_handle| drm_handle.get_gpu_metrics().ok())
.and_then(|metrics| metrics.get_throttle_status_info())
.map(|throttle| {
let mut result: BTreeMap<String, Vec<String>> = BTreeMap::new();
for bit in throttle.get_all_throttler() {
let throttle_type = ThrottlerType::from(bit);
result
.entry(throttle_type.to_string())
.or_default()
.push(bit.to_string());
}
result
})
}
pub fn get_clocks_info(&self) -> anyhow::Result<ClocksInfo> { pub fn get_clocks_info(&self) -> anyhow::Result<ClocksInfo> {
let clocks_table = self let clocks_table = self
.handle .handle

View File

@ -61,6 +61,24 @@ impl GpuStatsSection {
power_current.unwrap_or(0.0), power_current.unwrap_or(0.0),
power_cap_current.unwrap_or(0.0) power_cap_current.unwrap_or(0.0)
)); ));
match &stats.throttle_info {
Some(throttle_info) => {
if throttle_info.is_empty() {
self.set_throttling("No")
} else {
let type_text: Vec<String> = throttle_info
.iter()
.map(|(throttle_type, details)| {
format!("{throttle_type} ({})", details.join(", "))
})
.collect();
let text = type_text.join(", ");
self.set_throttling(text);
}
}
None => self.set_throttling("Unknown"),
}
} }
} }
@ -105,6 +123,8 @@ mod imp {
vram_usage: RefCell<f64>, vram_usage: RefCell<f64>,
#[property(get, set)] #[property(get, set)]
vram_usage_text: RefCell<String>, vram_usage_text: RefCell<String>,
#[property(get, set)]
throttling: RefCell<String>,
} }
#[glib::object_subclass] #[glib::object_subclass]

View File

@ -75,6 +75,11 @@ template $GpuStatsSection: $PageSection {
name: "Power Usage:"; name: "Power Usage:";
value: bind template.power-usage; value: bind template.power-usage;
} }
$InfoRow {
name: "Throttling:";
value: bind template.throttling;
}
} }
} }
} }

View File

@ -179,6 +179,7 @@ pub struct DeviceStats {
pub core_power_state: Option<usize>, pub core_power_state: Option<usize>,
pub memory_power_state: Option<usize>, pub memory_power_state: Option<usize>,
pub pcie_power_state: Option<usize>, pub pcie_power_state: Option<usize>,
pub throttle_info: Option<BTreeMap<String, Vec<String>>>,
} }
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]