import { app } from 'electron'; export interface AppMetricsProcessSnapshot { pid: number; type: string; workingSetKb: number | null; peakWorkingSetKb: number | null; privateBytesKb: number | null; creationTime: number | null; cpuPercent: number | null; } export interface AppMetricsSnapshot { collectedAt: number; processes: AppMetricsProcessSnapshot[]; } export function collectAppMetricsSnapshot(): AppMetricsSnapshot { return { collectedAt: Date.now(), processes: app.getAppMetrics().map((metric) => ({ pid: metric.pid, type: metric.type, workingSetKb: metric.memory?.workingSetSize ?? null, peakWorkingSetKb: readOptionalKilobytes(metric.memory?.peakWorkingSetSize), privateBytesKb: readOptionalKilobytes(metric.memory?.privateBytes), creationTime: metric.creationTime ?? null, cpuPercent: typeof metric.cpu?.percentCPUUsage === 'number' ? Math.round(metric.cpu.percentCPUUsage * 10) / 10 : null })) }; } function readOptionalKilobytes(value: number | undefined): number | null { return typeof value === 'number' && value >= 0 ? value : null; }