sprint 4 adds gpu support

This commit is contained in:
2026-02-19 15:43:43 +00:00
parent c897d94180
commit 6b6e0ed9bd
4 changed files with 241 additions and 9 deletions

View File

@@ -100,15 +100,25 @@ fn draw_body(frame: &mut Frame, area: Rect, state: &AppState) {
if state.show_process_details {
let split = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Min(8), Constraint::Length(6)])
.constraints([
Constraint::Min(8),
Constraint::Length(5),
Constraint::Length(6),
])
.split(sidebar);
draw_process_details(frame, split[0], state);
draw_network(frame, split[1], state);
draw_gpu(frame, split[1], state);
draw_network(frame, split[2], state);
} else {
draw_network(frame, sidebar, state);
let split = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(5), Constraint::Min(4)])
.split(sidebar);
draw_gpu(frame, split[0], state);
draw_network(frame, split[1], state);
}
} else {
let net_line = compact_network_line(state);
let net_line = compact_status_line(state);
let net_area = Rect {
x: main.x,
y: main.y,
@@ -325,6 +335,50 @@ fn draw_disks(frame: &mut Frame, area: Rect, state: &AppState) {
}
}
fn draw_gpu(frame: &mut Frame, area: Rect, state: &AppState) {
let block = Block::default().title("GPU").borders(Borders::ALL);
let lines = if state.snapshot.gpus.is_empty() {
vec![Line::from("No GPU detected")]
} else {
state
.snapshot
.gpus
.iter()
.take(2)
.map(|gpu| {
let util = gpu
.utilization_percent
.map(|u| format!("{u:.0}%"))
.unwrap_or_else(|| "-".to_string());
let mem = match (gpu.mem_used_bytes, gpu.mem_total_bytes) {
(Some(used), Some(total)) => {
format!("{}/{}", fmt_bytes_compact(used), fmt_bytes_compact(total))
}
_ => "-".to_string(),
};
Line::from(format!(
"{} {} u:{} m:{} t:{}",
truncate(&gpu.vendor, 4),
truncate(&gpu.name, 10),
util,
mem,
gpu.temperature_c
.map(|t| format!("{t:.0}C"))
.unwrap_or_else(|| "-".to_string())
))
})
.collect::<Vec<_>>()
};
frame.render_widget(
Paragraph::new(lines)
.block(block)
.alignment(Alignment::Left)
.wrap(Wrap { trim: true }),
area,
);
}
fn draw_network(frame: &mut Frame, area: Rect, state: &AppState) {
let block = Block::default().title("Net").borders(Borders::ALL);
@@ -594,13 +648,25 @@ fn sort_header(name: &str, col: ProcessSort, state: &AppState) -> String {
}
}
fn compact_network_line(state: &AppState) -> String {
fn compact_status_line(state: &AppState) -> String {
let gpu = state.snapshot.gpus.first().map_or_else(
|| "GPU -".to_string(),
|g| {
let util = g
.utilization_percent
.map(|u| format!("{u:.0}%"))
.unwrap_or_else(|| "-".to_string());
format!("GPU {util}")
},
);
format!(
"RX {}/s | TX {}/s | tot {}/{}",
"RX {}/s | TX {}/s | tot {}/{} | {}",
fmt_bytes_compact(state.network_rate.rx_bps as u64),
fmt_bytes_compact(state.network_rate.tx_bps as u64),
fmt_bytes_compact(state.snapshot.network_totals.rx_bytes),
fmt_bytes_compact(state.snapshot.network_totals.tx_bytes)
fmt_bytes_compact(state.snapshot.network_totals.tx_bytes),
gpu
)
}