@devries-cameron20 / t3code Mirror · read-only / commits / 0487654fc8
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 14:45 UTC

fix(web): diagnostics CPU time no longer reads "60s" or "60m" (#29395)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Mokhles elheni committed Nov 14, 2026 at 16:27 UTC 0487654fc8f2c9e733e94ce55eb8fec1c3a1ea52
4 files changed +32 -19
apps/web/src/components/settings/DiagnosticsSettings.tsx
+1 -7
@@ -42,6 +42,7 @@ import { toastManager } from "../ui/toast";
42 import { formatDiagnosticsDuration } from "./DiagnosticsSettings.logic";
43 import { ExpandableText } from "./ExpandableText";
44 import { ResourceTelemetryDiagnostics } from "./ResourceTelemetryDiagnostics";
45 +import { formatCpuTime } from "./ResourceTelemetryDiagnostics.logic";
46 import { SettingsPageContainer, SettingsSection } from "./settingsLayout";
47 import { useAtomCommand } from "../../state/use-atom-command";
48 import { useSettingsScope } from "./SettingsScopeContext";
@@ -431,13 +432,6 @@ const RESOURCE_HISTORY_WINDOWS = [
432 { label: "1h", windowMs: 60 * 60_000, bucketMs: 5 * 60_000 },
433 ] as const;
434
434 -function formatCpuTime(seconds: number): string {
435 - if (seconds < 60) return `${seconds.toFixed(seconds >= 10 ? 1 : 2).replace(/\.0+$/, "")}s`;
436 - const minutes = seconds / 60;
437 - if (minutes < 60) return `${minutes.toFixed(minutes >= 10 ? 1 : 2).replace(/\.0+$/, "")}m`;
438 - return `${(minutes / 60).toFixed(2).replace(/\.0+$/, "")}h`;
439 -}
440 -
435 function formatShortProcessName(command: string): string {
436 const name = formatProcessName(command);
437 return name.length > 42 ? `${name.slice(0, 39)}...` : name;
apps/web/src/components/settings/ResourceTelemetryDiagnostics.logic.test.ts
+15 -1
@@ -3,7 +3,10 @@ import { describe, expect, it } from "vite-plus/test";
3 import type { ResourceTelemetryProcess } from "@t3tools/contracts";
4 import * as DateTime from "effect/DateTime";
5
6 -import { visibleResourceTelemetryProcesses } from "./ResourceTelemetryDiagnostics.logic";
6 +import {
7 + formatCpuTime,
8 + visibleResourceTelemetryProcesses,
9 +} from "./ResourceTelemetryDiagnostics.logic";
10
11 const process = (pid: number, ppid: number, depth: number): ResourceTelemetryProcess => ({
12 identity: { pid, startTimeMs: pid * 1_000 },
@@ -46,3 +49,14 @@ describe("visibleResourceTelemetryProcesses", () => {
49 ]);
50 });
51 });
52 +
53 +describe("formatCpuTime", () => {
54 + it("switches units when rounding reaches the next unit", () => {
55 + expect([59.94, 59.97, 3_599.7, 3_600].map((seconds) => formatCpuTime(seconds))).toEqual([
56 + "59.9s",
57 + "1m",
58 + "1h",
59 + "1h",
60 + ]);
61 + });
62 +});
apps/web/src/components/settings/ResourceTelemetryDiagnostics.logic.ts
+10
@@ -58,3 +58,13 @@ export function resourceHistoryCpuScaleMax(
58 ): number {
59 return Math.max(1, ...buckets.map((bucket) => bucket.avgCpuPercent));
60 }
61 +
62 +export function formatCpuTime(seconds: number): string {
63 + const format = (value: number) => value.toFixed(value >= 10 ? 1 : 2).replace(/\.0+$/, "");
64 + // Pick the unit after rounding so 59.97 seconds never renders as "60s".
65 + const shortSeconds = format(seconds);
66 + if (Number(shortSeconds) < 60) return `${shortSeconds}s`;
67 + const shortMinutes = format(seconds / 60);
68 + if (Number(shortMinutes) < 60) return `${shortMinutes}m`;
69 + return `${(seconds / 3_600).toFixed(2).replace(/\.0+$/, "")}h`;
70 +}
apps/web/src/components/settings/ResourceTelemetryDiagnostics.tsx
+6 -11
@@ -53,6 +53,7 @@ import { Toggle, ToggleGroup } from "../ui/toggle-group";
53 import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
54 import { toastManager } from "../ui/toast";
55 import {
56 + formatCpuTime,
57 processIdentityKey,
58 resourceHistoryBarHeight,
59 resourceHistoryCpuScaleMax,
@@ -72,14 +73,6 @@ function formatRate(value: number): string {
73 return `${formatBytes(value)}/s`;
74 }
75
75 -function formatCpuTime(valueMs: number): string {
76 - const seconds = valueMs / 1_000;
77 - if (seconds < 60) return `${seconds.toFixed(seconds >= 10 ? 1 : 2).replace(/\.0+$/, "")}s`;
78 - const minutes = seconds / 60;
79 - if (minutes < 60) return `${minutes.toFixed(minutes >= 10 ? 1 : 2).replace(/\.0+$/, "")}m`;
80 - return `${(minutes / 60).toFixed(2).replace(/\.0+$/, "")}h`;
81 -}
82 -
76 function formatDurationMicros(value: number): string {
77 if (value < 1_000) return `${Math.round(value)} µs`;
78 if (value < 1_000_000) return `${(value / 1_000).toFixed(2).replace(/\.0+$/, "")} ms`;
@@ -613,7 +606,7 @@ function ProcessTable({
606 {process.cpuPercent.toFixed(1)}%
607 </td>
608 <td className="px-3 py-2 text-right font-mono tabular-nums">
616 - {formatCpuTime(process.cpuTimeMs)}
609 + {formatCpuTime(process.cpuTimeMs / 1_000)}
610 </td>
611 <td className="px-3 py-2 text-right font-mono tabular-nums">
612 {formatBytes(process.residentBytes)}
@@ -719,7 +712,7 @@ function HistoryProcessTable({
712 {categoryLabel(process.category)}
713 </td>
714 <td className="px-3 py-2 text-right font-mono tabular-nums">
722 - {formatCpuTime(process.cpuTimeMs)}
715 + {formatCpuTime(process.cpuTimeMs / 1_000)}
716 </td>
717 <td className="px-3 py-2 text-right font-mono tabular-nums">
718 {process.maxCpuPercent.toFixed(1)}%
@@ -1017,7 +1010,9 @@ function ResourceTelemetryDiagnosticsBody({
1010 icon={<CpuIcon className="size-3.5" />}
1011 label="Current CPU"
1012 value={allT3 ? `${allT3.currentCpuPercent.toFixed(1)}%` : "..."}
1020 - detail={allT3 ? `${formatCpuTime(allT3.cpuTimeMs)} observed CPU time` : undefined}
1013 + detail={
1014 + allT3 ? `${formatCpuTime(allT3.cpuTimeMs / 1_000)} observed CPU time` : undefined
1015 + }
1016 />
1017 <IconStat
1018 icon={<MemoryStickIcon className="size-3.5" />}