diff --git a/src/vs/base/browser/performance.ts b/src/vs/base/browser/performance.ts index bc642e9d86d..42f2710acf2 100644 --- a/src/vs/base/browser/performance.ts +++ b/src/vs/base/browser/performance.ts @@ -130,13 +130,13 @@ export namespace inputLatency { measurementsRender[measurementsCount] = performance.getEntriesByName('render')[0].duration; measurementsInputLatency[measurementsCount] = performance.getEntriesByName('inputlatency')[0].duration; - console.info( - `input latency=${measurementsInputLatency[measurementsCount].toFixed(1)} [` + - `keydown=${measurementsKeydown[measurementsCount].toFixed(1)}, ` + - `input=${measurementsInput[measurementsCount].toFixed(1)}, ` + - `render=${measurementsRender[measurementsCount].toFixed(1)}` + - `]` - ); + // console.info( + // `input latency=${measurementsInputLatency[measurementsCount].toFixed(1)} [` + + // `keydown=${measurementsKeydown[measurementsCount].toFixed(1)}, ` + + // `input=${measurementsInput[measurementsCount].toFixed(1)}, ` + + // `render=${measurementsRender[measurementsCount].toFixed(1)}` + + // `]` + // ); measurementsCount++; @@ -144,7 +144,6 @@ export namespace inputLatency { } }); } - setInterval(() => console.log(getAndClearMeasurements()), 10000); /** * Clear the current sample. diff --git a/src/vs/workbench/contrib/performance/browser/inputLatencyContrib.ts b/src/vs/workbench/contrib/performance/browser/inputLatencyContrib.ts new file mode 100644 index 00000000000..bd93a7e3582 --- /dev/null +++ b/src/vs/workbench/contrib/performance/browser/inputLatencyContrib.ts @@ -0,0 +1,39 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { inputLatency } from 'vs/base/browser/performance'; +import { RunOnceScheduler } from 'vs/base/common/async'; +import { Event } from 'vs/base/common/event'; +import { Disposable, MutableDisposable } from 'vs/base/common/lifecycle'; +import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; +import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; + +export class InputLatencyContrib extends Disposable implements IWorkbenchContribution { + private readonly _listener = this._register(new MutableDisposable()); + private readonly _scheduler: RunOnceScheduler; + + constructor( + @IEditorService private readonly _editorService: IEditorService + ) { + super(); + + // The current sampling strategy is when the active editor changes, start sampling and + // report the results after 60 seconds. It's done this way as we don't want to sample + // everything, just somewhat randomly, and using an interval would utilize CPU when the + // application is inactive. + this._scheduler = this._register(new RunOnceScheduler(() => { + const measurements = inputLatency.getAndClearMeasurements(); + console.log('measurements', measurements); + // Listen for the next editor change + this._setupListener(); + }, 60000)); + + this._setupListener(); + } + + private _setupListener(): void { + this._listener.value = Event.once(this._editorService.onDidActiveEditorChange)(() => this._scheduler.schedule()); + } +} diff --git a/src/vs/workbench/contrib/performance/browser/performance.contribution.ts b/src/vs/workbench/contrib/performance/browser/performance.contribution.ts index b7fbee24b67..78bc3795267 100644 --- a/src/vs/workbench/contrib/performance/browser/performance.contribution.ts +++ b/src/vs/workbench/contrib/performance/browser/performance.contribution.ts @@ -15,6 +15,7 @@ import { PerfviewContrib, PerfviewInput } from 'vs/workbench/contrib/performance import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { InstantiationService, Trace } from 'vs/platform/instantiation/common/instantiationService'; import { EventProfiling } from 'vs/base/common/event'; +import { InputLatencyContrib } from 'vs/workbench/contrib/performance/browser/inputLatencyContrib'; // -- startup performance view @@ -127,3 +128,11 @@ registerAction2(class PrintEventProfiling extends Action2 { } } }); + +// -- input latency + + +Registry.as(Extensions.Workbench).registerWorkbenchContribution( + InputLatencyContrib, + LifecyclePhase.Eventually +);