zernel/telemetry/
display.rs

1// Copyright (C) 2026 Dyber, Inc. — Proprietary
2
3use super::client::TelemetrySnapshot;
4
5/// Format a utilization bar for terminal display.
6pub fn format_gpu_bar(utilization: u8, width: usize) -> String {
7    let filled = (utilization as usize * width) / 100;
8    let empty = width - filled;
9    format!(
10        "[{}{}] {}%",
11        "#".repeat(filled),
12        " ".repeat(empty),
13        utilization
14    )
15}
16
17/// Format the full telemetry snapshot as a multi-line string.
18pub fn format_snapshot(snapshot: &TelemetrySnapshot) -> String {
19    let mut out = String::new();
20
21    for entry in &snapshot.gpu_utilization {
22        let used_gb = entry.current_bytes as f64 / (1024.0 * 1024.0 * 1024.0);
23        let total_gb = if entry.peak_bytes > 0 {
24            entry.peak_bytes as f64 / (1024.0 * 1024.0 * 1024.0)
25        } else {
26            80.0
27        };
28        out.push_str(&format!(
29            "{}: {:.1}/{:.1} GB\n",
30            entry.key, used_gb, total_gb,
31        ));
32    }
33
34    out.push_str(&format!(
35        "\nCUDA launch: p50={:.0}us p99={:.0}us\n",
36        snapshot.cuda_latency_p50_us, snapshot.cuda_latency_p99_us,
37    ));
38    out.push_str(&format!(
39        "NCCL allreduce: p50={:.0}ms p99={:.0}ms\n",
40        snapshot.nccl_allreduce_p50_ms, snapshot.nccl_allreduce_p99_ms,
41    ));
42    out.push_str(&format!(
43        "DataLoader wait: p50={:.0}ms\n",
44        snapshot.dataloader_wait_p50_ms,
45    ));
46
47    out
48}