From 92f910ffdbf9dfbea8e7037bf7caea645ef9bfc0 Mon Sep 17 00:00:00 2001 From: Henning Dieterichs Date: Thu, 27 Apr 2023 15:22:52 +0200 Subject: [PATCH] Adds telemetry to understand how long the diff editor was visible to the user. (#181021) * Adds telemetry to understand how long the diff editor was visible to the user. * Uses StopWatch utility. * Fixes CI * :lipstick: * :lipstick: --------- Co-authored-by: Benjamin Pasero --- .../browser/parts/editor/textDiffEditor.ts | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts index 5583dfd890f..aedd5030993 100644 --- a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts @@ -36,6 +36,7 @@ import { Dimension, multibyteAwareBtoa } from 'vs/base/browser/dom'; import { ByteSize, FileOperationError, FileOperationResult, IFileService, TooLargeFileOperationError } from 'vs/platform/files/common/files'; import { IBoundarySashes } from 'vs/base/browser/ui/sash/sash'; import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences'; +import { StopWatch } from 'vs/base/common/stopwatch'; /** * The text editor that leverages the diff text editor for the editing experience. @@ -49,6 +50,8 @@ export class TextDiffEditor extends AbstractTextEditor imp private diffNavigator: DiffNavigator | undefined; private readonly diffNavigatorDisposables = this._register(new DisposableStore()); + private inputLifecycleStopWatch: StopWatch | undefined = undefined; + override get scopedContextKeyService(): IContextKeyService | undefined { if (!this.diffEditorControl) { return undefined; @@ -96,7 +99,8 @@ export class TextDiffEditor extends AbstractTextEditor imp override async setInput(input: DiffEditorInput, options: ITextEditorOptions | undefined, context: IEditorOpenContext, token: CancellationToken): Promise { - // Dispose previous diff navigator + // Cleanup previous things associated with the input + this.inputLifecycleStopWatch = undefined; this.diffNavigatorDisposables.clear(); // Set input and resolve @@ -149,6 +153,9 @@ export class TextDiffEditor extends AbstractTextEditor imp readOnly: resolvedDiffEditorModel.modifiedModel?.isReadonly(), originalEditable: !resolvedDiffEditorModel.originalModel?.isReadonly() }); + + // Start to measure input lifecycle + this.inputLifecycleStopWatch = new StopWatch(false); } catch (error) { await this.handleSetInputError(error, input, options); } @@ -299,6 +306,13 @@ export class TextDiffEditor extends AbstractTextEditor imp override clearInput(): void { super.clearInput(); + // Log input lifecycle telemetry + const inputLifecycleElapsed = this.inputLifecycleStopWatch?.elapsed(); + this.inputLifecycleStopWatch = undefined; + if (typeof inputLifecycleElapsed === 'number') { + this.logInputLifecycleTelemetry(inputLifecycleElapsed, this.getControl()?.getModel()?.modified?.getLanguageId()); + } + // Dispose previous diff navigator this.diffNavigatorDisposables.clear(); @@ -306,6 +320,21 @@ export class TextDiffEditor extends AbstractTextEditor imp this.diffEditorControl?.setModel(null); } + private logInputLifecycleTelemetry(duration: number, languageId: string | undefined): void { + this.telemetryService.publicLog2<{ + editorVisibleTimeMs: number; + languageId: string; + }, { + owner: 'hediet'; + editorVisibleTimeMs: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; isMeasurement: true; comment: 'Indicates the time the diff editor was visible to the user' }; + languageId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Indicates for which language the diff editor was shown' }; + comment: 'This event gives insight about how long the diff editor was visible to the user.'; + }>('diffEditor.editorVisibleTime', { + editorVisibleTimeMs: duration, + languageId: languageId ?? '', + }); + } + getDiffNavigator(): DiffNavigator | undefined { return this.diffNavigator; }