From 7cd6a6e0a11421e0ee656857f97a2801c2337c79 Mon Sep 17 00:00:00 2001 From: jasonwitty Date: Mon, 11 Aug 2025 23:08:35 -0700 Subject: [PATCH] gpu clippy cleanup --- socktop/src/ui/cpu.rs | 18 +++++++++++++++--- socktop/src/ui/gpu.rs | 28 +++++++++++++++++++--------- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/socktop/src/ui/cpu.rs b/socktop/src/ui/cpu.rs index 9b5e200..d52fa75 100644 --- a/socktop/src/ui/cpu.rs +++ b/socktop/src/ui/cpu.rs @@ -265,7 +265,7 @@ pub fn draw_per_core_bars( area: Rect, m: Option<&Metrics>, per_core_hist: &PerCoreHistory, - scroll_offset: usize + scroll_offset: usize, ) { f.render_widget( Block::default().borders(Borders::ALL).title("Per-core"), @@ -319,7 +319,14 @@ pub fn draw_per_core_bars( .and_then(|d| d.iter().rev().nth(20).copied()) .map(|v| v as f32) .unwrap_or(curr); - let trend = if curr > older + 0.2 { "↑" } else if curr + 0.2 < older { "↓" } else { "╌" }; + + let trend = if curr > older + 0.2 { + "↑" + } else if curr + 0.2 < older { + "↓" + } else { + "╌" + }; let fg = match curr { x if x < 25.0 => Color::Green, @@ -337,7 +344,12 @@ pub fn draw_per_core_bars( }) .unwrap_or_default(); - let spark = Sparkline::default().data(&hist).max(100).style(Style::default().fg(fg)); + let spark = Sparkline::default() + .data(&hist) + .max(100) + .style(Style::default() + .fg(fg)); + f.render_widget(spark, hchunks[0]); let label = format!("cpu{idx:<2}{trend}{curr:>5.1}%"); diff --git a/socktop/src/ui/gpu.rs b/socktop/src/ui/gpu.rs index acaa98d..72b4f10 100644 --- a/socktop/src/ui/gpu.rs +++ b/socktop/src/ui/gpu.rs @@ -2,7 +2,7 @@ use ratatui::{ layout::{Constraint, Direction, Layout, Rect}, style::{Color, Style}, text::Span, - widgets::{Block, Borders, Gauge, Paragraph} + widgets::{Block, Borders, Gauge, Paragraph}, }; use crate::types::Metrics; @@ -12,11 +12,17 @@ fn fmt_bytes(b: u64) -> String { const MB: f64 = KB * 1024.0; const GB: f64 = MB * 1024.0; let fb = b as f64; - if fb >= GB { format!("{:.1}G", fb / GB) } - else if fb >= MB { format!("{:.1}M", fb / MB) } - else if fb >= KB { format!("{:.1}K", fb / KB) } - else { format!("{b}B") } -} + + if fb >= GB { + format!("{:.1}G", fb / GB) + } else if fb >= MB { + format!("{:.1}M", fb / MB) + } else if fb >= KB { + format!("{:.1}K", fb / KB) + } else { + format!("{b}B") + } + } pub fn draw_gpu(f: &mut ratatui::Frame<'_>, area: Rect, m: Option<&Metrics>) { let mut area = area; @@ -34,7 +40,10 @@ pub fn draw_gpu(f: &mut ratatui::Frame<'_>, area: Rect, m: Option<&Metrics>) { area.x += 1; area.width = area.width.saturating_sub(2); - let Some(metrics) = m else { return; }; + let Some(metrics) = m else { + return; + }; + let Some(gpus) = metrics.gpus.as_ref() else { f.render_widget(Paragraph::new("No GPUs"), area); return; @@ -88,7 +97,8 @@ pub fn draw_gpu(f: &mut ratatui::Frame<'_>, area: Rect, m: Option<&Metrics>) { .ratio(util as f64 / 100.0); f.render_widget(util_gauge, util_cols[0]); f.render_widget( - Paragraph::new(Span::raw(format!("util: {util}%"))).style(Style::default().fg(Color::Gray)), + Paragraph::new(Span::raw(format!("util: {util}%"))) + .style(Style::default().fg(Color::Gray)), util_cols[1], ); @@ -110,7 +120,7 @@ pub fn draw_gpu(f: &mut ratatui::Frame<'_>, area: Rect, m: Option<&Metrics>) { f.render_widget( Paragraph::new(Span::raw(format!("vram: {used_s}/{total_s} ({mem_pct}%)"))) .style(Style::default().fg(Color::Gray)), - mem_cols[1] + mem_cols[1], ); } } \ No newline at end of file