|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import { inputLatency } from 'vs/base/browser/performance'; |
| 7 | +import { RunOnceScheduler } from 'vs/base/common/async'; |
| 8 | +import { Event } from 'vs/base/common/event'; |
| 9 | +import { Disposable, MutableDisposable } from 'vs/base/common/lifecycle'; |
| 10 | +import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; |
| 11 | +import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; |
| 12 | + |
| 13 | +export class InputLatencyContrib extends Disposable implements IWorkbenchContribution { |
| 14 | + private readonly _listener = this._register(new MutableDisposable()); |
| 15 | + private readonly _scheduler: RunOnceScheduler; |
| 16 | + |
| 17 | + constructor( |
| 18 | + @IEditorService private readonly _editorService: IEditorService |
| 19 | + ) { |
| 20 | + super(); |
| 21 | + |
| 22 | + // The current sampling strategy is when the active editor changes, start sampling and |
| 23 | + // report the results after 60 seconds. It's done this way as we don't want to sample |
| 24 | + // everything, just somewhat randomly, and using an interval would utilize CPU when the |
| 25 | + // application is inactive. |
| 26 | + this._scheduler = this._register(new RunOnceScheduler(() => { |
| 27 | + const measurements = inputLatency.getAndClearMeasurements(); |
| 28 | + console.log('measurements', measurements); |
| 29 | + // Listen for the next editor change |
| 30 | + this._setupListener(); |
| 31 | + }, 60000)); |
| 32 | + |
| 33 | + this._setupListener(); |
| 34 | + } |
| 35 | + |
| 36 | + private _setupListener(): void { |
| 37 | + this._listener.value = Event.once(this._editorService.onDidActiveEditorChange)(() => this._scheduler.schedule()); |
| 38 | + } |
| 39 | +} |
0 commit comments