mirror of
https://codeberg.org/icewind/palantir.git
synced 2026-06-03 18:24:08 +02:00
prepare for windows impl
This commit is contained in:
parent
f363cac81d
commit
d12b70d11e
16 changed files with 550 additions and 279 deletions
|
|
@ -1,58 +0,0 @@
|
|||
use crate::gpu::GpuUsage;
|
||||
use crate::sensors::Memory;
|
||||
use nvml_wrapper::enum_wrappers::device::TemperatureSensor;
|
||||
use nvml_wrapper::{Device, Nvml};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
static NVIDIA: Lazy<Option<Nvml>> = Lazy::new(|| Nvml::init().ok());
|
||||
|
||||
fn device() -> Option<Device<'static>> {
|
||||
NVIDIA.as_ref()?.device_by_index(0).ok()
|
||||
}
|
||||
|
||||
pub fn temperature() -> Option<f32> {
|
||||
let temp = device()?.temperature(TemperatureSensor::Gpu).ok()?;
|
||||
Some(temp as f32)
|
||||
}
|
||||
|
||||
pub fn power() -> Option<u64> {
|
||||
device()?
|
||||
.total_energy_consumption()
|
||||
.ok()
|
||||
.map(|mj| mj * 1_000)
|
||||
}
|
||||
|
||||
pub fn memory() -> Option<Memory> {
|
||||
let mem = device()?.memory_info().ok()?;
|
||||
Some(Memory {
|
||||
total: mem.total,
|
||||
free: mem.free,
|
||||
available: mem.free,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn utilization() -> impl Iterator<Item = GpuUsage> {
|
||||
let sources = if let Some(device) = device() {
|
||||
let utilization = device.utilization_rates().ok();
|
||||
[
|
||||
("compute", utilization.as_ref().map(|u| u.gpu)),
|
||||
("memory", utilization.as_ref().map(|u| u.gpu)),
|
||||
(
|
||||
"encode",
|
||||
device.encoder_utilization().ok().map(|u| u.utilization),
|
||||
),
|
||||
(
|
||||
"decode",
|
||||
device.decoder_utilization().ok().map(|u| u.utilization),
|
||||
),
|
||||
]
|
||||
} else {
|
||||
[("", None); 4]
|
||||
};
|
||||
sources.into_iter().flat_map(|(system, usage)| {
|
||||
Some(GpuUsage {
|
||||
system,
|
||||
usage: usage?,
|
||||
})
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue