feat(ui): Build Diagnostics Panel with real-time plots

This commit is contained in:
2026-02-23 14:50:44 -05:00
parent 0b148325d0
commit 30d838c3a0
2 changed files with 134 additions and 0 deletions

69
gui.py
View File

@@ -460,6 +460,7 @@ class App:
"Theme": "win_theme",
"Last Script Output": "win_script_output",
"Text Viewer": "win_text_viewer",
"Diagnostics": "win_diagnostics",
}
@@ -496,6 +497,12 @@ class App:
self._script_blink_start_time = 0.0
self.perf_monitor = PerformanceMonitor()
self.perf_history = {
"frame_time": [0.0] * 100,
"fps": [0.0] * 100,
"cpu": [0.0] * 100,
"input_lag": [0.0] * 100
}
session_logger.open_session()
ai_client.set_provider(self.current_provider, self.current_model)
@@ -815,6 +822,32 @@ class App:
else:
dpg.configure_item("gemini_cache_label", show=False)
# Update Diagnostics panel
if dpg.is_item_shown("win_diagnostics"):
metrics = self.perf_monitor.get_metrics()
# Update history
self.perf_history["frame_time"].append(metrics['last_frame_time_ms'])
self.perf_history["fps"].append(metrics['fps'])
self.perf_history["cpu"].append(metrics['cpu_percent'])
self.perf_history["input_lag"].append(metrics['input_lag_ms'])
for k in self.perf_history:
if len(self.perf_history[k]) > 100:
self.perf_history[k].pop(0)
# Update labels
dpg.set_value("perf_fps_text", f"{metrics['fps']:.1f}")
dpg.set_value("perf_frame_text", f"{metrics['last_frame_time_ms']:.1f}ms")
dpg.set_value("perf_cpu_text", f"{metrics['cpu_percent']:.1f}%")
dpg.set_value("perf_lag_text", f"{metrics['input_lag_ms']:.1f}ms")
# Update plots
if dpg.does_item_exist("perf_frame_plot"):
dpg.set_value("perf_frame_plot", [list(range(100)), self.perf_history["frame_time"]])
if dpg.does_item_exist("perf_cpu_plot"):
dpg.set_value("perf_cpu_plot", [list(range(100)), self.perf_history["cpu"]])
def _append_comms_entry(self, entry: dict, idx: int):
if not dpg.does_item_exist("comms_scroll"):
return
@@ -2110,6 +2143,42 @@ class App:
with dpg.child_window(tag="text_viewer_wrap_container", width=-1, height=-1, border=False, show=False):
dpg.add_text("", tag="text_viewer_wrap", wrap=0)
# ---- Diagnostics panel ----
with dpg.window(
label="Diagnostics",
tag="win_diagnostics",
pos=(8, 804),
width=400,
height=380,
no_close=False,
):
dpg.add_text("Performance Telemetry")
with dpg.group(horizontal=True):
dpg.add_text("FPS:")
dpg.add_text("0.0", tag="perf_fps_text", color=(180, 255, 180))
dpg.add_spacer(width=20)
dpg.add_text("Frame:")
dpg.add_text("0.0ms", tag="perf_frame_text", color=(100, 200, 255))
with dpg.add_plot(label="Frame Time (ms)", height=100, width=-1, no_mouse_pos=True):
dpg.add_plot_axis(dpg.mvXAxis, label="samples", no_tick_labels=True)
with dpg.plot_axis(dpg.mvYAxis, label="ms"):
dpg.add_line_series(list(range(100)), self.perf_history["frame_time"], label="frame time", tag="perf_frame_plot")
dpg.set_axis_limits(dpg.last_item(), 0, 50)
with dpg.group(horizontal=True):
dpg.add_text("CPU:")
dpg.add_text("0.0%", tag="perf_cpu_text", color=(255, 220, 100))
dpg.add_spacer(width=20)
dpg.add_text("Input Lag:")
dpg.add_text("0.0ms", tag="perf_lag_text", color=(255, 180, 80))
with dpg.add_plot(label="CPU Usage (%)", height=100, width=-1, no_mouse_pos=True):
dpg.add_plot_axis(dpg.mvXAxis, label="samples", no_tick_labels=True)
with dpg.plot_axis(dpg.mvYAxis, label="%"):
dpg.add_line_series(list(range(100)), self.perf_history["cpu"], label="cpu usage", tag="perf_cpu_plot")
dpg.set_axis_limits(dpg.last_item(), 0, 100)
def run(self):
dpg.create_context()
dpg.configure_app(docking=True, docking_space=True, init_file="dpg_layout.ini")