Move power monitor logging (fix #288875) (#289021)

This commit is contained in:
Benjamin Pasero
2026-01-20 07:32:33 +01:00
committed by GitHub
parent a0ac005701
commit b6d6a3cc87
2 changed files with 39 additions and 34 deletions

View File

@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { app, protocol, session, Session, systemPreferences, WebFrameMain } from 'electron';
import { app, powerMonitor, protocol, session, Session, systemPreferences, WebFrameMain } from 'electron';
import { addUNCHostToAllowlist, disableUNCAccessRestrictions } from '../../base/node/unc.js';
import { validatedIpcMain } from '../../base/parts/ipc/electron-main/ipcMain.js';
import { hostname, release } from 'os';
@@ -611,7 +611,7 @@ export class CodeApplication extends Disposable {
this.lifecycleMainService.phase = LifecycleMainPhase.AfterWindowOpen;
// Post Open Windows Tasks
this.afterWindowOpen();
this.afterWindowOpen(appInstantiationService);
// Set lifecycle phase to `Eventually` after a short delay and when idle (min 2.5sec, max 5sec)
const eventuallyPhaseScheduler = this._register(new RunOnceScheduler(() => {
@@ -1374,7 +1374,7 @@ export class CodeApplication extends Disposable {
});
}
private afterWindowOpen(): void {
private afterWindowOpen(instantiationService: IInstantiationService): void {
// Windows: mutex
this.installMutex();
@@ -1400,6 +1400,41 @@ export class CodeApplication extends Disposable {
if (isMacintosh && app.runningUnderARM64Translation) {
this.windowsMainService?.sendToFocused('vscode:showTranslatedBuildWarning');
}
// Power telemetry
instantiationService.invokeFunction(accessor => {
const telemetryService = accessor.get(ITelemetryService);
type PowerEvent = {
readonly idleState: string;
readonly idleTime: number;
readonly thermalState: string;
readonly onBattery: boolean;
};
type PowerEventClassification = {
idleState: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The system idle state (active, idle, locked, unknown).' };
idleTime: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; isMeasurement: true; comment: 'The system idle time in seconds.' };
thermalState: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The system thermal state (unknown, nominal, fair, serious, critical).' };
onBattery: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; isMeasurement: true; comment: 'Whether the system is running on battery power.' };
owner: 'chrmarti';
comment: 'Tracks OS power suspend and resume events for reliability insights.';
};
const getPowerEventData = (): PowerEvent => ({
idleState: powerMonitor.getSystemIdleState(60),
idleTime: powerMonitor.getSystemIdleTime(),
thermalState: powerMonitor.getCurrentThermalState(),
onBattery: powerMonitor.isOnBatteryPower()
});
this._register(Event.fromNodeEventEmitter(powerMonitor, 'suspend')(() => {
telemetryService.publicLog2<PowerEvent, PowerEventClassification>('power.suspend', getPowerEventData());
}));
this._register(Event.fromNodeEventEmitter(powerMonitor, 'resume')(() => {
telemetryService.publicLog2<PowerEvent, PowerEventClassification>('power.resume', getPowerEventData());
}));
});
}
private async installMutex(): Promise<void> {