perf: diagnoistics improvements
This commit is contained in:
91
electron/diagnostics/session-context.collector.ts
Normal file
91
electron/diagnostics/session-context.collector.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user