Skip to content

Commit 75f3d21

Browse files
committed
refactor(ui): redesign busyness overlay vitals as sparkline stat tiles
Merge the duplicated sparkline row and numeric tile grid into three vital tiles (CPU, memory, event-loop delay) with gradient area charts, a live pulse dot, pointer scrubbing with value+age readout, and a danger tint driven by the gateway's own event-loop degradation reasons. Memory auto-ranges its baseline so RSS trends stay visible.
1 parent 52e29ff commit 75f3d21

7 files changed

Lines changed: 380 additions & 148 deletions

File tree

‎scripts/control-ui-mock-dev.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2616,7 +2616,12 @@ async function createChatPickerScenario(
26162616
},
26172617
},
26182618
status: {
2619-
eventLoop: { utilization: 0.42, delayP99Ms: 12, delayMaxMs: 87 },
2619+
eventLoop: { utilization: 0.42, cpuCoreRatio: 0.24, delayP99Ms: 12, delayMaxMs: 87 },
2620+
processMemory: {
2621+
rssBytes: 432 * 1_048_576,
2622+
heapUsedBytes: 210 * 1_048_576,
2623+
heapTotalBytes: 280 * 1_048_576,
2624+
},
26202625
uptimeMs: 5_412_000,
26212626
},
26222627
"last-heartbeat": { ts: baseTime },

‎ui/src/i18n/locales/en.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,9 +1441,10 @@ export const en: TranslationMap = {
14411441
cpu: "CPU",
14421442
memory: "Memory",
14431443
memoryMb: "{value} MB",
1444-
utilization: "Utilization",
1444+
loopShort: "loop {value}",
1445+
heapShort: "heap {value}",
1446+
maxShort: "max {value}",
14451447
delayP99: "Delay p99",
1446-
delayMax: "Delay max",
14471448
uptime: "Uptime",
14481449
activeRunsCount: "{count} active",
14491450
noActiveRuns: "No active runs.",

‎ui/src/pages/debug/debug-overlay-sections.ts‎

Lines changed: 77 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
type CommandLaneDiagnostics,
1414
} from "../../lib/gateway-diagnostics.ts";
1515
import { renderCommandLaneRows } from "./lane-table.ts";
16+
import "./sparkline-tile.ts";
17+
import type { SparklineSample } from "./sparkline-tile.ts";
1618

