Skip to content

Commit 92f910f

Browse files
hedietbpasero
andauthored
Adds telemetry to understand how long the diff editor was visible to the user. (microsoft#181021)
* Adds telemetry to understand how long the diff editor was visible to the user. * Uses StopWatch utility. * Fixes CI * 💄 * 💄 --------- Co-authored-by: Benjamin Pasero <[email protected]>
1 parent 5886713 commit 92f910f

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/vs/workbench/browser/parts/editor/textDiffEditor.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { Dimension, multibyteAwareBtoa } from 'vs/base/browser/dom';
3636
import { ByteSize, FileOperationError, FileOperationResult, IFileService, TooLargeFileOperationError } from 'vs/platform/files/common/files';
3737
import { IBoundarySashes } from 'vs/base/browser/ui/sash/sash';
3838
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
39+
import { StopWatch } from 'vs/base/common/stopwatch';
3940

4041
/**
4142
* The text editor that leverages the diff text editor for the editing experience.
@@ -49,6 +50,8 @@ export class TextDiffEditor extends AbstractTextEditor<IDiffEditorViewState> imp
4950
private diffNavigator: DiffNavigator | undefined;
5051
private readonly diffNavigatorDisposables = this._register(new DisposableStore());
5152

53+
private inputLifecycleStopWatch: StopWatch | undefined = undefined;
54+
5255
override get scopedContextKeyService(): IContextKeyService | undefined {
5356
if (!this.diffEditorControl) {
5457
return undefined;
@@ -96,7 +99,8 @@ export class TextDiffEditor extends AbstractTextEditor<IDiffEditorViewState> imp
9699

97100
override async setInput(input: DiffEditorInput, options: ITextEditorOptions | undefined, context: IEditorOpenContext, token: CancellationToken): Promise<void> {
98101

99-
// Dispose previous diff navigator
102+
// Cleanup previous things associated with the input
103+
this.inputLifecycleStopWatch = undefined;
100104
this.diffNavigatorDisposables.clear();
101105

102106
// Set input and resolve
@@ -149,6 +153,9 @@ export class TextDiffEditor extends AbstractTextEditor<IDiffEditorViewState> imp
149153
readOnly: resolvedDiffEditorModel.modifiedModel?.isReadonly(),
150154
originalEditable: !resolvedDiffEditorModel.originalModel?.isReadonly()
151155
});
156+
157+
// Start to measure input lifecycle
158+
this.inputLifecycleStopWatch = new StopWatch(false);
152159
} catch (error) {
153160
await this.handleSetInputError(error, input, options);
154161
}
@@ -299,13 +306,35 @@ export class TextDiffEditor extends AbstractTextEditor<IDiffEditorViewState> imp
299306
override clearInput(): void {
300307
super.clearInput();
301308

309+
// Log input lifecycle telemetry
310+
const inputLifecycleElapsed = this.inputLifecycleStopWatch?.elapsed();
311+
this.inputLifecycleStopWatch = undefined;
312+
if (typeof inputLifecycleElapsed === 'number') {
313+
this.logInputLifecycleTelemetry(inputLifecycleElapsed, this.getControl()?.getModel()?.modified?.getLanguageId());
314+
}
315+
302316
// Dispose previous diff navigator
303317
this.diffNavigatorDisposables.clear();
304318

305319
// Clear Model
306320
this.diffEditorControl?.setModel(null);
307321
}
308322

323+
private logInputLifecycleTelemetry(duration: number, languageId: string | undefined): void {
324+
this.telemetryService.publicLog2<{
325+
editorVisibleTimeMs: number;
326+
languageId: string;
327+
}, {
328+
owner: 'hediet';
329+
editorVisibleTimeMs: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; isMeasurement: true; comment: 'Indicates the time the diff editor was visible to the user' };
330+
languageId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Indicates for which language the diff editor was shown' };
331+
comment: 'This event gives insight about how long the diff editor was visible to the user.';
332+
}>('diffEditor.editorVisibleTime', {
333+
editorVisibleTimeMs: duration,
334+
languageId: languageId ?? '',
335+
});
336+
}
337+
309338
getDiffNavigator(): DiffNavigator | undefined {
310339
return this.diffNavigator;
311340
}

0 commit comments

Comments
 (0)