Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ResourceTelemetryDiagnostics.tsx

1,439 lines51.4 KB

1import { thrownErrorMessage } from "@t3tools/client-runtime/errors";
2import { ProcessSignalActions } from "./ProcessSignalActions";
3import { AuthEnvironmentMaintainScope } from "@t3tools/contracts";
4import { RefreshIcon } from "~/components/ui/refresh-icon";
5import {
6 ActivityIcon,
7 AlertTriangleIcon,
8 BatteryIcon,
9 CpuIcon,
10 DatabaseIcon,
11 GaugeIcon,
12 HardDriveIcon,
13 MemoryStickIcon,
14 ChevronDownIcon,
15 ChevronRightIcon,
16} from "lucide-react";
17import type {
18 BackgroundBooleanState,
19 EnvironmentId,
20 ResourceAttributionEntry,
21 ResourceTelemetryAggregate,
22 ResourceTelemetryHistoryBucket,
23 ResourceTelemetryIoSemantics,
24 ResourceTelemetryProcess,
25 ResourceTelemetryProcessCategory,
26 ResourceTelemetryProcessSummary,
27 ResourceTelemetrySourceHealth,
28 ResourceTelemetrySourceStatus,
29 ServerProcessSignal,
30} from "@t3tools/contracts";
31import * as DateTime from "effect/DateTime";
32import * as Option from "effect/Option";
33import { RegistryContext } from "@effect/atom-react";
34import { useContext, useRef, useState, type ReactNode } from "react";
35import {
36 isAtomCommandInterrupted,
37 squashAtomCommandFailure,
38} from "@t3tools/client-runtime/state/runtime";
39import { msg, T, useGT, useMessages, Var } from "gt-react";
40import { m, type MessageResolver } from "../../i18n/messages";
41​
42import {
43 useResourceTelemetry,
44 useResourceTelemetryHistory,
45} from "../../lib/resourceTelemetryState";
46import { cn } from "../../lib/utils";
47import { formatBytes } from "../../lib/formatBytes";
48import { ensureLocalApi } from "../../localApi";
49import { serverEnvironment } from "../../state/server";
50import { readEnvironmentScope, useEnvironmentScope } from "../../state/session";
51import { useAtomCommand } from "../../state/use-atom-command";
52import { useRelativeTimeState } from "../../hooks/useRelativeTimeState";
53import { Button } from "../ui/button";
54import { ScrollArea } from "../ui/scroll-area";
55import { Toggle, ToggleGroup } from "../ui/toggle-group";
56import { toastManager } from "../ui/toast";
57import {
58 formatCpuTime,
59 formatSamplingStatus,
60 processIdentityKey,
61 resourceHistoryBarHeight,
62 resourceHistoryCpuScaleMax,
63 shouldShowResourceMonitorRetry,
64 visibleResourceTelemetryProcesses,
65} from "./ResourceTelemetryDiagnostics.logic";
66import { SettingsSection } from "./settingsLayout";
67import { SharedTooltipTrigger } from "../ui/shared-tooltip";
68​
69const HISTORY_WINDOWS = [
70 { label: "5m", windowMs: 5 * 60_000, bucketMs: 15_000 },
71 { label: "15m", windowMs: 15 * 60_000, bucketMs: 30_000 },
72 { label: "30m", windowMs: 30 * 60_000, bucketMs: 60_000 },
73 { label: "1h", windowMs: 60 * 60_000, bucketMs: 2 * 60_000 },
74] as const;
75​
76function formatRate(value: number): string {
77 return `${formatBytes(value)}/s`;
79​
80function formatDurationMicros(value: number): string {
81 if (value < 1_000) return `${Math.round(value)} µs`;
82 if (value < 1_000_000) return `${(value / 1_000).toFixed(2).replace(/\.0+$/, "")} ms`;
83 return `${(value / 1_000_000).toFixed(2).replace(/\.0+$/, "")} s`;
85​
86function formatProcessName(process: Pick<ResourceTelemetryProcess, "command" | "name">): string {
87 if (process.name.trim()) return process.name;
88 const firstToken = process.command.trim().split(/\s+/)[0] ?? process.command;
89 const normalized = firstToken.replace(/^['"]|['"]$/g, "");
90 return normalized.split(/[\\/]/).findLast((segment) => segment.length > 0) ?? normalized;
92​
93function categoryLabel(
94 category: ResourceTelemetryProcessCategory,
95 resolve: MessageResolver = m,
96): string {
97 switch (category) {
98 case "server":
99 return resolve(msg("Server"));
100 case "server-child":
101 return resolve(msg("Backend child"));
102 case "provider-root":
103 return resolve(msg("Provider"));
104 case "terminal-root":
105 return resolve(msg("Terminal"));
106 case "electron-main":
107 return resolve(msg("Electron main"));
108 case "electron-renderer":
109 return resolve(msg("Renderer"));
110 case "electron-gpu":
111 return "GPU";
112 case "electron-utility":
113 return resolve(msg("Electron utility"));
114 case "resource-monitor":
115 return resolve(msg("Monitor"));
116 case "unknown-t3":
117 return resolve(msg("T3 process"));
118 }
120​
121function categoryDotClass(category: ResourceTelemetryProcessCategory): string {
122 if (category === "resource-monitor") return "bg-warning";
123 if (category.startsWith("electron-")) return "bg-info";
124 if (category === "server") return "bg-violet-500";
125 return "bg-success";
127​
128function ioSemanticsLabel(
129 semantics: ResourceTelemetryIoSemantics,
130 resolve: MessageResolver = m,
131): string {
132 switch (semantics) {
133 case "storage":
134 return resolve(msg("Storage bytes"));
135 case "logical":
136 return resolve(msg("Logical bytes"));
137 case "all-io":
138 return resolve(msg("All I/O bytes"));
139 case "unavailable":
140 return resolve(msg("Unavailable"));
141 }
143​
144function booleanStateLabel(
145 value: BackgroundBooleanState,
146 labels: { readonly true: string; readonly false: string },
147 resolve: MessageResolver = m,
148): string {
149 if (value === "true") return labels.true;
150 if (value === "false") return labels.false;
151 return resolve(msg("Unknown"));
153​
154function sourceStatusTone(status: ResourceTelemetrySourceStatus): "default" | "warning" | "danger" {
155 if (status === "healthy") return "default";
156 if (status === "starting" || status === "degraded") return "warning";
157 return "danger";
159​
160function SourceStatusBadge({
161 label,
162 status,
163 presentation,
164}: {
165 label: string;
166 status: ResourceTelemetrySourceStatus;
167 presentation?:
168 | {
169 readonly label: string;
170 readonly tone: "neutral";
171 }
172 | undefined;
173}) {
174 const tone = presentation?.tone ?? sourceStatusTone(status);
175 return (
176 <span
177 className={cn(
178 "inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-3xs font-semibold uppercase tracking-widest",
179 tone === "neutral" && "border-border/70 bg-muted/45 text-muted-foreground",
180 tone === "default" && "border-success/25 bg-success/10 text-success-foreground",
181 tone === "warning" && "border-warning/30 bg-warning/10 text-warning-foreground",
182 tone === "danger" && "border-destructive/30 bg-destructive/10 text-destructive",
183 )}
184 >
185 <span
186 className={cn(
187 "size-1.5 rounded-full",
188 tone === "neutral" && "bg-muted-foreground/55",
189 tone === "default" && "bg-success",
190 tone === "warning" && "bg-warning",
191 tone === "danger" && "bg-destructive",
192 )}
193 />
194 {label} {presentation?.label ?? status}
195 </span>
196 );
198​
199function LastSampleLabel({ sampledAt }: { sampledAt: DateTime.Utc | null }) {
200 const relative = useRelativeTimeState(sampledAt ? DateTime.formatIso(sampledAt) : null);
201 if (relative.status !== "relative") {
202 return (
203 <span className="text-2xs text-muted-foreground/55">
204 <T>Waiting for sample</T>
205 </span>
206 );
207 }
208 return (
209 <span className="text-2xs text-muted-foreground/60">
210 {relative.suffix ? (
211 <T context="the time is an elapsed time such as 5m">
212 Updated{" "}
213 <span className="font-mono tabular-nums">
214 <Var>{relative.value}</Var>
215 </span>{" "}
216 ago
217 </T>
218 ) : (
219 <T>
220 Updated{" "}
221 <span className="font-mono tabular-nums">
222 <Var>{relative.value}</Var>
223 </span>
224 </T>
225 )}
226 </span>
227 );
229​
230function IconStat({
231 icon,
232 label,
233 value,
234 detail,
235 tone = "default",
236}: {
237 icon: ReactNode;
238 label: string;
239 value: string;
240 detail?: string | undefined;
241 tone?: "default" | "warning" | "danger";
242}) {
243 return (
244 <div className="group min-w-0 px-4 py-4 sm:px-5">
245 <div className="flex items-center gap-2 text-3xs font-semibold uppercase tracking-widest text-muted-foreground/70">
246 <span className="text-muted-foreground/55 transition-colors group-hover:text-foreground/65">
247 {icon}
248 </span>
249 <span className="truncate">{label}</span>
250 </div>
251 <div
252 className={cn(
253 "mt-2.5 truncate font-mono text-2xl font-semibold tracking-tighter tabular-nums text-foreground",
254 tone === "warning" && "text-warning-foreground",
255 tone === "danger" && "text-destructive",
256 )}
257 >
258 {value}
259 </div>
260 {detail ? (
261 <div className="mt-1.5 truncate text-3xs text-muted-foreground/60">{detail}</div>
262 ) : null}
263 </div>
264 );
266​
267function AggregateCard({
268 label,
269 accentClass,
270 aggregate,
271}: {
272 label: string;
273 accentClass: string;
274 aggregate: ResourceTelemetryAggregate;
275}) {
276 const gt = useGT();
277 return (
278 <div className="relative overflow-hidden border-t border-border/60 px-4 py-4 first:border-t-0 md:border-t-0 md:border-l md:first:border-l-0 sm:px-5">
279 <span className={cn("absolute inset-x-5 top-0 h-0.5 rounded-full opacity-75", accentClass)} />
280 <div className="flex items-center justify-between gap-3">
281 <div className="text-3xs font-semibold uppercase tracking-widest text-muted-foreground/75">
282 {label}
283 </div>
284 <div className="rounded-md bg-muted/55 px-1.5 py-0.5 font-mono text-3xs tabular-nums text-muted-foreground/70">
285 {aggregate.processCount} {aggregate.processCount === 1 ? "process" : "processes"}
286 </div>
287 </div>
288 <div className="mt-3.5 grid grid-cols-2 gap-x-4 gap-y-2.5">
289 <MetricPair label={gt("CPU")} value={`${aggregate.currentCpuPercent.toFixed(1)}%`} />
290 <MetricPair label={gt("Memory")} value={formatBytes(aggregate.currentRssBytes)} />
291 <MetricPair label={gt("Read")} value={formatRate(aggregate.ioReadBytesPerSecond)} />
292 <MetricPair label={gt("Write")} value={formatRate(aggregate.ioWriteBytesPerSecond)} />
293 </div>
294 </div>
295 );
297​
298function MetricPair({ label, value }: { label: string; value: string }) {
299 return (
300 <div className="min-w-0">
301 <div className="text-3xs font-semibold uppercase tracking-widest text-muted-foreground/45">
302 {label}
303 </div>
304 <div className="truncate font-mono text-xs font-medium tabular-nums text-foreground/90">
305 {value}
306 </div>
307 </div>
308 );
310​
311function HealthSource({ label, health }: { label: string; health: ResourceTelemetrySourceHealth }) {
312 const gt = useGT();
313 const expectedInBrowser =
314 health.status === "unavailable" &&
315 Option.exists(health.lastError, (error) => error.includes("'web' mode"));
316 return (
317 <div className="flex items-start justify-between gap-4 border-t border-border/50 py-3 first:border-t-0">
318 <div className="min-w-0">
319 <div className="text-sm font-medium text-foreground">{label}</div>
320 <div className="mt-1 text-2xs leading-relaxed text-muted-foreground/65">
321 {expectedInBrowser
322 ? gt("Available when this page runs inside the desktop app.")
323 : Option.match(health.lastError, {
324 onNone: () => gt("No reported errors"),
325 onSome: (error) => error,
326 })}
327 </div>
328 </div>
329 <SourceStatusBadge
330 label=""
331 status={health.status}
332 presentation={
333 expectedInBrowser
334 ? {
335 label: gt("Desktop only"),
336 tone: "neutral",
337 }
338 : undefined
339 }
340 />
341 </div>
342 );
344​
345function DetailRow({
346 label,
347 value,
348 valueClassName,
349}: {
350 label: string;
351 value: ReactNode;
352 valueClassName?: string | undefined;
353}) {
354 return (
355 <div className="flex items-center justify-between gap-4 border-t border-border/50 py-2.5 first:border-t-0">
356 <span className="text-2xs text-muted-foreground/75">{label}</span>
357 <span
358 className={cn(
359 "min-w-0 truncate text-right font-mono text-2xs tabular-nums text-foreground/85",
360 valueClassName,
361 )}
362 >
363 {value}
364 </span>
365 </div>
366 );
368​
369function HistoryWindowSelector({
370 selectedWindowMs,
371 onSelect,
372}: {
373 selectedWindowMs: number;
374 onSelect: (windowMs: number) => void;
375}) {
376 const gt = useGT();
377 return (
378 <ToggleGroup
379 aria-label={gt("Resource history period")}
380 variant="segmented"
381 value={[String(selectedWindowMs)]}
382 onValueChange={(next) => {
383 const selected = HISTORY_WINDOWS.find((option) => String(option.windowMs) === next[0]);
384 if (selected) onSelect(selected.windowMs);
385 }}
386 >
387 {HISTORY_WINDOWS.map((option) => (
388 <Toggle key={option.windowMs} value={String(option.windowMs)}>
389 {option.label}
390 </Toggle>
391 ))}
392 </ToggleGroup>
393 );
395​
396function ResourceHistoryChart({
397 buckets,
398}: {
399 buckets: ReadonlyArray<ResourceTelemetryHistoryBucket>;
400}) {
401 const gt = useGT();
402 const maxCpu = resourceHistoryCpuScaleMax(buckets);
403 const maxIo = Math.max(1, ...buckets.map((bucket) => bucket.ioReadBytes + bucket.ioWriteBytes));
404​
405 return (
406 <div className="border-t border-border/60 px-4 py-4 sm:px-5">
407 <div className="mb-3 flex flex-wrap items-center gap-x-4 gap-y-1 text-3xs text-muted-foreground/65">
408 <span className="inline-flex items-center gap-1.5">
409 <span className="h-1.5 w-3 rounded-full bg-foreground/70" /> <T>CPU average</T>
410 </span>
411 <span className="inline-flex items-center gap-1.5">
412 <span className="h-1.5 w-3 rounded-full bg-info/70" /> <T>I/O reads</T>
413 </span>
414 <span className="inline-flex items-center gap-1.5">
415 <span className="h-1.5 w-3 rounded-full bg-warning/80" /> <T>I/O writes</T>
416 </span>
417 </div>
418 <div className="flex h-32 items-end gap-1 overflow-hidden rounded-lg border border-border/40 bg-muted/8 px-2 pt-3 pb-2">
419 {buckets.map((bucket) => {
420 const cpuHeight = resourceHistoryBarHeight({
421 value: bucket.avgCpuPercent,
422 max: maxCpu,
423 minimumVisiblePercent: 2,
424 });
425 const readHeight = resourceHistoryBarHeight({
426 value: bucket.ioReadBytes,
427 max: maxIo,
428 minimumVisiblePercent: 1,
429 });
430 const writeHeight = resourceHistoryBarHeight({
431 value: bucket.ioWriteBytes,
432 max: maxIo,
433 minimumVisiblePercent: 1,
434 });
435 return (
436 <SharedTooltipTrigger
437 key={DateTime.formatIso(bucket.startedAt)}
438 render={
439 <div className="grid h-full min-w-1 flex-1 grid-cols-3 items-end gap-px">
440 <span
441 className="block rounded-t-sm bg-foreground/65"
442 style={{ height: `${cpuHeight}%` }}
443 />
444 <span
445 className="block rounded-t-sm bg-info/70"
446 style={{ height: `${readHeight}%` }}
447 />
448 <span
449 className="block rounded-t-sm bg-warning/80"
450 style={{ height: `${writeHeight}%` }}
451 />
452 </div>
453 }
454 label={
455 <>
456 <div className="space-y-0.5">
457 <div>
458 {gt("CPU avg {percent}%", { percent: bucket.avgCpuPercent.toFixed(1) })}
459 </div>
460 <div>
461 {gt("CPU peak {percent}%", { percent: bucket.maxCpuPercent.toFixed(1) })}
462 </div>
463 <div>{gt("Read {bytes}", { bytes: formatBytes(bucket.ioReadBytes) })}</div>
464 <div>{gt("Write {bytes}", { bytes: formatBytes(bucket.ioWriteBytes) })}</div>
465 </div>
466 </>
467 }
468 className="text-left"
469 />
470 );
471 })}
472 </div>
473 </div>
474 );
476​
477function ProcessTreeName({
478 process,
479 collapsed,
480 onToggle,
481}: {
482 process: ResourceTelemetryProcess;
483 collapsed: boolean;
484 onToggle: (process: ResourceTelemetryProcess) => void;
485}) {
486 const gt = useGT();
487 const name = formatProcessName(process);
488 const hasChildren = process.childPids.length > 0;
489 return (
490 <div
491 className="grid min-w-0 grid-cols-[1.25rem_0.375rem_minmax(0,1fr)] items-center gap-2"
492 style={{ paddingLeft: `${Math.min(process.depth, 7) * 10}px` }}
493 >
494 {hasChildren ? (
495 <Button
496 size="icon-micro"
497 variant="ghost-muted"
498 onClick={() => onToggle(process)}
499 aria-label={collapsed ? gt("Expand {name}", { name }) : gt("Collapse {name}", { name })}
500 >
501 {collapsed ? (
502 <ChevronRightIcon className="size-3.5" />
503 ) : (
504 <ChevronDownIcon className="size-3.5" />
505 )}
506 </Button>
507 ) : (
508 <span className="size-5" aria-hidden />
509 )}
510 <span className={cn("size-1.5 rounded-full", categoryDotClass(process.category))} />
511 <SharedTooltipTrigger
512 render={<span className="min-w-0 truncate font-medium text-foreground">{name}</span>}
513 label={process.command || process.name}
514 variant="code"
515 />
516 </div>
517 );
519​
520function canSignalProcess(process: ResourceTelemetryProcess): boolean {
521 return (
522 process.category === "server-child" ||
523 process.category === "provider-root" ||
524 process.category === "terminal-root"
525 );
527​
528function ProcessActions({
529 process,
530 canMaintainEnvironment,
531 signalingKeys,
532 onSignal,
533}: {
534 process: ResourceTelemetryProcess;
535 canMaintainEnvironment: boolean;
536 signalingKeys: ReadonlySet<string>;
537 onSignal: (process: ResourceTelemetryProcess, signal: ServerProcessSignal) => void;
538}) {
539 if (!canSignalProcess(process)) {
540 return <span className="text-3xs text-muted-foreground/35">-</span>;
541 }
542 const isSignaling = signalingKeys.has(processIdentityKey(process));
543 return (
544 <ProcessSignalActions
545 disabled={!canMaintainEnvironment || isSignaling}
546 onSignal={(signal) => onSignal(process, signal)}
547 />
548 );
550​
551function ProcessTable({
552 processes,
553 canMaintainEnvironment,
554 signalingKeys,
555 onSignal,
556}: {
557 processes: ReadonlyArray<ResourceTelemetryProcess>;
558 canMaintainEnvironment: boolean;
559 signalingKeys: ReadonlySet<string>;
560 onSignal: (process: ResourceTelemetryProcess, signal: ServerProcessSignal) => void;
561}) {
562 const messages = useMessages();
563 const [collapsed, setCollapsed] = useState<ReadonlySet<string>>(() => new Set());
564 const visible = visibleResourceTelemetryProcesses(processes, collapsed);
565 const toggle = (process: ResourceTelemetryProcess) => {
566 const identityKey = processIdentityKey(process);
567 setCollapsed((current) => {
568 const next = new Set(current);
569 if (next.has(identityKey)) {
570 next.delete(identityKey);
571 } else {
572 next.add(identityKey);
573 }
574 return next;
575 });
576 };
577​
578 return (
579 <div className="border-t border-border/60">
580 <ScrollArea
581 chainVerticalScroll
582 scrollFade
583 hideScrollbars
584 className="max-h-[min(68vh,48rem)] w-full max-w-full"
585 >
586 <table className="w-full min-w-[1320px] table-fixed text-left text-xs">
587 <colgroup>
588 <col className="w-[20%]" />
589 <col className="w-[10%]" />
590 <col className="w-[7%]" />
591 <col className="w-[8%]" />
592 <col className="w-[9%]" />
593 <col className="w-[9%]" />
594 <col className="w-[9%]" />
595 <col className="w-[10%]" />
596 <col className="w-[8%]" />
597 <col className="w-[6%]" />
598 <col className="w-[4%]" />
599 </colgroup>
600 <thead className="sticky top-0 z-10 border-b border-border/60 bg-card text-3xs uppercase tracking-widest text-muted-foreground/65">
601 <tr>
602 <th className="px-4 py-2 font-semibold sm:pl-5">
603 <T>Process</T>
604 </th>
605 <th className="px-3 py-2 font-semibold">
606 <T>Category</T>
607 </th>
608 <th className="px-3 py-2 text-right font-semibold">
609 <T>CPU</T>
610 </th>
611 <th className="px-3 py-2 text-right font-semibold">
612 <T>CPU Time</T>
613 </th>
614 <th className="px-3 py-2 text-right font-semibold">
615 <T>Memory</T>
616 </th>
617 <th className="px-3 py-2 text-right font-semibold">
618 <T>Read/s</T>
619 </th>
620 <th className="px-3 py-2 text-right font-semibold">
621 <T>Write/s</T>
622 </th>
623 <th className="px-3 py-2 text-right font-semibold">
624 <T>Read Total</T>
625 </th>
626 <th className="px-3 py-2 text-right font-semibold">
627 <T>Write Total</T>
628 </th>
629 <th className="px-3 py-2 text-right font-semibold">
630 <T>PID</T>
631 </th>
632 <th className="px-2 py-2 text-right font-semibold sm:pr-4">
633 <T>Kill</T>
634 </th>
635 </tr>
636 </thead>
637 <tbody className="divide-y divide-border/50">
638 {visible.length === 0 ? (
639 <tr>
640 <td colSpan={11} className="px-4 py-5 text-xs text-muted-foreground sm:px-5">
641 <T>Waiting for the native process monitor.</T>
642 </td>
643 </tr>
644 ) : null}
645 {visible.map((process) => (
646 <tr key={processIdentityKey(process)} className="hover:bg-muted/20">
647 <td className="px-4 py-2 sm:pl-5">
648 <ProcessTreeName
649 process={process}
650 collapsed={collapsed.has(processIdentityKey(process))}
651 onToggle={toggle}
652 />
653 </td>
654 <td className="truncate px-3 py-2 text-2xs text-muted-foreground">
655 {categoryLabel(process.category, messages)}
656 </td>
657 <td className="px-3 py-2 text-right font-mono tabular-nums">
658 {process.cpuPercent.toFixed(1)}%
659 </td>
660 <td className="px-3 py-2 text-right font-mono tabular-nums">
661 {formatCpuTime(process.cpuTimeMs / 1_000, messages)}
662 </td>
663 <td className="px-3 py-2 text-right font-mono tabular-nums">
664 {formatBytes(process.residentBytes)}
665 </td>
666 <td className="px-3 py-2 text-right font-mono tabular-nums text-info-foreground">
667 {formatRate(process.ioReadBytesPerSecond)}
668 </td>
669 <td className="px-3 py-2 text-right font-mono tabular-nums text-warning-foreground">
670 {formatRate(process.ioWriteBytesPerSecond)}
671 </td>
672 <td className="px-3 py-2 text-right font-mono tabular-nums text-muted-foreground">
673 {formatBytes(process.ioReadBytes)}
674 </td>
675 <td className="px-3 py-2 text-right font-mono tabular-nums text-muted-foreground">
676 <SharedTooltipTrigger
677 render={<span>{formatBytes(process.ioWriteBytes)}</span>}
678 label={ioSemanticsLabel(process.ioSemantics, messages)}
679 />
680 </td>
681 <td className="px-3 py-2 text-right font-mono tabular-nums text-muted-foreground">
682 {process.identity.pid}
683 </td>
684 <td className="px-2 py-2 text-right sm:pr-4">
685 <ProcessActions
686 process={process}
687 canMaintainEnvironment={canMaintainEnvironment}
688 signalingKeys={signalingKeys}
689 onSignal={onSignal}
690 />
691 </td>
692 </tr>
693 ))}
694 </tbody>
695 </table>
696 </ScrollArea>
697 </div>
698 );
700​
701function HistoryProcessTable({
702 processes,
703}: {
704 processes: ReadonlyArray<ResourceTelemetryProcessSummary>;
705}) {
706 const messages = useMessages();
707 return (
708 <div className="border-t border-border/60">
709 <ScrollArea
710 chainVerticalScroll
711 scrollFade
712 hideScrollbars
713 className="max-h-[28rem] w-full max-w-full"
714 >
715 <table className="w-full min-w-[1020px] table-fixed text-left text-xs">
716 <colgroup>
717 <col className="w-[24%]" />
718 <col className="w-[11%]" />
719 <col className="w-[10%]" />
720 <col className="w-[10%]" />
721 <col className="w-[11%]" />
722 <col className="w-[11%]" />
723 <col className="w-[11%]" />
724 <col className="w-[7%]" />
725 <col className="w-[5%]" />
726 </colgroup>
727 <thead className="sticky top-0 z-10 border-b border-border/60 bg-card text-3xs uppercase tracking-widest text-muted-foreground/65">
728 <tr>
729 <th className="px-4 py-2 font-semibold sm:pl-5">
730 <T>Process</T>
731 </th>
732 <th className="px-3 py-2 font-semibold">
733 <T>Category</T>
734 </th>
735 <th className="px-3 py-2 text-right font-semibold">
736 <T>CPU Time</T>
737 </th>
738 <th className="px-3 py-2 text-right font-semibold">
739 <T>Peak CPU</T>
740 </th>
741 <th className="px-3 py-2 text-right font-semibold">
742 <T>Peak Mem</T>
743 </th>
744 <th className="px-3 py-2 text-right font-semibold">
745 <T>Read</T>
746 </th>
747 <th className="px-3 py-2 text-right font-semibold">
748 <T>Write</T>
749 </th>
750 <th className="px-3 py-2 text-right font-semibold">
751 <T>Samples</T>
752 </th>
753 <th className="px-3 py-2 text-right font-semibold sm:pr-5">
754 <T>PID</T>
755 </th>
756 </tr>
757 </thead>
758 <tbody className="divide-y divide-border/50">
759 {processes.length === 0 ? (
760 <tr>
761 <td colSpan={9} className="px-4 py-5 text-xs text-muted-foreground sm:px-5">
762 <T>No retained process samples in this window.</T>
763 </td>
764 </tr>
765 ) : null}
766 {processes.map((process) => (
767 <tr key={processIdentityKey(process)} className="hover:bg-muted/20">
768 <td className="px-4 py-2 sm:pl-5">
769 <SharedTooltipTrigger
770 render={
771 <span className="block truncate font-medium text-foreground">
772 {process.name || process.command}
773 </span>
774 }
775 label={process.command || process.name}
776 variant="code"
777 />
778 </td>
779 <td className="truncate px-3 py-2 text-2xs text-muted-foreground">
780 {categoryLabel(process.category, messages)}
781 </td>
782 <td className="px-3 py-2 text-right font-mono tabular-nums">
783 {formatCpuTime(process.cpuTimeMs / 1_000, messages)}
784 </td>
785 <td className="px-3 py-2 text-right font-mono tabular-nums">
786 {process.maxCpuPercent.toFixed(1)}%
787 </td>
788 <td className="px-3 py-2 text-right font-mono tabular-nums">
789 {formatBytes(process.peakRssBytes)}
790 </td>
791 <td className="px-3 py-2 text-right font-mono tabular-nums text-info-foreground">
792 {formatBytes(process.ioReadBytes)}
793 </td>
794 <td className="px-3 py-2 text-right font-mono tabular-nums text-warning-foreground">
795 {formatBytes(process.ioWriteBytes)}
796 </td>
797 <td className="px-3 py-2 text-right font-mono tabular-nums text-muted-foreground">
798 {process.sampleCount}
799 </td>
800 <td className="px-3 py-2 text-right font-mono tabular-nums text-muted-foreground sm:pr-5">
801 {process.identity.pid}
802 </td>
803 </tr>
804 ))}
805 </tbody>
806 </table>
807 </ScrollArea>
808 </div>
809 );
811​
812function AttributionTable({ entries }: { entries: ReadonlyArray<ResourceAttributionEntry> }) {
813 return (
814 <div className="overflow-x-auto border-t border-border/60">
815 <table className="w-full min-w-[720px] table-fixed text-left text-xs">
816 <colgroup>
817 <col className="w-[22%]" />
818 <col className="w-[28%]" />
819 <col className="w-[14%]" />
820 <col className="w-[14%]" />
821 <col className="w-[10%]" />
822 <col className="w-[12%]" />
823 </colgroup>
824 <thead className="border-b border-border/60 text-3xs uppercase tracking-widest text-muted-foreground/65">
825 <tr>
826 <th className="px-4 py-2 font-semibold sm:pl-5">
827 <T>Component</T>
828 </th>
829 <th className="px-3 py-2 font-semibold">
830 <T>Operation</T>
831 </th>
832 <th className="px-3 py-2 text-right font-semibold">
833 <T>Logical Read</T>
834 </th>
835 <th className="px-3 py-2 text-right font-semibold">
836 <T>Logical Write</T>
837 </th>
838 <th className="px-3 py-2 text-right font-semibold">
839 <T>Count</T>
840 </th>
841 <th className="px-3 py-2 text-right font-semibold sm:pr-5">
842 <T>Time</T>
843 </th>
844 </tr>
845 </thead>
846 <tbody className="divide-y divide-border/50">
847 {entries.length === 0 ? (
848 <tr>
849 <td colSpan={6} className="px-4 py-5 text-xs text-muted-foreground sm:px-5">
850 <T>No instrumented application I/O has been recorded yet.</T>
851 </td>
852 </tr>
853 ) : null}
854 {entries.map((entry) => (
855 <tr key={`${entry.component}:${entry.operation}`} className="hover:bg-muted/20">
856 <td className="truncate px-4 py-2 font-medium text-foreground sm:pl-5">
857 {entry.component}
858 </td>
859 <td className="truncate px-3 py-2 text-muted-foreground">{entry.operation}</td>
860 <td className="px-3 py-2 text-right font-mono tabular-nums text-info-foreground">
861 {formatBytes(entry.logicalReadBytes)}
862 </td>
863 <td className="px-3 py-2 text-right font-mono tabular-nums text-warning-foreground">
864 {formatBytes(entry.logicalWriteBytes)}
865 </td>
866 <td className="px-3 py-2 text-right font-mono tabular-nums">{entry.count}</td>
867 <td className="px-3 py-2 text-right font-mono tabular-nums text-muted-foreground sm:pr-5">
868 {(entry.durationMs / 1_000).toFixed(2).replace(/\.0+$/, "")}s
869 </td>
870 </tr>
871 ))}
872 </tbody>
873 </table>
874 </div>
875 );
877​
878export function ResourceTelemetryDiagnostics({
879 environmentId,
880}: {
881 environmentId: EnvironmentId | null;
882}) {
883 // Pending signals and retries belong to one environment, so a switch starts fresh.
884 return (
885 <ResourceTelemetryDiagnosticsBody key={environmentId ?? ""} environmentId={environmentId} />
886 );
888​
889function ResourceTelemetryDiagnosticsBody({
890 environmentId,
891}: {
892 environmentId: EnvironmentId | null;
893}) {
894 const messages = useMessages();
895 const gt = useGT();
896 const registry = useContext(RegistryContext);
897 const [windowMs, setWindowMs] = useState(15 * 60_000);
898 const selectedWindow =
899 HISTORY_WINDOWS.find((option) => option.windowMs === windowMs) ?? HISTORY_WINDOWS[1];
900 const canMaintainEnvironment = useEnvironmentScope(environmentId, AuthEnvironmentMaintainScope);
901 const telemetry = useResourceTelemetry(environmentId);
902 const retryTelemetry = telemetry.retry;
903 const history = useResourceTelemetryHistory(
904 {
905 windowMs: selectedWindow.windowMs,
906 bucketMs: selectedWindow.bucketMs,
907 },
908 environmentId,
909 );
910 const signalServerProcess = useAtomCommand(serverEnvironment.signalProcess, {
911 reportFailure: false,
912 });
913 const [signalingKeys, setSignalingKeys] = useState<ReadonlySet<string>>(() => new Set());
914 const signalingKeysRef = useRef<ReadonlySet<string>>(new Set());
915 const [isRetrying, setIsRetrying] = useState(false);
916 const snapshot = telemetry.data;
917 const allT3 = snapshot?.groups.allT3;
918​
919 const signalProcess = async (process: ResourceTelemetryProcess, signal: ServerProcessSignal) => {
920 const targetEnvironmentId = environmentId;
921 if (
922 targetEnvironmentId === null ||
923 !readEnvironmentScope(targetEnvironmentId, AuthEnvironmentMaintainScope)
924 )
925 return;
926 const identityKey = processIdentityKey(process);
927 if (signalingKeysRef.current.has(identityKey)) return;
928 const nextSignalingKeys = new Set(signalingKeysRef.current).add(identityKey);
929 signalingKeysRef.current = nextSignalingKeys;
930 setSignalingKeys(nextSignalingKeys);
931 const clearSignaling = () => {
932 const next = new Set(signalingKeysRef.current);
933 next.delete(identityKey);
934 signalingKeysRef.current = next;
935 setSignalingKeys(next);
936 };
937​
938 if (signal === "SIGKILL") {
939 let confirmed = false;
940 try {
941 confirmed = await ensureLocalApi().dialogs.confirm(
942 gt("Send SIGKILL to process {pid}? This cannot be handled by the process.", {
943 pid: process.identity.pid,
944 }),
945 { variant: "destructive" },
946 );
947 } catch (error) {
948 clearSignaling();
949 toastManager.add({
950 type: "error",
951 title: gt("Could not confirm signal"),
952 description:
953 error instanceof Error
954 ? (thrownErrorMessage(error, m) ?? error.message)
955 : gt("Failed to send {signal}.", { signal }),
956 });
957 return;
958 }
959 if (!confirmed) {
960 clearSignaling();
961 return;
962 }
963 }
964 if (!readEnvironmentScope(targetEnvironmentId, AuthEnvironmentMaintainScope)) {
965 clearSignaling();
966 return;
967 }
968 void signalServerProcess({
969 environmentId: targetEnvironmentId,
970 input: {
971 pid: process.identity.pid,
972 startTimeMs: process.identity.startTimeMs,
973 signal,
974 },
975 })
976 .then((result) => {
977 if (result._tag === "Failure") {
978 if (isAtomCommandInterrupted(result)) return;
979 throw squashAtomCommandFailure(result);
980 }
981 if (result.value.signaled) return;
982 toastManager.add({
983 type: "error",
984 title: gt("Could not send {signal}", { signal }),
985 description: Option.getOrElse(result.value.message, () =>
986 gt("Failed to send {signal} to process {pid}.", {
987 signal,
988 pid: process.identity.pid,
989 }),
990 ),
991 });
992 })
993 .catch((error: unknown) => {
994 toastManager.add({
995 type: "error",
996 title: gt("Could not send {signal}", { signal }),
997 description:
998 error instanceof Error
999 ? (thrownErrorMessage(error, m) ?? error.message)
1000 : gt("Failed to send {signal}.", { signal }),
1001 });
1002 })
1003 .finally(() => {
1004 clearSignaling();
1005 });
1006 };
1007​
1008 const retryCollector = () => {
1009 if (
1010 environmentId === null ||
1011 !readEnvironmentScope(environmentId, AuthEnvironmentMaintainScope)
1013 return;
1014 setIsRetrying(true);
1015 void retryTelemetry()
1016 .then(() => {
1017 // The user can pick another window while the retry runs; refreshing every window
1018 // re-reads the one on screen and only invalidates the rest.
1019 for (const option of HISTORY_WINDOWS) {
1020 registry.refresh(
1021 serverEnvironment.resourceTelemetryHistory({
1022 environmentId,
1023 input: { windowMs: option.windowMs, bucketMs: option.bucketMs },
1024 }),
1025 );
1027 })
1028 .catch((error: unknown) => {
1029 toastManager.add({
1030 type: "error",
1031 title: gt("Could not restart resource monitor"),
1032 description:
1033 error instanceof Error
1034 ? (thrownErrorMessage(error, m) ?? error.message)
1035 : gt("The resource monitor retry failed."),
1036 });
1037 })
1038 .finally(() => {
1039 setIsRetrying(false);
1040 });
1041 };
1042​
1043 const speedLimit = snapshot ? Option.getOrNull(snapshot.speedLimitPercent) : null;
1044 const collectorNeedsRetry = shouldShowResourceMonitorRetry({
1045 nativeStatus: snapshot?.health.native.status ?? null,
1046 error: telemetry.error,
1047 });
1048 const hasHostPowerSignal =
1049 snapshot !== null &&
1050 (snapshot.power.onBattery !== "unknown" ||
1051 snapshot.power.lowPowerMode !== "unknown" ||
1052 snapshot.power.idle !== "unknown" ||
1053 snapshot.power.locked !== "unknown" ||
1054 snapshot.power.thermalState !== "unknown");
1055​
1056 return (
1057 <>
1058 <SettingsSection
1059 title={gt("Resource monitor")}
1060 icon={<ActivityIcon className="size-4 text-muted-foreground" />}
1061 headerAction={
1062 <div className="flex items-center gap-2">
1063 {snapshot ? (
1064 <SourceStatusBadge label={gt("Native")} status={snapshot.health.native.status} />
1065 ) : null}
1066 <LastSampleLabel sampledAt={snapshot?.readAt ?? null} />
1067 <SharedTooltipTrigger
1068 render={
1069 <Button
1070 size="icon-micro"
1071 variant="ghost"
1072 disabled={telemetry.isPending}
1073 onClick={telemetry.refresh}
1074 aria-label={gt("Refresh resource telemetry")}
1076 <RefreshIcon size="xs" refreshing={telemetry.isPending} />
1077 </Button>
1079 label={
1080 <>
1081 <T>Refresh telemetry snapshot</T>
1082 </>
1084 />
1085 </div>
1088 <div className="overflow-hidden rounded-[inherit]">
1089 <div className="flex flex-col gap-3 border-b border-border/60 bg-linear-to-r from-muted/45 via-muted/20 to-transparent px-4 py-4 sm:flex-row sm:items-center sm:justify-between sm:px-5">
1090 <div>
1091 <div className="text-3xs font-semibold uppercase tracking-widest text-muted-foreground/70">
1092 <T>T3 system footprint</T>
1093 </div>
1094 <p className="mt-1 max-w-xl text-xs leading-relaxed text-muted-foreground">
1095 <T>
1096 Live native counters for the server, providers, terminals, desktop processes, and
1097 the monitor itself.
1098 </T>
1099 </p>
1100 </div>
1101 <div className="flex items-center gap-2 text-3xs text-muted-foreground/65">
1102 <span
1103 className={cn(
1104 "size-1.5 rounded-full",
1105 snapshot && snapshot.sampleIntervalMs > 0
1106 ? "bg-success"
1107 : "bg-muted-foreground/55",
1108 )}
1109 />
1110 {snapshot
1111 ? formatSamplingStatus(snapshot.sampleIntervalMs, messages)
1112 : gt("Sampling every ...")}
1113 </div>
1114 </div>
1115 <div className="grid grid-cols-2 divide-x divide-y divide-border/55 md:grid-cols-3">
1116 <IconStat
1117 icon={<CpuIcon className="size-3.5" />}
1118 label={gt("Current CPU")}
1119 value={allT3 ? `${allT3.currentCpuPercent.toFixed(1)}%` : "..."}
1120 detail={
1121 allT3
1122 ? gt("{time} observed CPU time", {
1123 time: formatCpuTime(allT3.cpuTimeMs / 1_000, messages),
1124 })
1125 : undefined
1127 />
1128 <IconStat
1129 icon={<MemoryStickIcon className="size-3.5" />}
1130 label={gt("Resident memory")}
1131 value={allT3 ? formatBytes(allT3.currentRssBytes) : "..."}
1132 detail={
1133 allT3
1134 ? gt("{bytes} combined process peaks", { bytes: formatBytes(allT3.peakRssBytes) })
1135 : undefined
1137 />
1138 <IconStat
1139 icon={<ActivityIcon className="size-3.5" />}
1140 label={gt("Process count")}
1141 value={allT3 ? String(allT3.processCount) : "..."}
1142 detail={
1143 allT3
1144 ? gt("{processStarts} starts · {processExits} exits", {
1145 processStarts: allT3.processStarts,
1146 processExits: allT3.processExits,
1147 })
1148 : undefined
1150 />
1151 <IconStat
1152 icon={<HardDriveIcon className="size-3.5" />}
1153 label={gt("Read throughput")}
1154 value={allT3 ? formatRate(allT3.ioReadBytesPerSecond) : "..."}
1155 detail={allT3 ? `${formatBytes(allT3.ioReadBytes)} observed` : undefined}
1156 />
1157 <IconStat
1158 icon={<DatabaseIcon className="size-3.5" />}
1159 label={gt("Write throughput")}
1160 value={allT3 ? formatRate(allT3.ioWriteBytesPerSecond) : "..."}
1161 detail={allT3 ? `${formatBytes(allT3.ioWriteBytes)} observed` : undefined}
1162 tone={
1163 allT3 && allT3.ioWriteBytesPerSecond >= 10 * 1_024 * 1_024
1164 ? "danger"
1165 : allT3 && allT3.ioWriteBytesPerSecond >= 1_024 * 1_024
1166 ? "warning"
1167 : "default"
1169 />
1170 <IconStat
1171 icon={<GaugeIcon className="size-3.5" />}
1172 label={gt("CPU speed limit")}
1173 value={
1174 snapshot
1175 ? speedLimit === null
1176 ? gt("Unknown")
1177 : `${speedLimit.toFixed(0)}%`
1178 : "..."
1180 detail={
1181 snapshot
1182 ? gt("{thermalState} thermal state", {
1183 thermalState: snapshot.power.thermalState,
1184 })
1185 : undefined
1187 tone={speedLimit !== null && speedLimit < 80 ? "warning" : "default"}
1188 />
1189 </div>
1190 {telemetry.error ? (
1191 <div className="flex items-start gap-2 border-t border-destructive/20 bg-destructive/5 px-4 py-3 text-xs text-destructive sm:px-5">
1192 <AlertTriangleIcon className="size-3.5 h-lh shrink-0" />
1193 <span>{telemetry.error}</span>
1194 </div>
1195 ) : null}
1196 {snapshot ? (
1197 <div className="grid border-t border-border/60 bg-muted/10 md:grid-cols-3">
1198 <AggregateCard
1199 label={gt("Backend + agents")}
1200 accentClass="bg-success/80"
1201 aggregate={snapshot.groups.backend}
1202 />
1203 <AggregateCard
1204 label={gt("Desktop")}
1205 accentClass="bg-info/80"
1206 aggregate={snapshot.groups.electron}
1207 />
1208 <AggregateCard
1209 label={gt("Monitor overhead")}
1210 accentClass="bg-warning/80"
1211 aggregate={snapshot.groups.monitor}
1212 />
1213 </div>
1214 ) : null}
1215 </div>
1216 </SettingsSection>
1217​
1218 <SettingsSection
1219 title={gt("Host & collection")}
1220 icon={<GaugeIcon className="size-4 text-muted-foreground" />}
1221 headerAction={
1222 collectorNeedsRetry ? (
1223 <Button size="xs" variant="outline" disabled={isRetrying} onClick={retryCollector}>
1224 <RefreshIcon size="xs" refreshing={isRetrying} />
1225 <T>Retry monitor</T>
1226 </Button>
1227 ) : null
1230 <div className="grid overflow-hidden rounded-[inherit] md:grid-cols-2 md:divide-x md:divide-border/60">
1231 <div className="px-4 py-4 sm:px-5">
1232 <div className="mb-3 flex items-center gap-2 text-3xs font-semibold uppercase tracking-widest text-muted-foreground/70">
1233 <span className="flex size-6 items-center justify-center rounded-md bg-muted/60">
1234 <BatteryIcon className="size-3.5" />
1235 </span>
1236 <T>Host state</T>
1237 </div>
1238 {hasHostPowerSignal && snapshot ? (
1239 <>
1240 <DetailRow
1241 label={gt("Power source")}
1242 value={booleanStateLabel(
1243 snapshot.power.onBattery,
1244 { true: gt("Battery"), false: gt("External power") },
1245 messages,
1246 )}
1247 />
1248 <DetailRow
1249 label={gt("Low power mode")}
1250 value={booleanStateLabel(
1251 snapshot.power.lowPowerMode,
1252 { true: gt("Enabled"), false: gt("Disabled") },
1253 messages,
1254 )}
1255 />
1256 <DetailRow
1257 label={gt("Idle")}
1258 value={`${booleanStateLabel(
1259 snapshot.power.idle,
1261 true: gt("Idle", { $context: "host power state" }),
1262 false: gt("Active", { $context: "host power state" }),
1263 },
1264 messages,
1265 )}${
1266 snapshot.power.idleSeconds === null
1267 ? ""
1268 : ` · ${Math.round(snapshot.power.idleSeconds)}s`
1269 }`}
1270 />
1271 <DetailRow
1272 label={gt("Session")}
1273 value={
1274 snapshot.power.suspended
1275 ? gt("Suspended")
1276 : booleanStateLabel(
1277 snapshot.power.locked,
1278 { true: gt("Locked"), false: gt("Unlocked") },
1279 messages,
1282 />
1283 <DetailRow
1284 label={gt("Thermal")}
1285 value={snapshot.power.thermalState}
1286 valueClassName={
1287 snapshot.power.thermalState === "serious" ||
1288 snapshot.power.thermalState === "critical"
1289 ? "text-destructive"
1290 : undefined
1292 />
1293 </>
1294 ) : (
1295 <div className="rounded-xl border border-dashed border-border/70 bg-muted/20 px-4 py-5">
1296 <div className="text-sm font-medium text-foreground">
1297 <T>Desktop host signals not connected</T>
1298 </div>
1299 <p className="mt-1.5 max-w-sm text-2xs leading-relaxed text-muted-foreground/70">
1300 <T>
1301 Power, idle, lock, and thermal state are supplied by the desktop host. Process
1302 telemetry remains fully active in this browser session.
1303 </T>
1304 </p>
1305 </div>
1306 )}
1307 </div>
1308 <div className="border-t border-border/60 px-4 py-4 md:border-t-0 sm:px-5">
1309 <div className="mb-3 flex items-center gap-2 text-3xs font-semibold uppercase tracking-widest text-muted-foreground/70">
1310 <span className="flex size-6 items-center justify-center rounded-md bg-muted/60">
1311 <GaugeIcon className="size-3.5" />
1312 </span>
1313 <T>Collection health</T>
1314 </div>
1315 {snapshot ? (
1316 <>
1317 <HealthSource
1318 label={gt("Native process monitor")}
1319 health={snapshot.health.native}
1320 />
1321 <HealthSource
1322 label={gt("Electron main process")}
1323 health={snapshot.health.desktop}
1324 />
1325 <DetailRow
1326 label={gt("Collection time")}
1327 value={formatDurationMicros(snapshot.health.collectionDurationMicros)}
1328 />
1329 <DetailRow
1330 label={gt("Process scan")}
1331 value={`${snapshot.health.retainedProcessCount}/${snapshot.health.scannedProcessCount} retained`}
1332 />
1333 <DetailRow
1334 label={gt("Inaccessible")}
1335 value={String(snapshot.health.inaccessibleProcessCount)}
1336 valueClassName={
1337 snapshot.health.inaccessibleProcessCount > 0
1338 ? "text-warning-foreground"
1339 : undefined
1341 />
1342 <DetailRow
1343 label={gt("Sidecar")}
1344 value={Option.match(snapshot.health.sidecarVersion, {
1345 onNone: () => gt("Unavailable"),
1346 onSome: (version) =>
1347 `${version}${Option.match(snapshot.health.sidecarPid, {
1348 onNone: () => "",
1349 onSome: (pid) => ` · PID ${pid}`,
1350 })}`,
1351 })}
1352 />
1353 <DetailRow label={gt("Restarts")} value={String(snapshot.health.restartCount)} />
1354 </>
1355 ) : (
1356 <div className="py-4 text-xs text-muted-foreground">
1357 <T>Waiting for collector health.</T>
1358 </div>
1359 )}
1360 </div>
1361 </div>
1362 </SettingsSection>
1363​
1364 <SettingsSection
1365 title={gt("Resource timeline")}
1366 icon={<HardDriveIcon className="size-4 text-muted-foreground" />}
1367 headerAction={
1368 <div className="flex items-center gap-2">
1369 <HistoryWindowSelector selectedWindowMs={windowMs} onSelect={setWindowMs} />
1370 <Button
1371 size="icon-micro"
1372 variant="ghost"
1373 disabled={history.isPending}
1374 onClick={history.refresh}
1375 aria-label={gt("Refresh resource history")}
1377 <RefreshIcon size="xs" refreshing={history.isPending} />
1378 </Button>
1379 </div>
1382 <div className="overflow-hidden rounded-[inherit]">
1383 {history.error ? (
1384 <div className="flex items-start gap-2 border-b border-destructive/20 bg-destructive/5 px-4 py-3 text-xs text-destructive sm:px-5">
1385 <AlertTriangleIcon className="size-3.5 h-lh shrink-0" />
1386 <span>{history.error}</span>
1387 </div>
1388 ) : null}
1389 <ResourceHistoryChart buckets={history.data?.buckets ?? []} />
1390 <HistoryProcessTable processes={history.data?.topProcesses ?? []} />
1391 </div>
1392 </SettingsSection>
1393​
1394 <SettingsSection
1395 title={gt("Live process tree")}
1396 icon={<CpuIcon className="size-4 text-muted-foreground" />}
1397 headerAction={
1398 snapshot ? (
1399 <span className="text-3xs text-muted-foreground/55">
1400 <T>
1401 Identity: <span className="font-mono">PID + start time</span>
1402 </T>
1403 </span>
1404 ) : null
1407 <div className="overflow-hidden rounded-[inherit]">
1408 <ProcessTable
1409 processes={snapshot?.processes ?? []}
1410 canMaintainEnvironment={canMaintainEnvironment}
1411 signalingKeys={signalingKeys}
1412 onSignal={signalProcess}
1413 />
1414 </div>
1415 </SettingsSection>
1416​
1417 <SettingsSection
1418 title={gt("Instrumented application I/O")}
1419 icon={<DatabaseIcon className="size-4 text-muted-foreground" />}
1420 headerAction={
1421 <span className="text-3xs text-muted-foreground/55">
1422 <T>Logical bytes by operation</T>
1423 </span>
1426 <div className="overflow-hidden rounded-[inherit]">
1427 <div className="bg-muted/15 px-4 py-3 text-2xs leading-relaxed text-muted-foreground sm:px-5">
1428 <T>
1429 Native counters identify which process is reading or writing. These application-level
1430 counters identify known T3 operations so process spikes can be correlated with
1431 specific persistence and logging paths.
1432 </T>
1433 </div>
1434 <AttributionTable entries={snapshot?.attribution.entries ?? []} />
1435 </div>
1436 </SettingsSection>
1437 </>
1438 );