1719
type DebugOverlaySectionContext = {
1820
client: GatewayBrowserClient;
@@ -23,7 +25,7 @@ type TypedDebugOverlaySectionDescriptor<T> = {
2325
id: string;
2426
titleKey: string;
2527
load: (context: DebugOverlaySectionContext, signal: AbortSignal) => Promise<T>;
26-
render: (value: T, statusHistory: readonly DebugOverlayStatusSnapshot[]) => TemplateResult;
28+
render: (value: T, statusHistory: readonly DebugOverlayStatusSample[]) => TemplateResult;
2729
};
2830

2931
export type DebugOverlaySectionDescriptor = TypedDebugOverlaySectionDescriptor<unknown>;
@@ -45,6 +47,7 @@ type EventLoopSnapshot = {
4547
cpuCoreRatio?: number;
4648
delayP99Ms?: number;
4749
delayMaxMs?: number;
50+
reasons?: string[];
4851
};
4952

5053
export type DebugOverlayStatusSnapshot = {
@@ -57,6 +60,11 @@ export type DebugOverlayStatusSnapshot = {
5760
uptimeMs?: number;
5861
};
5962

63+
export type DebugOverlayStatusSample = {
64+
at: number;
65+
status: DebugOverlayStatusSnapshot;
66+
};
67+
6068
type ActiveSession = {
6169
key?: string;
6270
sessionId?: string;
@@ -82,104 +90,86 @@ function renderLanes(diagnostics: CommandLaneDiagnostics): TemplateResult {
8290
`;
8391
}
8492

85-
function renderSparkline(
86-
history: readonly DebugOverlayStatusSnapshot[],
87-
kind: "cpu" | "memory" | "delay",
88-
label: string,
89-
readValue: (sample: DebugOverlayStatusSnapshot) => number | undefined,
90-
formatValue: (value: number) => string | undefined,
91-
) {
92-
const values = history.map(readValue).filter((value): value is number => Number.isFinite(value));
93-
const current = values.at(-1);
94-
if (values.length < 2 || current === undefined) {
95-
return nothing;
93+
function collectSamples(
94+
history: readonly DebugOverlayStatusSample[],
95+
read: (status: DebugOverlayStatusSnapshot) => number | undefined,
96+
): SparklineSample[] {
97+
const samples: SparklineSample[] = [];
98+
for (const entry of history) {
99+
const value = read(entry.status);
100+
if (typeof value === "number" && Number.isFinite(value)) {
101+
samples.push({ value, at: entry.at });
102+
}
96103
}
97-
const maximum = Math.max(...values, 1);
98-
const points = values
99-
.map((value, index) => {
100-
const x = (index / (values.length - 1)) * 100;
101-
const y = 30 - (value / maximum) * 26;
102-
return `${x},${y}`;
103-
})
104-
.join(" ");
105-
return html`
106-
<figure class="debug-overlay__graph debug-overlay__graph--${kind}">
107-
<figcaption>
108-
<span>${label}</span>
109-
<span class="mono">${formatValue(current)}</span>
110-
</figcaption>
111-
<svg viewBox="0 0 100 32" preserveAspectRatio="none" aria-hidden="true">
112-
<polygon points="0,32 ${points} 100,32"></polygon>
113-
<polyline points=${points}></polyline>
114-
</svg>
115-
</figure>
116-
`;
104+
return samples;
105+
}
106+
107+
function formatPercent(value: number): string {
108+
return `${Math.round(value * 100)}%`;
109+
}
110+
111+
function formatMegabytes(bytes: number): string {
112+
return t("debug.overlay.memoryMb", { value: String(Math.round(bytes / 1_048_576)) });
113+
}
114+
115+
function formatDelayMs(value: number): string {
116+
return formatDurationCompact(value) ?? t("common.na");
117117
}
118118

119119
function renderStatus(
120120
status: DebugOverlayStatusSnapshot,
121-
history: readonly DebugOverlayStatusSnapshot[],
121+
history: readonly DebugOverlayStatusSample[],
122122
): TemplateResult {
123123
const eventLoop = status.eventLoop;
124-
const utilization =
124+
const reasons = eventLoop?.reasons ?? [];
125+
const cpuDegraded = reasons.includes("cpu") || reasons.includes("event_loop_utilization");
126+
const delayDegraded = reasons.includes("event_loop_delay");
127+
const loopSub =
125128
typeof eventLoop?.utilization === "number"
126-
? `${Math.round(eventLoop.utilization * 100)}%`
127-
: t("common.na");
128-
const delay =
129-
typeof eventLoop?.delayP99Ms === "number"
130-
? formatDurationCompact(eventLoop.delayP99Ms)
131-
: t("common.na");
132-
const maxDelay =
129+
? t("debug.overlay.loopShort", { value: formatPercent(eventLoop.utilization) })
130+
: "";
131+
const heapSub =
132+
typeof status.processMemory?.heapUsedBytes === "number"
133+
? t("debug.overlay.heapShort", { value: formatMegabytes(status.processMemory.heapUsedBytes) })
134+
: "";
135+
const maxSub =
133136
typeof eventLoop?.delayMaxMs === "number"
134-
? formatDurationCompact(eventLoop.delayMaxMs)
135-
: t("common.na");
137+
? t("debug.overlay.maxShort", { value: formatDelayMs(eventLoop.delayMaxMs) })
138+
: "";
136139
return html`
137-
${history.length >= 2
138-
? html`<div class="debug-overlay__graphs">
139-
${renderSparkline(
140-
history,
141-
"cpu",
142-
t("debug.overlay.cpu"),
143-
(sample) => sample.eventLoop?.cpuCoreRatio,
144-
(value) => `${Math.round(value * 100)}%`,
145-
)}
146-
${renderSparkline(
147-
history,
148-
"memory",
149-
t("debug.overlay.memory"),
150-
(sample) => sample.processMemory?.rssBytes,
151-
(value) =>
152-
t("debug.overlay.memoryMb", { value: String(Math.round(value / 1_048_576)) }),
153-
)}
154-
${renderSparkline(
155-
history,
156-
"delay",
157-
t("debug.overlay.delayP99"),
158-
(sample) => sample.eventLoop?.delayP99Ms,
159-
formatDurationCompact,
160-
)}
140+
<div class="debug-overlay__vitals">
141+
<openclaw-debug-sparkline
142+
class="debug-overlay__vital debug-overlay__vital--cpu"
143+
data-degraded=${cpuDegraded ? "" : nothing}
144+
.label=${t("debug.overlay.cpu")}
145+
.sub=${loopSub}
146+
.samples=${collectSamples(history, (sample) => sample.eventLoop?.cpuCoreRatio)}
147+
.format=${formatPercent}
148+
.floorMax=${1}
149+
></openclaw-debug-sparkline>
150+
<openclaw-debug-sparkline
151+
class="debug-overlay__vital debug-overlay__vital--memory"
152+
.label=${t("debug.overlay.memory")}
153+
.sub=${heapSub}
154+
.samples=${collectSamples(history, (sample) => sample.processMemory?.rssBytes)}
155+
.format=${formatMegabytes}
156+
autorange
157+
></openclaw-debug-sparkline>
158+
<openclaw-debug-sparkline
159+
class="debug-overlay__vital debug-overlay__vital--delay"
160+
data-degraded=${delayDegraded ? "" : nothing}
161+
.label=${t("debug.overlay.delayP99")}
162+
.sub=${maxSub}
163+
.samples=${collectSamples(history, (sample) => sample.eventLoop?.delayP99Ms)}
164+
.format=${formatDelayMs}
165+
.floorMax=${20}
166+
></openclaw-debug-sparkline>
167+
</div>
168+
${typeof status.uptimeMs === "number"
169+
? html`<div class="debug-overlay__vitals-footer mono">
170+
${t("debug.overlay.uptime")} ${formatDurationHuman(status.uptimeMs)}
161171
</div>`
162172
: nothing}
163-
<dl class="debug-overlay__metrics">
164-
<div>
165-
<dt>${t("debug.overlay.utilization")}</dt>
166-
<dd class="mono">${utilization}</dd>
167-
</div>
168-
<div>
169-
<dt>${t("debug.overlay.delayP99")}</dt>
170-
<dd class="mono">${delay}</dd>
171-
</div>
172-
<div>
173-
<dt>${t("debug.overlay.delayMax")}</dt>
174-
<dd class="mono">${maxDelay}</dd>
175-
</div>
176-
${typeof status.uptimeMs === "number"
177-
? html`<div>
178-
<dt>${t("debug.overlay.uptime")}</dt>
179-
<dd class="mono">${formatDurationHuman(status.uptimeMs)}</dd>
180-
</div>`
181-
: ""}
182-
</dl>
183173
`;
184174
}
185175

‎ui/src/pages/debug/debug-overlay.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import "../../styles/debug.css";
99
import {
1010
DEBUG_OVERLAY_SECTIONS,
1111
type DebugOverlaySectionDescriptor,
12+
type DebugOverlayStatusSample,
1213
type DebugOverlayStatusSnapshot,
1314
} from "./debug-overlay-sections.ts";
1415

@@ -30,7 +31,7 @@ export class DebugOverlay extends OpenClawLightDomElement {
3031
private requestController: AbortController | null = null;
3132
private requestActive = false;
3233
private requestGeneration = 0;
33-
private statusHistory: DebugOverlayStatusSnapshot[] = [];
34+
private statusHistory: DebugOverlayStatusSample[] = [];
3435
private eventLogSource: ApplicationContext["gateway"] | null = null;
3536
private unsubscribeEventLog: (() => void) | null = null;
3637
private readonly polling = new PollController(
@@ -143,7 +144,7 @@ export class DebugOverlay extends OpenClawLightDomElement {
143144
const snapshot = state.value as DebugOverlayStatusSnapshot;
144145
this.statusHistory = [
145146
...this.statusHistory.slice(-(DEBUG_OVERLAY_HISTORY_LIMIT - 1)),
146-
snapshot,
147+
{ at: Date.now(), status: snapshot },
147148
];
148149
}
149150
const next = new Map(this.sections);

0 commit comments

Comments
 (0)