perf: diagnoistics improvements
This commit is contained in:
@@ -7,6 +7,11 @@ import type { ElectronApi } from '../../core/platform/electron/electron-api.mode
|
||||
import { PerfDiagnosticsCollector, publishRendererDiagnosticsSample } from './diagnostics.collector';
|
||||
import type { PerfDiagEntry, PerfDiagReporter } from './diagnostics.models';
|
||||
|
||||
declare global {
|
||||
// Registered for synchronous main-process sampling at high-memory threshold.
|
||||
var __collectPerfDiagSample: (() => PerfDiagEntry[]) | undefined;
|
||||
}
|
||||
|
||||
const SAMPLE_INTERVAL_MS = 10_000;
|
||||
|
||||
let started = false;
|
||||
@@ -36,6 +41,22 @@ export async function bootstrapPerfDiagnostics(
|
||||
|
||||
started = true;
|
||||
|
||||
let immediateSampleCollector: PerfDiagnosticsCollector | null = null;
|
||||
|
||||
runInInjectionContext(injector, () => {
|
||||
immediateSampleCollector = inject(PerfDiagnosticsCollector);
|
||||
});
|
||||
|
||||
globalThis.__collectPerfDiagSample = () => {
|
||||
if (!immediateSampleCollector) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const sample = immediateSampleCollector.collectSample();
|
||||
|
||||
return sample ? immediateSampleCollector.buildEntries(sample) : [];
|
||||
};
|
||||
|
||||
const reporter: PerfDiagReporter = {
|
||||
report: (entry: PerfDiagEntry) => reportSample(entry)
|
||||
};
|
||||
@@ -92,5 +113,6 @@ function stopPerfDiagnosticsSampling(): void {
|
||||
sampleTimer = null;
|
||||
}
|
||||
|
||||
delete globalThis.__collectPerfDiagSample;
|
||||
started = false;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ export type PerfDiagSource = 'main' | 'renderer';
|
||||
|
||||
export type PerfDiagEntryType =
|
||||
| 'session'
|
||||
| 'environment'
|
||||
| 'process'
|
||||
| 'store'
|
||||
| 'components'
|
||||
| 'heap'
|
||||
| 'high-memory'
|
||||
| 'crash'
|
||||
| 'unresponsive';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user