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