返回 DeepSeek-Reasonix
perfDebug.ts
根目录 / desktop / frontend / src / lib / perfDebug.ts
1 // perfDebug — the window.__reasonixPerf introspection hook used by the
2 // real-DOM benchmark harness (desktop/frontend/bench). It is installed only
3 // when the page URL carries `?bench=1`, so production WebView sessions never
4 // see it. Everything exposed is the same content-free diagnostic state the
5 // crash reporter snapshots: activation timings, history page stats, cache
6 // weights, markdown worker counters, mounted row counts.
7
8 import {
9 activationLog,
10 resetSessionDiagnostics,
11 sessionPipelineDiagnostics,
12 type ActivationDiagnostic,
13 type SessionPipelineDiagnostics,
14 } from "./sessionDiagnostics";
15
16 export interface ReasonixPerfHook {
17 /** Aggregate point-in-time diagnostics snapshot. */
18 stats(): SessionPipelineDiagnostics;
19 /** Recent activation records (oldest first), for per-switch timings. */
20 activations(): ActivationDiagnostic[];
21 /** Clear activation/history counters (between benchmark scenarios). */
22 reset(): void;
23 }
24
25 declare global {
26 interface Window {
27 __reasonixPerf?: ReasonixPerfHook;
28 }
29 }
30
31 export function installPerfDebugHook(): void {
32 if (typeof window === "undefined") return;
33 if (!new URLSearchParams(window.location.search).has("bench")) return;
34 window.__reasonixPerf = {
35 stats: () => sessionPipelineDiagnostics(),
36 activations: () => activationLog(),
37 reset: () => resetSessionDiagnostics(),
38 };
39 }
40
40 lines TYPESCRIPT