Skip to content

Commit

Permalink
update nvml-wrapper to 0.7.0 (#89)
Browse files Browse the repository at this point in the history
* update nvml-wrapper to 0.7.0

* only init NVML once at startup
  • Loading branch information
alexmaco committed Dec 14, 2020
1 parent 140d4a4 commit bcc0130
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
29 changes: 25 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ signal-hook = "0.1.*"
log = { version = "0.4.*"}
env_logger = { version = "0.8.1", default-features = false }
libc = "0.2"
nvml-wrapper = { version = "0.6.0", optional = true }
nvml-wrapper = { version = "0.7.0", optional = true }
13 changes: 4 additions & 9 deletions src/graphics_nvidia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::metrics::CPUTimeApp;
use nvml::device::Device;
use nvml::enum_wrappers::device::{Clock, TemperatureSensor, TemperatureThreshold};
use nvml::struct_wrappers::device::ProcessUtilizationSample;
use nvml::NVML;
use std::convert::TryFrom;
use std::fmt;

Expand Down Expand Up @@ -93,15 +92,11 @@ impl fmt::Display for GraphicsDevice {

impl GraphicsExt for CPUTimeApp {
fn update_gfx_devices(&mut self) {
self.gfx_devices.clear();
let nvml = NVML::init();
let n = match nvml {
Ok(n) => n,
Err(e) => {
error!("Couldn't init NVML: {:?}", e);
return;
}
let n = match &self.nvml {
Some(n) => n,
_ => return,
};
self.gfx_devices.clear();

let count = n.device_count().unwrap_or(0);
for i in 0..count {
Expand Down
11 changes: 11 additions & 0 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ pub struct CPUTimeApp {
pub max_pid_len: usize,
pub batteries: Vec<battery::Battery>,
pub uptime: Duration,
#[cfg(all(target_os = "linux", feature = "nvidia"))]
pub nvml: Option<nvml::NVML>,
}

impl CPUTimeApp {
Expand Down Expand Up @@ -233,6 +235,15 @@ impl CPUTimeApp {
top_disk_writer_pid: None,
uptime: Duration::from_secs(0),
gfx_devices: vec![],

#[cfg(all(target_os = "linux", feature = "nvidia"))]
nvml: match nvml::NVML::init() {
Ok(n) => Some(n),
Err(e) => {
error!("Couldn't init NVML: {:?}", e);
None
}
},
};
debug!("Initial Metrics Update");
s.system.refresh_all();
Expand Down

0 comments on commit bcc0130

Please sign in to comment.