perf: diagnoistics improvements

This commit is contained in:
2026-06-12 01:22:01 +02:00
parent 29032b5a36
commit dac5cb42a5
29 changed files with 1168 additions and 28 deletions

View File

@@ -0,0 +1,91 @@
import { app, BrowserWindow } from 'electron';
import * as os from 'os';
export interface SessionWindowSnapshot {
id: number;
title: string;
url: string | null;
focused: boolean;
visible: boolean;
destroyed: boolean;
}
export interface SessionContextSnapshot {
collectedAt: number;
sessionStartedAt: number;
uptimeMs: number;
appVersion: string;
electronVersion: string;
chromeVersion: string;
nodeVersion: string;
platform: NodeJS.Platform;
arch: string;
osType: string;
osRelease: string;
osVersion: string | null;
totalMemKb: number;
freeMemKb: number;
userDataPath: string;
appPath: string;
isPackaged: boolean;
locale: string;
windowCount: number;
windows: SessionWindowSnapshot[];
}
export function collectSessionContext(input: {
sessionStartedAt: number;
userDataPath: string;
}): SessionContextSnapshot {
const collectedAt = Date.now();
return {
collectedAt,
sessionStartedAt: input.sessionStartedAt,
uptimeMs: Math.max(0, collectedAt - input.sessionStartedAt),
appVersion: app.getVersion(),
electronVersion: process.versions.electron ?? 'unknown',
chromeVersion: process.versions.chrome ?? 'unknown',
nodeVersion: process.versions.node ?? 'unknown',
platform: process.platform,
arch: process.arch,
osType: os.type(),
osRelease: os.release(),
osVersion: readOsVersion(),
totalMemKb: Math.round(os.totalmem() / 1024),
freeMemKb: Math.round(os.freemem() / 1024),
userDataPath: input.userDataPath,
appPath: app.getAppPath(),
isPackaged: app.isPackaged,
locale: app.getLocale(),
windowCount: BrowserWindow.getAllWindows().length,
windows: BrowserWindow.getAllWindows().map(collectWindowSnapshot)
};
}
function collectWindowSnapshot(window: BrowserWindow): SessionWindowSnapshot {
let url: string | null = null;
try {
url = window.webContents.getURL() || null;
} catch {
url = null;
}
return {
id: window.id,
title: window.getTitle(),
url,
focused: window.isFocused(),
visible: window.isVisible(),
destroyed: window.isDestroyed()
};
}
function readOsVersion(): string | null {
try {
return os.version?.() ?? null;
} catch {
return null;
}
}