Skip to main content

trueno_gpu/monitor/tui_layout/
render_state.rs

1//! TUI render state types for compute monitoring display.
2
3use std::collections::VecDeque;
4
5use crate::monitor::device::DeviceId;
6use crate::monitor::memory::PressureLevel;
7
8// ============================================================================
9// TUI Render State
10// ============================================================================
11
12/// Complete TUI render state
13#[derive(Debug, Clone)]
14pub struct TuiRenderState {
15    /// CPU device metrics
16    pub cpu: Option<DeviceRenderState>,
17    /// GPU device metrics
18    pub gpus: Vec<DeviceRenderState>,
19    /// Memory metrics
20    pub memory: MemoryRenderState,
21    /// Data flow metrics
22    pub data_flow: DataFlowRenderState,
23    /// Active kernels
24    pub kernels: Vec<KernelRenderState>,
25    /// Current pressure level
26    pub pressure: PressureLevel,
27    /// Stress test active
28    pub stress_active: bool,
29    /// Paused
30    pub paused: bool,
31    /// Current focus
32    pub focused_section: usize,
33    /// Error message (if any)
34    pub error: Option<String>,
35}
36
37impl Default for TuiRenderState {
38    fn default() -> Self {
39        Self {
40            cpu: None,
41            gpus: Vec::new(),
42            memory: MemoryRenderState::default(),
43            data_flow: DataFlowRenderState::default(),
44            kernels: Vec::new(),
45            pressure: PressureLevel::Ok,
46            stress_active: false,
47            paused: false,
48            focused_section: 0,
49            error: None,
50        }
51    }
52}
53
54/// Device render state
55#[derive(Debug, Clone)]
56pub struct DeviceRenderState {
57    /// Device ID
58    pub device_id: DeviceId,
59    /// Device name
60    pub name: String,
61    /// Utilization percentage
62    pub utilization_pct: f64,
63    /// Temperature in Celsius
64    pub temperature_c: f64,
65    /// Power in Watts
66    pub power_watts: f64,
67    /// Power limit in Watts
68    pub power_limit_watts: f64,
69    /// Clock speed in MHz
70    pub clock_mhz: u32,
71    /// Utilization history
72    pub history: VecDeque<f64>,
73}
74
75/// Memory render state
76#[derive(Debug, Clone, Default)]
77pub struct MemoryRenderState {
78    /// RAM usage percentage
79    pub ram_pct: f64,
80    /// RAM used in GB
81    pub ram_used_gb: f64,
82    /// RAM total in GB
83    pub ram_total_gb: f64,
84    /// Swap usage percentage
85    pub swap_pct: f64,
86    /// Swap used in GB
87    pub swap_used_gb: f64,
88    /// Swap total in GB
89    pub swap_total_gb: f64,
90    /// VRAM metrics per GPU
91    pub vram: Vec<(DeviceId, f64, f64, f64)>, // (id, pct, used_gb, total_gb)
92    /// RAM history
93    pub ram_history: VecDeque<f64>,
94}
95
96/// Data flow render state
97#[derive(Debug, Clone, Default)]
98pub struct DataFlowRenderState {
99    /// PCIe TX in GB/s
100    pub pcie_tx_gbps: f64,
101    /// PCIe RX in GB/s
102    pub pcie_rx_gbps: f64,
103    /// PCIe theoretical in GB/s
104    pub pcie_theoretical_gbps: f64,
105    /// Memory bus utilization percentage
106    pub memory_bus_pct: f64,
107    /// Active transfers
108    pub transfers: Vec<(String, String, f64)>, // (label, direction, progress)
109}
110
111/// Kernel render state
112#[derive(Debug, Clone)]
113pub struct KernelRenderState {
114    /// Kernel name
115    pub name: String,
116    /// Device ID
117    pub device_id: DeviceId,
118    /// Progress percentage
119    pub progress_pct: f64,
120    /// Grid dimensions
121    pub grid: String,
122    /// Elapsed time in ms
123    pub elapsed_ms: f64,
124}