Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ export class ChatController {
session.createNewTokenSource()
try {
this.messenger.sendInitalStream(tabID, triggerID)
this.telemetryHelper.setConversationStreamStartTime(tabID)
response = await session.chat(request)
this.telemetryHelper.recordEnterFocusConversation(triggerEvent.tabID)
this.telemetryHelper.recordStartConversation(triggerEvent, triggerPayload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export class CWCTelemetryHelper {
private triggerEventsStorage: TriggerEventsStorage
private responseStreamStartTime: Map<string, number> = new Map()
private responseStreamTotalTime: Map<string, number> = new Map()
private conversationStreamStartTime: Map<string, number> = new Map()
private conversationStreamTotalTime: Map<string, number> = new Map()
private responseStreamTimeForChunks: Map<string, number[]> = new Map()
private responseWithProjectContext: Map<string, boolean> = new Map()

Expand Down Expand Up @@ -447,7 +449,9 @@ export class CWCTelemetryHelper {
this.getTimeBetweenChunks(message.tabID, this.responseStreamTimeForChunks)
),
cwsprChatFullResponseLatency: this.responseStreamTotalTime.get(message.tabID) ?? 0,
cwsprTimeToFirstDisplay: this.getFirstDisplayTime(tabID, startTime),
cwsprChatTimeToFirstDisplay: this.getFirstDisplayTime(tabID, startTime),
cwsprChatTimeFirstUsableChunk: this.getFirstUsableChunkTime(message.tabID) ?? 0,
cwsprChatFullServerResponseLatency: this.conversationStreamTotalTime.get(message.tabID) ?? 0,
cwsprChatTimeBetweenDisplays: JSON.stringify(this.getTimeBetweenChunks(tabID, this.displayTimeForChunks)),
cwsprChatFullDisplayLatency: fullDisplayLatency,
cwsprChatRequestLength: triggerPayload.message?.length ?? 0,
Expand Down Expand Up @@ -549,6 +553,10 @@ export class CWCTelemetryHelper {
this.responseWithProjectContext.set(messageId, true)
}

public setConversationStreamStartTime(tabID: string) {
this.conversationStreamStartTime.set(tabID, performance.now())
}

private getResponseStreamTimeToFirstChunk(tabID: string): number {
const chunkTimes = this.responseStreamTimeForChunks.get(tabID) ?? [0, 0]
if (chunkTimes.length === 1) {
Expand All @@ -568,6 +576,13 @@ export class CWCTelemetryHelper {
return Math.round(chunkTimes[0] - startTime)
}

private getFirstUsableChunkTime(tabID: string) {
const startTime = this.conversationStreamStartTime.get(tabID) ?? 0
const chunkTimes = this.responseStreamTimeForChunks.get(tabID) ?? [0, 0]
// first chunk is the start time, we use the second because thats the first actual usable chunk time
return Math.round(chunkTimes[1] - startTime)
}

private getTimeBetweenChunks(tabID: string, chunks: Map<string, number[]>): number[] {
try {
const chunkDeltaTimes: number[] = []
Expand All @@ -584,8 +599,13 @@ export class CWCTelemetryHelper {
}

public setResponseStreamTotalTime(tabID: string) {
const totalTime = performance.now() - (this.responseStreamStartTime.get(tabID) ?? 0)
this.responseStreamTotalTime.set(tabID, Math.round(totalTime))
// time from when the requests started streaming until the end of the stream
const totalStreamingTime = performance.now() - (this.responseStreamStartTime.get(tabID) ?? 0)
this.responseStreamTotalTime.set(tabID, Math.round(totalStreamingTime))

// time from the initial server request, including creating the conversation id, until the end of the stream
const totalConversationTime = performance.now() - (this.conversationStreamStartTime.get(tabID) ?? 0)
this.conversationStreamTotalTime.set(tabID, Math.round(totalConversationTime))
}

public getConversationId(tabID: string): string | undefined {
Expand Down
24 changes: 20 additions & 4 deletions packages/core/src/shared/telemetry/vscodeTelemetry.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
{
"name": "cwsprChatTimeToFirstChunk",
"type": "int",
"description": "The time between the initial server request and when we got back the first usable result"
"description": "The time between when the conversation id was created and when we got back the first usable result"
},
{
"name": "cwsprChatTimeBetweenChunks",
Expand All @@ -167,10 +167,20 @@
{
"name": "cwsprChatFullResponseLatency",
"type": "int",
"description": "The time between the initial server request and the final response from the server"
"description": "The time between when the conversation id was created and the final response from the server was received"
},
{
"name": "cwsprTimeToFirstDisplay",
"name": "cwsprChatTimeFirstUsableChunk",
"type": "int",
"description": "The time between the initial server request, including creating the conversation id, and the first usable result"
},
{
"name": "cwsprChatFullServerResponseLatency",
"type": "int",
"description": "The time between the initial server request, including creating the conversation id, and the final response from the server"
},
{
"name": "cwsprChatTimeToFirstDisplay",
"type": "int",
"description": "The time between the user pressing enter and when the first chunk of data is displayed to the user"
},
Expand Down Expand Up @@ -753,7 +763,13 @@
"type": "cwsprChatFullResponseLatency"
},
{
"type": "cwsprTimeToFirstDisplay"
"type": "cwsprChatTimeFirstUsableChunk"
},
{
"type": "cwsprChatFullServerResponseLatency"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is something blocking these from being upstreamed to https://github.com/aws/aws-toolkit-common ?

},
{
"type": "cwsprChatTimeToFirstDisplay"
},
{
"type": "cwsprChatFullDisplayLatency"
Expand Down
Loading