Skip to content

Commit

Permalink
Merge pull request #415 from nokyan/nvidia-usage-fix
Browse files Browse the repository at this point in the history
Fix usage statistics for NVIDIA being wrong
  • Loading branch information
nokyan authored Dec 5, 2024
2 parents 8cc3aa3 + 9a4651d commit 1b70083
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
5 changes: 3 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ gettext_package = meson.project_name()
if get_option('profile') == 'development'
profile = 'Devel'
vcs_tag = run_command('git', 'rev-parse', '--short', 'HEAD').stdout().strip()
if vcs_tag == ''
vcs_branch = run_command('git', 'rev-parse', '--abbrev-ref', 'HEAD').stdout().strip()
if vcs_tag == '' or vcs_branch == ''
version_suffix = '-devel'
else
version_suffix = '-@0@'.format(vcs_tag)
version_suffix = '-@0@/@1@'.format(vcs_branch, vcs_tag)
endif
application_id = '@0@.@1@'.format(base_id, profile)
else
Expand Down
2 changes: 1 addition & 1 deletion src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl Application {

pub fn run(&self) {
info!("Resources ({APP_ID})");
info!("Version: {VERSION} ({PROFILE})");
info!("Version: {VERSION}");
info!("Datadir: {PKGDATADIR}");

let os_info = OsInfo::get();
Expand Down
18 changes: 9 additions & 9 deletions src/ui/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mod imp {
use std::{cell::RefCell, collections::HashMap};

use crate::{
config::VERSION,
ui::{
pages::{
applications::ResApplications, cpu::ResCPU, memory::ResMemory,
Expand Down Expand Up @@ -158,6 +159,9 @@ mod imp {
// Devel Profile
if PROFILE == "Devel" {
obj.add_css_class("devel");
obj.set_title(Some(
&format!("{} ({})", obj.title().unwrap_or_default(), VERSION).trim(),
));
}

// Load latest window state
Expand Down Expand Up @@ -297,11 +301,9 @@ impl MainWindow {
}
}

fn init_gpu_pages(self: &MainWindow) -> Vec<Gpu> {
fn init_gpu_pages(self: &MainWindow, gpus: &[Gpu]) {
let imp = self.imp();

let gpus = Gpu::get_gpus().unwrap_or_default();

for (i, gpu) in gpus.iter().enumerate() {
let page = ResGPU::new();

Expand All @@ -325,8 +327,6 @@ impl MainWindow {
.borrow_mut()
.insert(gpu.pci_slot(), (gpu.clone(), added_page));
}

gpus
}

fn init_npu_pages(self: &MainWindow) -> Vec<Npu> {
Expand Down Expand Up @@ -366,6 +366,10 @@ impl MainWindow {

let gpus = Gpu::get_gpus().unwrap_or_default();

if !ARGS.disable_gpu_monitoring {
self.init_gpu_pages(&gpus);
}

imp.resources_sidebar.set_stack(&imp.content_stack);

if SETTINGS.show_search_on_start() {
Expand Down Expand Up @@ -413,10 +417,6 @@ impl MainWindow {
imp.memory.init();
}

if !ARGS.disable_gpu_monitoring {
self.init_gpu_pages();
}

if !ARGS.disable_npu_monitoring {
self.init_npu_pages();
}
Expand Down
19 changes: 5 additions & 14 deletions src/utils/gpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,11 @@ impl GpuData {
pub fn new(gpu: &Gpu) -> Self {
let pci_slot = gpu.pci_slot();

let usage_fraction = gpu
.usage()
.map(|usage| (usage / 100.0).clamp(0.0, 1.0))
.ok();

let encode_fraction = gpu
.encode_usage()
.map(|usage| (usage / 100.0).clamp(0.0, 1.0))
.ok();

let decode_fraction = gpu
.decode_usage()
.map(|usage| (usage / 100.0).clamp(0.0, 1.0))
.ok();
let usage_fraction = gpu.usage().map(|usage| usage.clamp(0.0, 1.0)).ok();

let encode_fraction = gpu.encode_usage().map(|usage| usage.clamp(0.0, 1.0)).ok();

let decode_fraction = gpu.decode_usage().map(|usage| usage.clamp(0.0, 1.0)).ok();

let total_vram = gpu.total_vram().ok();
let used_vram = gpu.used_vram().ok();
Expand Down

0 comments on commit 1b70083

Please sign in to comment.