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

ResourceTelemetryDiagnostics.tsx

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