""" gui/pages/data_interrupts.py — ∿ Interrupts Interrupt rate, wakeup latency, and their energy cost. """ import streamlit as st import pandas as pd import plotly.graph_objects as go from gui.config import PL, WF_COLORS from gui.pages._dm_helpers import get_runs, rgba, no_data_banner from gui.db import q, q1 ACCENT = "#a78bfa" def render(ctx: dict) -> None: df = get_runs(ctx) if df.empty or "interrupt_rate" not in df.columns: no_data_banner("No interrupt rate data available yet.", ACCENT) return df = df[df["interrupt_rate"].notna() & (df["interrupt_rate"] > 0)].copy() if df.empty: no_data_banner("No runs with interrupt data yet.", ACCENT) return has_energy = "energy_j" in df.columns has_wakeup = "wakeup_latency_us" in df.columns has_irq_ps = "interrupts_per_second" in df.columns lin = df[df["workflow_type"] == "linear"] age = df[df["workflow_type"] == "agentic"] avg_irq_lin = lin["interrupt_rate"].mean() if not lin.empty else 0 avg_irq_age = age["interrupt_rate"].mean() if not age.empty else 0 avg_wakeup = df["wakeup_latency_us"].mean() if has_wakeup else 0 avg_irq_ps = df["interrupts_per_second"].mean() if has_irq_ps else 0 # ── Header ──────────────────────────────────────────────────────────────── st.markdown( f"
" f"
" f"Interrupts — {len(df)} runs
" f"
" + "".join([ f"
{v}
" f"
{l}
" for v, l, c in [ (f"{avg_irq_lin:.0f}", "Interrupt rate linear", WF_COLORS["linear"]), (f"{avg_irq_age:.0f}", "Interrupt rate agentic", WF_COLORS["agentic"]), (f"{avg_wakeup:.1f}µs", "Avg wakeup latency", "#f59e0b"), (f"{avg_irq_ps:.0f}/s", "Interrupts/sec", ACCENT), ] ]) + "
", unsafe_allow_html=True) col1, col2 = st.columns(2) with col1: st.markdown( f"
" f"Interrupt rate vs Energy
", unsafe_allow_html=True) fig = go.Figure() if has_energy: for wf, clr in WF_COLORS.items(): sub = df[df["workflow_type"] == wf] sub = sub[sub["energy_j"].notna() & (sub["energy_j"] > 0)] if sub.empty: continue fig.add_trace(go.Scatter( x=sub["interrupt_rate"], y=sub["energy_j"], mode="markers", name=wf, marker=dict(color=clr, size=5, opacity=0.6))) fig.update_layout(**PL, height=260, xaxis_title="Interrupt rate", yaxis_title="Energy (J)") st.plotly_chart(fig, use_container_width=True, key="dm_irq_scatter") with col2: st.markdown( f"
" f"Interrupt rate distribution
", unsafe_allow_html=True) fig2 = go.Figure() for wf, clr in WF_COLORS.items(): sub = df[df["workflow_type"] == wf]["interrupt_rate"].dropna() if sub.empty: continue fig2.add_trace(go.Box( y=sub, name=wf, marker_color=clr, line_color=clr, boxmean=True)) fig2.update_layout(**PL, height=260, yaxis_title="Interrupt rate", showlegend=False) st.plotly_chart(fig2, use_container_width=True, key="dm_irq_box") # ── Trend over runs ─────────────────────────────────────────────────────── st.markdown( f"
" f"Interrupt rate trend across runs
", unsafe_allow_html=True) df_sorted = df.sort_values("run_id") if "run_id" in df.columns else df fig3 = go.Figure() for wf, clr in WF_COLORS.items(): sub = df_sorted[df_sorted["workflow_type"] == wf] if sub.empty: continue x_vals = sub["run_id"] if "run_id" in sub.columns else sub.index fig3.add_trace(go.Scatter( x=x_vals, y=sub["interrupt_rate"], mode="markers+lines", name=wf, marker=dict(color=clr, size=3), line=dict(color=clr, width=1), opacity=0.7)) fig3.update_layout(**PL, height=220, xaxis_title="Run ID", yaxis_title="Interrupt rate") st.plotly_chart(fig3, use_container_width=True, key="dm_irq_trend") # ── interrupt_samples time series ───────────────────────────────────────── st.markdown( f"
" f"Time-series drilldown — interrupt samples
", unsafe_allow_html=True) sample_count = q1("SELECT COUNT(*) AS n FROM interrupt_samples").get("n", 0) or 0 if sample_count == 0: st.info("No interrupt_samples time-series data yet.") else: run_ids = df["run_id"].dropna().astype(int).sort_values( ascending=False).head(50).tolist() \ if "run_id" in df.columns else [] if run_ids: sel_run = st.selectbox( "Select run", run_ids, key="dm_irq_run_sel", format_func=lambda x: f"Run {x}") samples = q(f""" SELECT timestamp_ns / 1e9 AS time_s, interrupts_per_sec FROM interrupt_samples WHERE run_id = {int(sel_run)} ORDER BY timestamp_ns """) if not samples.empty: samples["time_s"] -= samples["time_s"].min() fig4 = go.Figure(go.Scatter( x=samples["time_s"], y=samples["interrupts_per_sec"], mode="lines", line=dict(color=ACCENT, width=1.5), fill="tozeroy", fillcolor=rgba(ACCENT, 0.13), # rgba() not hex8 )) fig4.update_layout(**PL, height=220, xaxis_title="Time (s)", yaxis_title="Interrupts/sec", showlegend=False) st.plotly_chart(fig4, use_container_width=True, key=f"dm_irq_samples_{sel_run}") # ── Insight ─────────────────────────────────────────────────────────────── irq_delta = avg_irq_age - avg_irq_lin st.markdown( f"
" f"Agentic runs generate {irq_delta:+.0f} more interrupts than linear. " f"Each interrupt forces a C-state exit, preventing deep sleep recovery " f"and directly increasing package energy.
", unsafe_allow_html=True)