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

ResourceTelemetryDiagnostics.tsx

1,434 lines51.5 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, plural, part } 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 {gt`${plural(
286 { count: aggregate.processCount },
287 {
288 one: part`${{ count: aggregate.processCount }} process`,
289 other: part`${{ count: aggregate.processCount }} processes`,
290 },
291 )}`}
292 </div>
293 </div>
294 <div className="mt-3.5 grid grid-cols-2 gap-x-4 gap-y-2.5">
295 <MetricPair label={gt`CPU`} value={`${aggregate.currentCpuPercent.toFixed(1)}%`} />
296 <MetricPair label={gt`Memory`} value={formatBytes(aggregate.currentRssBytes)} />
297 <MetricPair label={gt`Read`} value={formatRate(aggregate.ioReadBytesPerSecond)} />
298 <MetricPair label={gt`Write`} value={formatRate(aggregate.ioWriteBytesPerSecond)} />
299 </div>
300 </div>
301 );
303​
304function MetricPair({ label, value }: { label: string; value: string }) {
305 return (
306 <div className="min-w-0">
307 <div className="text-3xs font-semibold uppercase tracking-widest text-muted-foreground/45">
308 {label}
309 </div>
310 <div className="truncate font-mono text-xs font-medium tabular-nums text-foreground/90">
311 {value}
312 </div>
313 </div>
314 );
316​
317function HealthSource({ label, health }: { label: string; health: ResourceTelemetrySourceHealth }) {
318 const gt = useGT();
319 const expectedInBrowser =
320 health.status === "unavailable" &&
321 Option.exists(health.lastError, (error) => error.includes("'web' mode"));
322 return (
323 <div className="flex items-start justify-between gap-4 border-t border-border/50 py-3 first:border-t-0">
324 <div className="min-w-0">
325 <div className="text-sm font-medium text-foreground">{label}</div>
326 <div className="mt-1 text-2xs leading-relaxed text-muted-foreground/65">
327 {expectedInBrowser
328 ? gt`Available when this page runs inside the desktop app.`
329 : Option.match(health.lastError, {
330 onNone: () => gt`No reported errors`,
331 onSome: (error) => error,
332 })}
333 </div>
334 </div>
335 <SourceStatusBadge
336 label=""
337 status={health.status}
338 presentation={
339 expectedInBrowser
340 ? {
341 label: gt`Desktop only`,
342 tone: "neutral",
343 }
344 : undefined
345 }
346 />
347 </div>
348 );
350​
351function DetailRow({
352 label,
353 value,
354 valueClassName,
355}: {
356 label: string;
357 value: ReactNode;
358 valueClassName?: string | undefined;
359}) {
360 return (
361 <div className="flex items-center justify-between gap-4 border-t border-border/50 py-2.5 first:border-t-0">
362 <span className="text-2xs text-muted-foreground/75">{label}</span>
363 <span
364 className={cn(
365 "min-w-0 truncate text-right font-mono text-2xs tabular-nums text-foreground/85",
366 valueClassName,
367 )}
368 >
369 {value}
370 </span>
371 </div>
372 );
374​
375function HistoryWindowSelector({
376 selectedWindowMs,
377 onSelect,
378}: {
379 selectedWindowMs: number;
380 onSelect: (windowMs: number) => void;
381}) {
382 const gt = useGT();
383 return (
384 <ToggleGroup
385 aria-label={gt`Resource history period`}
386 variant="segmented"
387 value={[String(selectedWindowMs)]}
388 onValueChange={(next) => {
389 const selected = HISTORY_WINDOWS.find((option) => String(option.windowMs) === next[0]);
390 if (selected) onSelect(selected.windowMs);
391 }}
392 >
393 {HISTORY_WINDOWS.map((option) => (
394 <Toggle key={option.windowMs} value={String(option.windowMs)}>
395 {option.label}
396 </Toggle>
397 ))}
398 </ToggleGroup>
399 );
401​
402function ResourceHistoryChart({
403 buckets,
404}: {
405 buckets: ReadonlyArray<ResourceTelemetryHistoryBucket>;
406}) {
407 const gt = useGT();
408 const maxCpu = resourceHistoryCpuScaleMax(buckets);
409 const maxIo = Math.max(1, ...buckets.map((bucket) => bucket.ioReadBytes + bucket.ioWriteBytes));
410​
411 return (
412 <div className="border-t border-border/60 px-4 py-4 sm:px-5">
413 <div className="mb-3 flex flex-wrap items-center gap-x-4 gap-y-1 text-3xs text-muted-foreground/65">
414 <span className="inline-flex items-center gap-1.5">
415 <span className="h-1.5 w-3 rounded-full bg-foreground/70" /> <T>CPU average</T>
416 </span>
417 <span className="inline-flex items-center gap-1.5">
418 <span className="h-1.5 w-3 rounded-full bg-info/70" /> <T>I/O reads</T>
419 </span>
420 <span className="inline-flex items-center gap-1.5">
421 <span className="h-1.5 w-3 rounded-full bg-warning/80" /> <T>I/O writes</T>
422 </span>
423 </div>
424 <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">
425 {buckets.map((bucket) => {
426 const cpuHeight = resourceHistoryBarHeight({
427 value: bucket.avgCpuPercent,
428 max: maxCpu,
429 minimumVisiblePercent: 2,
430 });
431 const readHeight = resourceHistoryBarHeight({
432 value: bucket.ioReadBytes,
433 max: maxIo,
434 minimumVisiblePercent: 1,
435 });
436 const writeHeight = resourceHistoryBarHeight({
437 value: bucket.ioWriteBytes,
438 max: maxIo,
439 minimumVisiblePercent: 1,
440 });
441 return (
442 <SharedTooltipTrigger
443 key={DateTime.formatIso(bucket.startedAt)}
444 render={
445 <div className="grid h-full min-w-1 flex-1 grid-cols-3 items-end gap-px">
446 <span
447 className="block rounded-t-sm bg-foreground/65"
448 style={{ height: `${cpuHeight}%` }}
449 />
450 <span
451 className="block rounded-t-sm bg-info/70"
452 style={{ height: `${readHeight}%` }}
453 />
454 <span
455 className="block rounded-t-sm bg-warning/80"
456 style={{ height: `${writeHeight}%` }}
457 />
458 </div>
459 }
460 label={
461 <>
462 <div className="space-y-0.5">
463 <div>{gt`CPU avg ${{ percent: bucket.avgCpuPercent.toFixed(1) }}%`}</div>
464 <div>{gt`CPU peak ${{ percent: bucket.maxCpuPercent.toFixed(1) }}%`}</div>
465 <div>{gt`Read ${{ bytes: formatBytes(bucket.ioReadBytes) }}`}</div>
466 <div>{gt`Write ${{ bytes: formatBytes(bucket.ioWriteBytes) }}`}</div>
467 </div>
468 </>
469 }
470 className="text-left"
471 />
472 );
473 })}
474 </div>
475 </div>
476 );
478​
479function ProcessTreeName({
480 process,
481 collapsed,
482 onToggle,
483}: {
484 process: ResourceTelemetryProcess;
485 collapsed: boolean;
486 onToggle: (process: ResourceTelemetryProcess) => void;
487}) {
488 const gt = useGT();
489 const name = formatProcessName(process);
490 const hasChildren = process.childPids.length > 0;
491 return (
492 <div
493 className="grid min-w-0 grid-cols-[1.25rem_0.375rem_minmax(0,1fr)] items-center gap-2"
494 style={{ paddingLeft: `${Math.min(process.depth, 7) * 10}px` }}
495 >
496 {hasChildren ? (
497 <Button
498 size="icon-micro"
499 variant="ghost-muted"
500 onClick={() => onToggle(process)}
501 aria-label={collapsed ? gt`Expand ${{ name }}` : gt`Collapse ${{ name }}`}
502 >
503 {collapsed ? (
504 <ChevronRightIcon className="size-3.5" />
505 ) : (
506 <ChevronDownIcon className="size-3.5" />
507 )}
508 </Button>
509 ) : (
510 <span className="size-5" aria-hidden />
511 )}
512 <span className={cn("size-1.5 rounded-full", categoryDotClass(process.category))} />
513 <SharedTooltipTrigger
514 render={<span className="min-w-0 truncate font-medium text-foreground">{name}</span>}
515 label={process.command || process.name}
516 variant="code"
517 />
518 </div>
519 );
521​
522function canSignalProcess(process: ResourceTelemetryProcess): boolean {
523 return (
524 process.category === "server-child" ||
525 process.category === "provider-root" ||
526 process.category === "terminal-root"
527 );
529​
530function ProcessActions({
531 process,
532 canMaintainEnvironment,
533 signalingKeys,
534 onSignal,
535}: {
536 process: ResourceTelemetryProcess;
537 canMaintainEnvironment: boolean;
538 signalingKeys: ReadonlySet<string>;
539 onSignal: (process: ResourceTelemetryProcess, signal: ServerProcessSignal) => void;
540}) {
541 if (!canSignalProcess(process)) {
542 return <span className="text-3xs text-muted-foreground/35">-</span>;
543 }
544 const isSignaling = signalingKeys.has(processIdentityKey(process));
545 return (
546 <ProcessSignalActions
547 disabled={!canMaintainEnvironment || isSignaling}
548 onSignal={(signal) => onSignal(process, signal)}
549 />
550 );
552​
553function ProcessTable({
554 processes,
555 canMaintainEnvironment,
556 signalingKeys,
557 onSignal,
558}: {
559 processes: ReadonlyArray<ResourceTelemetryProcess>;
560 canMaintainEnvironment: boolean;
561 signalingKeys: ReadonlySet<string>;
562 onSignal: (process: ResourceTelemetryProcess, signal: ServerProcessSignal) => void;
563}) {
564 const messages = useMessages();
565 const [collapsed, setCollapsed] = useState<ReadonlySet<string>>(() => new Set());
566 const visible = visibleResourceTelemetryProcesses(processes, collapsed);
567 const toggle = (process: ResourceTelemetryProcess) => {
568 const identityKey = processIdentityKey(process);
569 setCollapsed((current) => {
570 const next = new Set(current);
571 if (next.has(identityKey)) {
572 next.delete(identityKey);
573 } else {
574 next.add(identityKey);
575 }
576 return next;
577 });
578 };
579​
580 return (
581 <div className="border-t border-border/60">
582 <ScrollArea
583 chainVerticalScroll
584 scrollFade
585 hideScrollbars
586 className="max-h-[min(68vh,48rem)] w-full max-w-full"
587 >
588 <table className="w-full min-w-[1320px] table-fixed text-left text-xs">
589 <colgroup>
590 <col className="w-[20%]" />
591 <col className="w-[10%]" />
592 <col className="w-[7%]" />
593 <col className="w-[8%]" />
594 <col className="w-[9%]" />
595 <col className="w-[9%]" />
596 <col className="w-[9%]" />
597 <col className="w-[10%]" />
598 <col className="w-[8%]" />
599 <col className="w-[6%]" />
600 <col className="w-[4%]" />
601 </colgroup>
602 <thead className="sticky top-0 z-10 border-b border-border/60 bg-card text-3xs uppercase tracking-widest text-muted-foreground/65">
603 <tr>
604 <th className="px-4 py-2 font-semibold sm:pl-5">
605 <T>Process</T>
606 </th>
607 <th className="px-3 py-2 font-semibold">
608 <T>Category</T>
609 </th>
610 <th className="px-3 py-2 text-right font-semibold">
611 <T>CPU</T>
612 </th>
613 <th className="px-3 py-2 text-right font-semibold">
614 <T>CPU Time</T>
615 </th>
616 <th className="px-3 py-2 text-right font-semibold">
617 <T>Memory</T>
618 </th>
619 <th className="px-3 py-2 text-right font-semibold">
620 <T>Read/s</T>
621 </th>
622 <th className="px-3 py-2 text-right font-semibold">
623 <T>Write/s</T>
624 </th>
625 <th className="px-3 py-2 text-right font-semibold">
626 <T>Read Total</T>
627 </th>
628 <th className="px-3 py-2 text-right font-semibold">
629 <T>Write Total</T>
630 </th>
631 <th className="px-3 py-2 text-right font-semibold">
632 <T>PID</T>
633 </th>
634 <th className="px-2 py-2 text-right font-semibold sm:pr-4">
635 <T>Kill</T>
636 </th>
637 </tr>
638 </thead>
639 <tbody className="divide-y divide-border/50">
640 {visible.length === 0 ? (
641 <tr>
642 <td colSpan={11} className="px-4 py-5 text-xs text-muted-foreground sm:px-5">
643 <T>Waiting for the native process monitor.</T>
644 </td>
645 </tr>
646 ) : null}
647 {visible.map((process) => (
648 <tr key={processIdentityKey(process)} className="hover:bg-muted/20">
649 <td className="px-4 py-2 sm:pl-5">
650 <ProcessTreeName
651 process={process}
652 collapsed={collapsed.has(processIdentityKey(process))}
653 onToggle={toggle}
654 />
655 </td>
656 <td className="truncate px-3 py-2 text-2xs text-muted-foreground">
657 {categoryLabel(process.category, messages)}
658 </td>
659 <td className="px-3 py-2 text-right font-mono tabular-nums">
660 {process.cpuPercent.toFixed(1)}%
661 </td>
662 <td className="px-3 py-2 text-right font-mono tabular-nums">
663 {formatCpuTime(process.cpuTimeMs / 1_000, messages)}
664 </td>
665 <td className="px-3 py-2 text-right font-mono tabular-nums">
666 {formatBytes(process.residentBytes)}
667 </td>
668 <td className="px-3 py-2 text-right font-mono tabular-nums text-info-foreground">
669 {formatRate(process.ioReadBytesPerSecond)}
670 </td>
671 <td className="px-3 py-2 text-right font-mono tabular-nums text-warning-foreground">
672 {formatRate(process.ioWriteBytesPerSecond)}
673 </td>
674 <td className="px-3 py-2 text-right font-mono tabular-nums text-muted-foreground">
675 {formatBytes(process.ioReadBytes)}
676 </td>
677 <td className="px-3 py-2 text-right font-mono tabular-nums text-muted-foreground">
678 <SharedTooltipTrigger
679 render={<span>{formatBytes(process.ioWriteBytes)}</span>}
680 label={ioSemanticsLabel(process.ioSemantics, messages)}
681 />
682 </td>
683 <td className="px-3 py-2 text-right font-mono tabular-nums text-muted-foreground">
684 {process.identity.pid}
685 </td>
686 <td className="px-2 py-2 text-right sm:pr-4">
687 <ProcessActions
688 process={process}
689 canMaintainEnvironment={canMaintainEnvironment}
690 signalingKeys={signalingKeys}
691 onSignal={onSignal}
692 />
693 </td>
694 </tr>
695 ))}
696 </tbody>
697 </table>
698 </ScrollArea>
699 </div>
700 );
702​
703function HistoryProcessTable({
704 processes,
705}: {
706 processes: ReadonlyArray<ResourceTelemetryProcessSummary>;
707}) {
708 const messages = useMessages();
709 return (
710 <div className="border-t border-border/60">
711 <ScrollArea
712 chainVerticalScroll
713 scrollFade
714 hideScrollbars
715 className="max-h-[28rem] w-full max-w-full"
716 >
717 <table className="w-full min-w-[1020px] table-fixed text-left text-xs">
718 <colgroup>
719 <col className="w-[24%]" />
720 <col className="w-[11%]" />
721 <col className="w-[10%]" />
722 <col className="w-[10%]" />
723 <col className="w-[11%]" />
724 <col className="w-[11%]" />
725 <col className="w-[11%]" />
726 <col className="w-[7%]" />
727 <col className="w-[5%]" />
728 </colgroup>
729 <thead className="sticky top-0 z-10 border-b border-border/60 bg-card text-3xs uppercase tracking-widest text-muted-foreground/65">
730 <tr>
731 <th className="px-4 py-2 font-semibold sm:pl-5">
732 <T>Process</T>
733 </th>
734 <th className="px-3 py-2 font-semibold">
735 <T>Category</T>
736 </th>
737 <th className="px-3 py-2 text-right font-semibold">
738 <T>CPU Time</T>
739 </th>
740 <th className="px-3 py-2 text-right font-semibold">
741 <T>Peak CPU</T>
742 </th>
743 <th className="px-3 py-2 text-right font-semibold">
744 <T>Peak Mem</T>
745 </th>
746 <th className="px-3 py-2 text-right font-semibold">
747 <T>Read</T>
748 </th>
749 <th className="px-3 py-2 text-right font-semibold">
750 <T>Write</T>
751 </th>
752 <th className="px-3 py-2 text-right font-semibold">
753 <T>Samples</T>
754 </th>
755 <th className="px-3 py-2 text-right font-semibold sm:pr-5">
756 <T>PID</T>
757 </th>
758 </tr>
759 </thead>
760 <tbody className="divide-y divide-border/50">
761 {processes.length === 0 ? (
762 <tr>
763 <td colSpan={9} className="px-4 py-5 text-xs text-muted-foreground sm:px-5">
764 <T>No retained process samples in this window.</T>
765 </td>
766 </tr>
767 ) : null}
768 {processes.map((process) => (
769 <tr key={processIdentityKey(process)} className="hover:bg-muted/20">
770 <td className="px-4 py-2 sm:pl-5">
771 <SharedTooltipTrigger
772 render={
773 <span className="block truncate font-medium text-foreground">
774 {process.name || process.command}
775 </span>
776 }
777 label={process.command || process.name}
778 variant="code"
779 />
780 </td>
781 <td className="truncate px-3 py-2 text-2xs text-muted-foreground">
782 {categoryLabel(process.category, messages)}
783 </td>
784 <td className="px-3 py-2 text-right font-mono tabular-nums">
785 {formatCpuTime(process.cpuTimeMs / 1_000, messages)}
786 </td>
787 <td className="px-3 py-2 text-right font-mono tabular-nums">
788 {process.maxCpuPercent.toFixed(1)}%
789 </td>
790 <td className="px-3 py-2 text-right font-mono tabular-nums">
791 {formatBytes(process.peakRssBytes)}
792 </td>
793 <td className="px-3 py-2 text-right font-mono tabular-nums text-info-foreground">
794 {formatBytes(process.ioReadBytes)}
795 </td>
796 <td className="px-3 py-2 text-right font-mono tabular-nums text-warning-foreground">
797 {formatBytes(process.ioWriteBytes)}
798 </td>
799 <td className="px-3 py-2 text-right font-mono tabular-nums text-muted-foreground">
800 {process.sampleCount}
801 </td>
802 <td className="px-3 py-2 text-right font-mono tabular-nums text-muted-foreground sm:pr-5">
803 {process.identity.pid}
804 </td>
805 </tr>
806 ))}
807 </tbody>
808 </table>
809 </ScrollArea>
810 </div>
811 );
813​
814function AttributionTable({ entries }: { entries: ReadonlyArray<ResourceAttributionEntry> }) {
815 return (
816 <div className="overflow-x-auto border-t border-border/60">
817 <table className="w-full min-w-[720px] table-fixed text-left text-xs">
818 <colgroup>
819 <col className="w-[22%]" />
820 <col className="w-[28%]" />
821 <col className="w-[14%]" />
822 <col className="w-[14%]" />
823 <col className="w-[10%]" />
824 <col className="w-[12%]" />
825 </colgroup>
826 <thead className="border-b border-border/60 text-3xs uppercase tracking-widest text-muted-foreground/65">
827 <tr>
828 <th className="px-4 py-2 font-semibold sm:pl-5">
829 <T>Component</T>
830 </th>
831 <th className="px-3 py-2 font-semibold">
832 <T>Operation</T>
833 </th>
834 <th className="px-3 py-2 text-right font-semibold">
835 <T>Logical Read</T>
836 </th>
837 <th className="px-3 py-2 text-right font-semibold">
838 <T>Logical Write</T>
839 </th>
840 <th className="px-3 py-2 text-right font-semibold">
841 <T>Count</T>
842 </th>
843 <th className="px-3 py-2 text-right font-semibold sm:pr-5">
844 <T>Time</T>
845 </th>
846 </tr>
847 </thead>
848 <tbody className="divide-y divide-border/50">
849 {entries.length === 0 ? (
850 <tr>
851 <td colSpan={6} className="px-4 py-5 text-xs text-muted-foreground sm:px-5">
852 <T>No instrumented application I/O has been recorded yet.</T>
853 </td>
854 </tr>
855 ) : null}
856 {entries.map((entry) => (
857 <tr key={`${entry.component}:${entry.operation}`} className="hover:bg-muted/20">
858 <td className="truncate px-4 py-2 font-medium text-foreground sm:pl-5">
859 {entry.component}
860 </td>
861 <td className="truncate px-3 py-2 text-muted-foreground">{entry.operation}</td>
862 <td className="px-3 py-2 text-right font-mono tabular-nums text-info-foreground">
863 {formatBytes(entry.logicalReadBytes)}
864 </td>
865 <td className="px-3 py-2 text-right font-mono tabular-nums text-warning-foreground">
866 {formatBytes(entry.logicalWriteBytes)}
867 </td>
868 <td className="px-3 py-2 text-right font-mono tabular-nums">{entry.count}</td>
869 <td className="px-3 py-2 text-right font-mono tabular-nums text-muted-foreground sm:pr-5">
870 {(entry.durationMs / 1_000).toFixed(2).replace(/\.0+$/, "")}s
871 </td>
872 </tr>
873 ))}
874 </tbody>
875 </table>
876 </div>
877 );
879​
880export function ResourceTelemetryDiagnostics({
881 environmentId,
882}: {
883 environmentId: EnvironmentId | null;
884}) {
885 // Pending signals and retries belong to one environment, so a switch starts fresh.
886 return (
887 <ResourceTelemetryDiagnosticsBody key={environmentId ?? ""} environmentId={environmentId} />
888 );
890​
891function ResourceTelemetryDiagnosticsBody({
892 environmentId,
893}: {
894 environmentId: EnvironmentId | null;
895}) {
896 const messages = useMessages();
897 const gt = useGT();
898 const registry = useContext(RegistryContext);
899 const [windowMs, setWindowMs] = useState(15 * 60_000);
900 const selectedWindow =
901 HISTORY_WINDOWS.find((option) => option.windowMs === windowMs) ?? HISTORY_WINDOWS[1];
902 const canMaintainEnvironment = useEnvironmentScope(environmentId, AuthEnvironmentMaintainScope);
903 const telemetry = useResourceTelemetry(environmentId);
904 const retryTelemetry = telemetry.retry;
905 const history = useResourceTelemetryHistory(
906 {
907 windowMs: selectedWindow.windowMs,
908 bucketMs: selectedWindow.bucketMs,
909 },
910 environmentId,
911 );
912 const signalServerProcess = useAtomCommand(serverEnvironment.signalProcess, {
913 reportFailure: false,
914 });
915 const [signalingKeys, setSignalingKeys] = useState<ReadonlySet<string>>(() => new Set());
916 const signalingKeysRef = useRef<ReadonlySet<string>>(new Set());
917 const [isRetrying, setIsRetrying] = useState(false);
918 const snapshot = telemetry.data;
919 const allT3 = snapshot?.groups.allT3;
920​
921 const signalProcess = async (process: ResourceTelemetryProcess, signal: ServerProcessSignal) => {
922 const targetEnvironmentId = environmentId;
923 if (
924 targetEnvironmentId === null ||
925 !readEnvironmentScope(targetEnvironmentId, AuthEnvironmentMaintainScope)
926 )
927 return;
928 const identityKey = processIdentityKey(process);
929 if (signalingKeysRef.current.has(identityKey)) return;
930 const nextSignalingKeys = new Set(signalingKeysRef.current).add(identityKey);
931 signalingKeysRef.current = nextSignalingKeys;
932 setSignalingKeys(nextSignalingKeys);
933 const clearSignaling = () => {
934 const next = new Set(signalingKeysRef.current);
935 next.delete(identityKey);
936 signalingKeysRef.current = next;
937 setSignalingKeys(next);
938 };
939​
940 if (signal === "SIGKILL") {
941 let confirmed = false;
942 try {
943 confirmed = await ensureLocalApi().dialogs.confirm(
944 gt`Send SIGKILL to process ${{ pid: process.identity.pid }}? This cannot be handled by the process.`,
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 }}.`,
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 }}`,
985 description: Option.getOrElse(
986 result.value.message,
987 () => gt`Failed to send ${{ signal }} to process ${{ pid: process.identity.pid }}.`,
988 ),
989 });
990 })
991 .catch((error: unknown) => {
992 toastManager.add({
993 type: "error",
994 title: gt`Could not send ${{ signal }}`,
995 description:
996 error instanceof Error
997 ? (thrownErrorMessage(error, m) ?? error.message)
998 : gt`Failed to send ${{ signal }}.`,
999 });
1000 })
1001 .finally(() => {
1002 clearSignaling();
1003 });
1004 };
1005​
1006 const retryCollector = () => {
1007 if (
1008 environmentId === null ||
1009 !readEnvironmentScope(environmentId, AuthEnvironmentMaintainScope)
1011 return;
1012 setIsRetrying(true);
1013 void retryTelemetry()
1014 .then(() => {
1015 // The user can pick another window while the retry runs; refreshing every window
1016 // re-reads the one on screen and only invalidates the rest.
1017 for (const option of HISTORY_WINDOWS) {
1018 registry.refresh(
1019 serverEnvironment.resourceTelemetryHistory({
1020 environmentId,
1021 input: { windowMs: option.windowMs, bucketMs: option.bucketMs },
1022 }),
1023 );
1025 })
1026 .catch((error: unknown) => {
1027 toastManager.add({
1028 type: "error",
1029 title: gt`Could not restart resource monitor`,
1030 description:
1031 error instanceof Error
1032 ? (thrownErrorMessage(error, m) ?? error.message)
1033 : gt`The resource monitor retry failed.`,
1034 });
1035 })
1036 .finally(() => {
1037 setIsRetrying(false);
1038 });
1039 };
1040​
1041 const speedLimit = snapshot ? Option.getOrNull(snapshot.speedLimitPercent) : null;
1042 const collectorNeedsRetry = shouldShowResourceMonitorRetry({
1043 nativeStatus: snapshot?.health.native.status ?? null,
1044 error: telemetry.error,
1045 });
1046 const hasHostPowerSignal =
1047 snapshot !== null &&
1048 (snapshot.power.onBattery !== "unknown" ||
1049 snapshot.power.lowPowerMode !== "unknown" ||
1050 snapshot.power.idle !== "unknown" ||
1051 snapshot.power.locked !== "unknown" ||
1052 snapshot.power.thermalState !== "unknown");
1053​
1054 return (
1055 <>
1056 <SettingsSection
1057 title={gt`Resource monitor`}
1058 icon={<ActivityIcon className="size-4 text-muted-foreground" />}
1059 headerAction={
1060 <div className="flex items-center gap-2">
1061 {snapshot ? (
1062 <SourceStatusBadge label={gt`Native`} status={snapshot.health.native.status} />
1063 ) : null}
1064 <LastSampleLabel sampledAt={snapshot?.readAt ?? null} />
1065 <SharedTooltipTrigger
1066 render={
1067 <Button
1068 size="icon-micro"
1069 variant="ghost"
1070 disabled={telemetry.isPending}
1071 onClick={telemetry.refresh}
1072 aria-label={gt`Refresh resource telemetry`}
1074 <RefreshIcon size="xs" refreshing={telemetry.isPending} />
1075 </Button>
1077 label={
1078 <>
1079 <T>Refresh telemetry snapshot</T>
1080 </>
1082 />
1083 </div>
1086 <div className="overflow-hidden rounded-[inherit]">
1087 <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">
1088 <div>
1089 <div className="text-3xs font-semibold uppercase tracking-widest text-muted-foreground/70">
1090 <T>T3 system footprint</T>
1091 </div>
1092 <p className="mt-1 max-w-xl text-xs leading-relaxed text-muted-foreground">
1093 <T>
1094 Live native counters for the server, providers, terminals, desktop processes, and
1095 the monitor itself.
1096 </T>
1097 </p>
1098 </div>
1099 <div className="flex items-center gap-2 text-3xs text-muted-foreground/65">
1100 <span
1101 className={cn(
1102 "size-1.5 rounded-full",
1103 snapshot && snapshot.sampleIntervalMs > 0
1104 ? "bg-success"
1105 : "bg-muted-foreground/55",
1106 )}
1107 />
1108 {snapshot
1109 ? formatSamplingStatus(snapshot.sampleIntervalMs, messages)
1110 : gt`Sampling every ...`}
1111 </div>
1112 </div>
1113 <div className="grid grid-cols-2 divide-x divide-y divide-border/55 md:grid-cols-3">
1114 <IconStat
1115 icon={<CpuIcon className="size-3.5" />}
1116 label={gt`Current CPU`}
1117 value={allT3 ? `${allT3.currentCpuPercent.toFixed(1)}%` : "..."}
1118 detail={
1119 allT3
1120 ? gt`${{ time: formatCpuTime(allT3.cpuTimeMs / 1_000, messages) }} observed CPU time`
1121 : undefined
1123 />
1124 <IconStat
1125 icon={<MemoryStickIcon className="size-3.5" />}
1126 label={gt`Resident memory`}
1127 value={allT3 ? formatBytes(allT3.currentRssBytes) : "..."}
1128 detail={
1129 allT3
1130 ? gt`${{ bytes: formatBytes(allT3.peakRssBytes) }} combined process peaks`
1131 : undefined
1133 />
1134 <IconStat
1135 icon={<ActivityIcon className="size-3.5" />}
1136 label={gt`Process count`}
1137 value={allT3 ? String(allT3.processCount) : "..."}
1138 detail={
1139 allT3
1140 ? gt`${plural(
1141 { processStarts: allT3.processStarts },
1143 one: part`${{ processStarts: allT3.processStarts }} start`,
1144 other: part`${{ processStarts: allT3.processStarts }} starts`,
1145 },
1146 )} · ${plural(
1147 { processExits: allT3.processExits },
1149 one: part`${{ processExits: allT3.processExits }} exit`,
1150 other: part`${{ processExits: allT3.processExits }} exits`,
1151 },
1152 )}`
1153 : undefined
1155 />
1156 <IconStat
1157 icon={<HardDriveIcon className="size-3.5" />}
1158 label={gt`Read throughput`}
1159 value={allT3 ? formatRate(allT3.ioReadBytesPerSecond) : "..."}
1160 detail={allT3 ? gt`${{ bytes: formatBytes(allT3.ioReadBytes) }} observed` : undefined}
1161 />
1162 <IconStat
1163 icon={<DatabaseIcon className="size-3.5" />}
1164 label={gt`Write throughput`}
1165 value={allT3 ? formatRate(allT3.ioWriteBytesPerSecond) : "..."}
1166 detail={
1167 allT3 ? gt`${{ bytes: formatBytes(allT3.ioWriteBytes) }} observed` : undefined
1169 tone={
1170 allT3 && allT3.ioWriteBytesPerSecond >= 10 * 1_024 * 1_024
1171 ? "danger"
1172 : allT3 && allT3.ioWriteBytesPerSecond >= 1_024 * 1_024
1173 ? "warning"
1174 : "default"
1176 />
1177 <IconStat
1178 icon={<GaugeIcon className="size-3.5" />}
1179 label={gt`CPU speed limit`}
1180 value={
1181 snapshot ? (speedLimit === null ? gt`Unknown` : `${speedLimit.toFixed(0)}%`) : "..."
1183 detail={
1184 snapshot
1185 ? gt`${{ thermalState: snapshot.power.thermalState }} thermal state`
1186 : undefined
1188 tone={speedLimit !== null && speedLimit < 80 ? "warning" : "default"}
1189 />
1190 </div>
1191 {telemetry.error ? (
1192 <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">
1193 <AlertTriangleIcon className="size-3.5 h-lh shrink-0" />
1194 <span>{telemetry.error}</span>
1195 </div>
1196 ) : null}
1197 {snapshot ? (
1198 <div className="grid border-t border-border/60 bg-muted/10 md:grid-cols-3">
1199 <AggregateCard
1200 label={gt`Backend + agents`}
1201 accentClass="bg-success/80"
1202 aggregate={snapshot.groups.backend}
1203 />
1204 <AggregateCard
1205 label={gt`Desktop`}
1206 accentClass="bg-info/80"
1207 aggregate={snapshot.groups.electron}
1208 />
1209 <AggregateCard
1210 label={gt`Monitor overhead`}
1211 accentClass="bg-warning/80"
1212 aggregate={snapshot.groups.monitor}
1213 />
1214 </div>
1215 ) : null}
1216 </div>
1217 </SettingsSection>
1218​
1219 <SettingsSection
1220 title={gt`Host & collection`}
1221 icon={<GaugeIcon className="size-4 text-muted-foreground" />}
1222 headerAction={
1223 collectorNeedsRetry ? (
1224 <Button size="xs" variant="outline" disabled={isRetrying} onClick={retryCollector}>
1225 <RefreshIcon size="xs" refreshing={isRetrying} />
1226 <T>Retry monitor</T>
1227 </Button>
1228 ) : null
1231 <div className="grid overflow-hidden rounded-[inherit] md:grid-cols-2 md:divide-x md:divide-border/60">
1232 <div className="px-4 py-4 sm:px-5">
1233 <div className="mb-3 flex items-center gap-2 text-3xs font-semibold uppercase tracking-widest text-muted-foreground/70">
1234 <span className="flex size-6 items-center justify-center rounded-md bg-muted/60">
1235 <BatteryIcon className="size-3.5" />
1236 </span>
1237 <T>Host state</T>
1238 </div>
1239 {hasHostPowerSignal && snapshot ? (
1240 <>
1241 <DetailRow
1242 label={gt`Power source`}
1243 value={booleanStateLabel(
1244 snapshot.power.onBattery,
1245 { true: gt`Battery`, false: gt`External power` },
1246 messages,
1247 )}
1248 />
1249 <DetailRow
1250 label={gt`Low power mode`}
1251 value={booleanStateLabel(
1252 snapshot.power.lowPowerMode,
1253 { true: gt`Enabled`, false: gt`Disabled` },
1254 messages,
1255 )}
1256 />
1257 <DetailRow
1258 label={gt`Idle`}
1259 value={`${booleanStateLabel(
1260 snapshot.power.idle,
1262 true: gt({ context: "host power state" })`Idle`,
1263 false: gt({ context: "host power state" })`Active`,
1264 },
1265 messages,
1266 )}${
1267 snapshot.power.idleSeconds === null
1268 ? ""
1269 : ` · ${Math.round(snapshot.power.idleSeconds)}s`
1270 }`}
1271 />
1272 <DetailRow
1273 label={gt`Session`}
1274 value={
1275 snapshot.power.suspended
1276 ? gt`Suspended`
1277 : booleanStateLabel(
1278 snapshot.power.locked,
1279 { true: gt`Locked`, false: gt`Unlocked` },
1280 messages,
1283 />
1284 <DetailRow
1285 label={gt`Thermal`}
1286 value={snapshot.power.thermalState}
1287 valueClassName={
1288 snapshot.power.thermalState === "serious" ||
1289 snapshot.power.thermalState === "critical"
1290 ? "text-destructive"
1291 : undefined
1293 />
1294 </>
1295 ) : (
1296 <div className="rounded-xl border border-dashed border-border/70 bg-muted/20 px-4 py-5">
1297 <div className="text-sm font-medium text-foreground">
1298 <T>Desktop host signals not connected</T>
1299 </div>
1300 <p className="mt-1.5 max-w-sm text-2xs leading-relaxed text-muted-foreground/70">
1301 <T>
1302 Power, idle, lock, and thermal state are supplied by the desktop host. Process
1303 telemetry remains fully active in this browser session.
1304 </T>
1305 </p>
1306 </div>
1307 )}
1308 </div>
1309 <div className="border-t border-border/60 px-4 py-4 md:border-t-0 sm:px-5">
1310 <div className="mb-3 flex items-center gap-2 text-3xs font-semibold uppercase tracking-widest text-muted-foreground/70">
1311 <span className="flex size-6 items-center justify-center rounded-md bg-muted/60">
1312 <GaugeIcon className="size-3.5" />
1313 </span>
1314 <T>Collection health</T>
1315 </div>
1316 {snapshot ? (
1317 <>
1318 <HealthSource label={gt`Native process monitor`} health={snapshot.health.native} />
1319 <HealthSource label={gt`Electron main process`} health={snapshot.health.desktop} />
1320 <DetailRow
1321 label={gt`Collection time`}
1322 value={formatDurationMicros(snapshot.health.collectionDurationMicros)}
1323 />
1324 <DetailRow
1325 label={gt`Process scan`}
1326 value={gt`${{ retained: snapshot.health.retainedProcessCount }}/${{ scanned: snapshot.health.scannedProcessCount }} retained`}
1327 />
1328 <DetailRow
1329 label={gt`Inaccessible`}
1330 value={String(snapshot.health.inaccessibleProcessCount)}
1331 valueClassName={
1332 snapshot.health.inaccessibleProcessCount > 0
1333 ? "text-warning-foreground"
1334 : undefined
1336 />
1337 <DetailRow
1338 label={gt`Sidecar`}
1339 value={Option.match(snapshot.health.sidecarVersion, {
1340 onNone: () => gt`Unavailable`,
1341 onSome: (version) =>
1342 `${version}${Option.match(snapshot.health.sidecarPid, {
1343 onNone: () => "",
1344 onSome: (pid) => ` · PID ${pid}`,
1345 })}`,
1346 })}
1347 />
1348 <DetailRow label={gt`Restarts`} value={String(snapshot.health.restartCount)} />
1349 </>
1350 ) : (
1351 <div className="py-4 text-xs text-muted-foreground">
1352 <T>Waiting for collector health.</T>
1353 </div>
1354 )}
1355 </div>
1356 </div>
1357 </SettingsSection>
1358​
1359 <SettingsSection
1360 title={gt`Resource timeline`}
1361 icon={<HardDriveIcon className="size-4 text-muted-foreground" />}
1362 headerAction={
1363 <div className="flex items-center gap-2">
1364 <HistoryWindowSelector selectedWindowMs={windowMs} onSelect={setWindowMs} />
1365 <Button
1366 size="icon-micro"
1367 variant="ghost"
1368 disabled={history.isPending}
1369 onClick={history.refresh}
1370 aria-label={gt`Refresh resource history`}
1372 <RefreshIcon size="xs" refreshing={history.isPending} />
1373 </Button>
1374 </div>
1377 <div className="overflow-hidden rounded-[inherit]">
1378 {history.error ? (
1379 <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">
1380 <AlertTriangleIcon className="size-3.5 h-lh shrink-0" />
1381 <span>{history.error}</span>
1382 </div>
1383 ) : null}
1384 <ResourceHistoryChart buckets={history.data?.buckets ?? []} />
1385 <HistoryProcessTable processes={history.data?.topProcesses ?? []} />
1386 </div>
1387 </SettingsSection>
1388​
1389 <SettingsSection
1390 title={gt`Live process tree`}
1391 icon={<CpuIcon className="size-4 text-muted-foreground" />}
1392 headerAction={
1393 snapshot ? (
1394 <span className="text-3xs text-muted-foreground/55">
1395 <T>
1396 Identity: <span className="font-mono">PID + start time</span>
1397 </T>
1398 </span>
1399 ) : null
1402 <div className="overflow-hidden rounded-[inherit]">
1403 <ProcessTable
1404 processes={snapshot?.processes ?? []}
1405 canMaintainEnvironment={canMaintainEnvironment}
1406 signalingKeys={signalingKeys}
1407 onSignal={signalProcess}
1408 />
1409 </div>
1410 </SettingsSection>
1411​
1412 <SettingsSection
1413 title={gt`Instrumented application I/O`}
1414 icon={<DatabaseIcon className="size-4 text-muted-foreground" />}
1415 headerAction={
1416 <span className="text-3xs text-muted-foreground/55">
1417 <T>Logical bytes by operation</T>
1418 </span>
1421 <div className="overflow-hidden rounded-[inherit]">
1422 <div className="bg-muted/15 px-4 py-3 text-2xs leading-relaxed text-muted-foreground sm:px-5">
1423 <T>
1424 Native counters identify which process is reading or writing. These application-level
1425 counters identify known T3 operations so process spikes can be correlated with
1426 specific persistence and logging paths.
1427 </T>
1428 </div>
1429 <AttributionTable entries={snapshot?.attribution.entries ?? []} />
1430 </div>
1431 </SettingsSection>
1432 </>
1433 );