Skip to content

Commit c1fa901

Browse files
committed
Add an input latency contrib that will do the reporting
1 parent 635ed4c commit c1fa901

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

src/vs/base/browser/performance.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,20 @@ export namespace inputLatency {
130130
measurementsRender[measurementsCount] = performance.getEntriesByName('render')[0].duration;
131131
measurementsInputLatency[measurementsCount] = performance.getEntriesByName('inputlatency')[0].duration;
132132

133-
console.info(
134-
`input latency=${measurementsInputLatency[measurementsCount].toFixed(1)} [` +
135-
`keydown=${measurementsKeydown[measurementsCount].toFixed(1)}, ` +
136-
`input=${measurementsInput[measurementsCount].toFixed(1)}, ` +
137-
`render=${measurementsRender[measurementsCount].toFixed(1)}` +
138-
`]`
139-
);
133+
// console.info(
134+
// `input latency=${measurementsInputLatency[measurementsCount].toFixed(1)} [` +
135+
// `keydown=${measurementsKeydown[measurementsCount].toFixed(1)}, ` +
136+
// `input=${measurementsInput[measurementsCount].toFixed(1)}, ` +
137+
// `render=${measurementsRender[measurementsCount].toFixed(1)}` +
138+
// `]`
139+
// );
140140

141141
measurementsCount++;
142142

143143
reset();
144144
}
145145
});
146146
}
147-
setInterval(() => console.log(getAndClearMeasurements()), 10000);
148147

149148
/**
150149
* Clear the current sample.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
}

src/vs/workbench/contrib/performance/browser/performance.contribution.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { PerfviewContrib, PerfviewInput } from 'vs/workbench/contrib/performance
1515
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
1616
import { InstantiationService, Trace } from 'vs/platform/instantiation/common/instantiationService';
1717
import { EventProfiling } from 'vs/base/common/event';
18+
import { InputLatencyContrib } from 'vs/workbench/contrib/performance/browser/inputLatencyContrib';
1819

1920
// -- startup performance view
2021

@@ -127,3 +128,11 @@ registerAction2(class PrintEventProfiling extends Action2 {
127128
}
128129
}
129130
});
131+
132+
// -- input latency
133+
134+
135+
Registry.as<IWorkbenchContributionsRegistry>(Extensions.Workbench).registerWorkbenchContribution(
136+
InputLatencyContrib,
137+
LifecyclePhase.Eventually
138+
);

0 commit comments

Comments
 (0)