Add an input latency contrib that will do the reporting

This commit is contained in:
Daniel Imms
2022-11-10 16:18:24 -08:00
parent 635ed4c921
commit c1fa901cee
3 changed files with 55 additions and 8 deletions
+7 -8
View File
@@ -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.
@@ -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());
}
}
@@ -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<IWorkbenchContributionsRegistry>(Extensions.Workbench).registerWorkbenchContribution(
InputLatencyContrib,
LifecyclePhase.Eventually
);