@@ -12,7 +12,7 @@ use anyhow::Result; |
| 12 | 12 | use gartk_core::{InputEvent, Key, Point, Rect}; |
| 13 | 13 | use gartk_render::{Renderer, TextStyle}; |
| 14 | 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 | 16 | use std::collections::HashMap; |
| 17 | 17 | use std::io::{BufRead, BufReader, Write}; |
| 18 | 18 | use std::os::unix::net::UnixStream; |
@@ -98,6 +98,7 @@ pub struct App { |
| 98 | 98 | network_stats: Vec<NetworkStats>, |
| 99 | 99 | disk_stats: Vec<DiskStats>, |
| 100 | 100 | temp_stats: Option<TempStats>, |
| 101 | + gpu_stats: Option<GpuStats>, |
| 101 | 102 | cpu_history: Vec<CpuStats>, |
| 102 | 103 | memory_history: Vec<MemoryStats>, |
| 103 | 104 | network_history: Vec<Vec<NetworkStats>>, |
@@ -195,6 +196,7 @@ impl App { |
| 195 | 196 | network_stats: Vec::new(), |
| 196 | 197 | disk_stats: Vec::new(), |
| 197 | 198 | temp_stats: None, |
| 199 | + gpu_stats: None, |
| 198 | 200 | cpu_history: Vec::new(), |
| 199 | 201 | memory_history: Vec::new(), |
| 200 | 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 | 333 | // Get processes sorted by current tab's resource (skip when frozen) |
| 325 | 334 | if !self.frozen { |
| 326 | 335 | let sort_field = match self.tab_bar.active() { |
@@ -383,6 +392,15 @@ impl App { |
| 383 | 392 | .max_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal)) |
| 384 | 393 | }); |
| 385 | 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 | 406 | /// Render the entire UI. |