Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/performance/browser/inputLatencyContrib.ts
5245 views
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 '../../../../base/browser/performance.js';
7
import { RunOnceScheduler } from '../../../../base/common/async.js';
8
import { Event } from '../../../../base/common/event.js';
9
import { Disposable, MutableDisposable } from '../../../../base/common/lifecycle.js';
10
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
11
import { ITelemetryService } from '../../../../platform/telemetry/common/telemetry.js';
12
import { IWorkbenchContribution } from '../../../common/contributions.js';
13
import { IEditorService } from '../../../services/editor/common/editorService.js';
14
15
export class InputLatencyContrib extends Disposable implements IWorkbenchContribution {
16
private readonly _listener = this._register(new MutableDisposable());
17
private readonly _scheduler: RunOnceScheduler;
18
19
constructor(
20
@IConfigurationService private readonly _configurationService: IConfigurationService,
21
@IEditorService private readonly _editorService: IEditorService,
22
@ITelemetryService private readonly _telemetryService: ITelemetryService
23
) {
24
super();
25
26
// The current sampling strategy is when the active editor changes, start sampling and
27
// report the results after 60 seconds. It's done this way as we don't want to sample
28
// everything, just somewhat randomly, and using an interval would utilize CPU when the
29
// application is inactive.
30
this._scheduler = this._register(new RunOnceScheduler(() => {
31
this._logSamples();
32
this._setupListener();
33
}, 60000));
34
35
36
// Only log 1% of users selected randomly to reduce the volume of data, always report if GPU
37
// acceleration is enabled as it's opt-in
38
if (Math.random() <= 0.01 || this._configurationService.getValue('editor.experimentalGpuAcceleration') === 'on') {
39
this._setupListener();
40
}
41
42
}
43
44
private _setupListener(): void {
45
this._listener.value = Event.once(this._editorService.onDidActiveEditorChange)(() => this._scheduler.schedule());
46
}
47
48
private _logSamples(): void {
49
const measurements = inputLatency.getAndClearMeasurements();
50
if (!measurements) {
51
return;
52
}
53
54
type InputLatencyStatisticFragment = {
55
owner: 'tyriar';
56
comment: 'Represents a set of statistics collected about input latencies';
57
average: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The average time it took to execute.' };
58
max: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The maximum time it took to execute.' };
59
min: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The minimum time it took to execute.' };
60
};
61
62
type PerformanceInputLatencyClassification = {
63
owner: 'tyriar';
64
comment: 'This is a set of samples of the time (in milliseconds) that various events took when typing in the editor';
65
keydown: InputLatencyStatisticFragment;
66
input: InputLatencyStatisticFragment;
67
render: InputLatencyStatisticFragment;
68
total: InputLatencyStatisticFragment;
69
sampleCount: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The number of samples measured.' };
70
gpuAcceleration: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'Whether GPU acceleration was enabled at the time the event was reported.' };
71
};
72
73
type PerformanceInputLatencyEvent = inputLatency.IInputLatencyMeasurements & {
74
gpuAcceleration: boolean;
75
};
76
77
this._telemetryService.publicLog2<PerformanceInputLatencyEvent, PerformanceInputLatencyClassification>('performance.inputLatency', {
78
keydown: measurements.keydown,
79
input: measurements.input,
80
render: measurements.render,
81
total: measurements.total,
82
sampleCount: measurements.sampleCount,
83
gpuAcceleration: this._configurationService.getValue('editor.experimentalGpuAcceleration') === 'on'
84
});
85
}
86
}
87
88