gardesk/gartop / d102575

Browse files

Fetch and display GPU stats in GUI

Authored by espadonne
SHA
d1025757efd00cf215f5d4ff2e6413ad9b5abe07
Parents
342f826
Tree
2f50f77

1 changed file

StatusFile+-
M gartop/src/gui/app.rs 19 1
gartop/src/gui/app.rsmodified
@@ -12,7 +12,7 @@ use anyhow::Result;
12
 use gartk_core::{InputEvent, Key, Point, Rect};
12
 use gartk_core::{InputEvent, Key, Point, Rect};
13
 use gartk_render::{Renderer, TextStyle};
13
 use gartk_render::{Renderer, TextStyle};
14
 use gartk_x11::{Connection, EventLoop, EventLoopConfig, Window, WindowConfig};
14
 use gartk_x11::{Connection, EventLoop, EventLoopConfig, Window, WindowConfig};
15
-use gartop_ipc::{Command, CpuStats, DiskStats, MemoryStats, NetworkStats, ProcessInfo, Response, SortField, StatusInfo, TempStats};
15
+use gartop_ipc::{Command, CpuStats, DiskStats, GpuStats, MemoryStats, NetworkStats, ProcessInfo, Response, SortField, StatusInfo, TempStats};
16
 use std::collections::HashMap;
16
 use std::collections::HashMap;
17
 use std::io::{BufRead, BufReader, Write};
17
 use std::io::{BufRead, BufReader, Write};
18
 use std::os::unix::net::UnixStream;
18
 use std::os::unix::net::UnixStream;
@@ -98,6 +98,7 @@ pub struct App {
98
     network_stats: Vec<NetworkStats>,
98
     network_stats: Vec<NetworkStats>,
99
     disk_stats: Vec<DiskStats>,
99
     disk_stats: Vec<DiskStats>,
100
     temp_stats: Option<TempStats>,
100
     temp_stats: Option<TempStats>,
101
+    gpu_stats: Option<GpuStats>,
101
     cpu_history: Vec<CpuStats>,
102
     cpu_history: Vec<CpuStats>,
102
     memory_history: Vec<MemoryStats>,
103
     memory_history: Vec<MemoryStats>,
103
     network_history: Vec<Vec<NetworkStats>>,
104
     network_history: Vec<Vec<NetworkStats>>,
@@ -195,6 +196,7 @@ impl App {
195
             network_stats: Vec::new(),
196
             network_stats: Vec::new(),
196
             disk_stats: Vec::new(),
197
             disk_stats: Vec::new(),
197
             temp_stats: None,
198
             temp_stats: None,
199
+            gpu_stats: None,
198
             cpu_history: Vec::new(),
200
             cpu_history: Vec::new(),
199
             memory_history: Vec::new(),
201
             memory_history: Vec::new(),
200
             network_history: Vec::new(),
202
             network_history: Vec::new(),
@@ -321,6 +323,13 @@ impl App {
321
             }
323
             }
322
         }
324
         }
323
 
325
 
326
+        // Get GPU stats
327
+        if let Some(resp) = self.send_command(&Command::GetGpu) {
328
+            if resp.success {
329
+                self.gpu_stats = resp.data.and_then(|d| serde_json::from_value(d).ok());
330
+            }
331
+        }
332
+
324
         // Get processes sorted by current tab's resource (skip when frozen)
333
         // Get processes sorted by current tab's resource (skip when frozen)
325
         if !self.frozen {
334
         if !self.frozen {
326
             let sort_field = match self.tab_bar.active() {
335
             let sort_field = match self.tab_bar.active() {
@@ -383,6 +392,15 @@ impl App {
383
                 .max_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal))
392
                 .max_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal))
384
         });
393
         });
385
         self.header.update_temp(max_temp);
394
         self.header.update_temp(max_temp);
395
+
396
+        // Get primary GPU usage (first device with non-zero usage)
397
+        let gpu_usage = self.gpu_stats.as_ref().and_then(|gs| {
398
+            gs.devices.iter()
399
+                .map(|d| d.usage_percent)
400
+                .find(|&u| u > 0.0)
401
+                .or_else(|| gs.devices.first().map(|d| d.usage_percent))
402
+        });
403
+        self.header.update_gpu(gpu_usage);
386
     }
404
     }
387
 
405
 
388
     /// Render the entire UI.
406
     /// Render the entire UI.