Path: blob/main/src/vs/workbench/contrib/performance/browser/inputLatencyContrib.ts
5245 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { inputLatency } from '../../../../base/browser/performance.js';6import { RunOnceScheduler } from '../../../../base/common/async.js';7import { Event } from '../../../../base/common/event.js';8import { Disposable, MutableDisposable } from '../../../../base/common/lifecycle.js';9import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';10import { ITelemetryService } from '../../../../platform/telemetry/common/telemetry.js';11import { IWorkbenchContribution } from '../../../common/contributions.js';12import { IEditorService } from '../../../services/editor/common/editorService.js';1314export class InputLatencyContrib extends Disposable implements IWorkbenchContribution {15private readonly _listener = this._register(new MutableDisposable());16private readonly _scheduler: RunOnceScheduler;1718constructor(19@IConfigurationService private readonly _configurationService: IConfigurationService,20@IEditorService private readonly _editorService: IEditorService,21@ITelemetryService private readonly _telemetryService: ITelemetryService22) {23super();2425// The current sampling strategy is when the active editor changes, start sampling and26// report the results after 60 seconds. It's done this way as we don't want to sample27// everything, just somewhat randomly, and using an interval would utilize CPU when the28// application is inactive.29this._scheduler = this._register(new RunOnceScheduler(() => {30this._logSamples();31this._setupListener();32}, 60000));333435// Only log 1% of users selected randomly to reduce the volume of data, always report if GPU36// acceleration is enabled as it's opt-in37if (Math.random() <= 0.01 || this._configurationService.getValue('editor.experimentalGpuAcceleration') === 'on') {38this._setupListener();39}4041}4243private _setupListener(): void {44this._listener.value = Event.once(this._editorService.onDidActiveEditorChange)(() => this._scheduler.schedule());45}4647private _logSamples(): void {48const measurements = inputLatency.getAndClearMeasurements();49if (!measurements) {50return;51}5253type InputLatencyStatisticFragment = {54owner: 'tyriar';55comment: 'Represents a set of statistics collected about input latencies';56average: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The average time it took to execute.' };57max: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The maximum time it took to execute.' };58min: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The minimum time it took to execute.' };59};6061type PerformanceInputLatencyClassification = {62owner: 'tyriar';63comment: 'This is a set of samples of the time (in milliseconds) that various events took when typing in the editor';64keydown: InputLatencyStatisticFragment;65input: InputLatencyStatisticFragment;66render: InputLatencyStatisticFragment;67total: InputLatencyStatisticFragment;68sampleCount: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The number of samples measured.' };69gpuAcceleration: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'Whether GPU acceleration was enabled at the time the event was reported.' };70};7172type PerformanceInputLatencyEvent = inputLatency.IInputLatencyMeasurements & {73gpuAcceleration: boolean;74};7576this._telemetryService.publicLog2<PerformanceInputLatencyEvent, PerformanceInputLatencyClassification>('performance.inputLatency', {77keydown: measurements.keydown,78input: measurements.input,79render: measurements.render,80total: measurements.total,81sampleCount: measurements.sampleCount,82gpuAcceleration: this._configurationService.getValue('editor.experimentalGpuAcceleration') === 'on'83});84}85}868788