diff --git a/packages/core/src/codewhisperer/service/inlineCompletionItemProvider.ts b/packages/core/src/codewhisperer/service/inlineCompletionItemProvider.ts index b2571ece38c..e5ac2212e06 100644 --- a/packages/core/src/codewhisperer/service/inlineCompletionItemProvider.ts +++ b/packages/core/src/codewhisperer/service/inlineCompletionItemProvider.ts @@ -169,6 +169,7 @@ export class CWInlineCompletionItemProvider implements vscode.InlineCompletionIt ImportAdderProvider.instance.onShowRecommendation(document, this.startPos.line, r) this.nextMove = 0 TelemetryHelper.instance.setFirstSuggestionShowTime() + session.setPerceivedLatency() this._onDidShow.fire() if (matchedCount >= 2 || this.nextToken !== '') { const result = [item] diff --git a/packages/core/src/codewhisperer/util/codeWhispererSession.ts b/packages/core/src/codewhisperer/util/codeWhispererSession.ts index f57fddaecd0..e5daae22d17 100644 --- a/packages/core/src/codewhisperer/util/codeWhispererSession.ts +++ b/packages/core/src/codewhisperer/util/codeWhispererSession.ts @@ -43,6 +43,7 @@ class CodeWhispererSession { invokeSuggestionStartTime = 0 timeToFirstRecommendation = 0 firstSuggestionShowTime = 0 + perceivedLatency = 0 public static get instance() { return (this.#instance ??= new CodeWhispererSession()) @@ -91,6 +92,17 @@ class CodeWhispererSession { } } + setPerceivedLatency() { + if (this.perceivedLatency !== 0) { + return + } + if (this.triggerType === 'OnDemand') { + this.perceivedLatency = this.timeToFirstRecommendation + } else { + this.perceivedLatency = this.firstSuggestionShowTime - vsCodeState.lastUserModificationTime + } + } + reset() { this.sessionId = '' this.requestContext = { request: {} as any, supplementalMetadata: {} as any } diff --git a/packages/core/src/codewhisperer/util/telemetryHelper.ts b/packages/core/src/codewhisperer/util/telemetryHelper.ts index 25f4809af66..2d156066fe7 100644 --- a/packages/core/src/codewhisperer/util/telemetryHelper.ts +++ b/packages/core/src/codewhisperer/util/telemetryHelper.ts @@ -325,9 +325,7 @@ export class TelemetryHelper { suggestionState: this.getSendTelemetrySuggestionState(aggregatedSuggestionState), recommendationLatencyMilliseconds: e2eLatency, triggerToResponseLatencyMilliseconds: session.timeToFirstRecommendation, - perceivedLatencyMilliseconds: session.getPerceivedLatency( - this.sessionDecisions[0].codewhispererTriggerType - ), + perceivedLatencyMilliseconds: session.perceivedLatency, timestamp: new Date(Date.now()), suggestionReferenceCount: referenceCount, generatedLine: generatedLines, @@ -388,6 +386,7 @@ export class TelemetryHelper { this.typeAheadLength = 0 this.timeSinceLastModification = 0 session.timeToFirstRecommendation = 0 + session.perceivedLatency = 0 this.classifierResult = undefined this.classifierThreshold = undefined }