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
4 changes: 2 additions & 2 deletions packages/amazonq/src/app/inline/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ export async function activate(languageClient: LanguageClient) {

if (vsCodeState.lastUserModificationTime) {
TelemetryHelper.instance.setTimeSinceLastModification(
performance.now() - vsCodeState.lastUserModificationTime
Date.now() - vsCodeState.lastUserModificationTime
)
}
vsCodeState.lastUserModificationTime = performance.now()
vsCodeState.lastUserModificationTime = Date.now()
/**
* Important: Doing this sleep(10) is to make sure
* 1. this event is processed by vs code first
Expand Down
28 changes: 14 additions & 14 deletions packages/amazonq/src/app/inline/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class InlineCompletionManager implements Disposable {
const startLine = position.line
// TODO: also log the seen state for other suggestions in session
// Calculate timing metrics before diagnostic delay
const totalSessionDisplayTime = performance.now() - requestStartTime
const totalSessionDisplayTime = Date.now() - requestStartTime
await sleep(500)
const diagnosticDiff = getDiagnosticsDifferences(
this.sessionManager.getActiveSession()?.diagnosticsBeforeAccept,
Expand Down Expand Up @@ -175,7 +175,7 @@ export class InlineCompletionManager implements Disposable {
return
}
const requestStartTime = session.requestStartTime
const totalSessionDisplayTime = performance.now() - requestStartTime
const totalSessionDisplayTime = Date.now() - requestStartTime
await commands.executeCommand('editor.action.inlineSuggest.hide')
// TODO: also log the seen state for other suggestions in session
this.disposable.dispose()
Expand Down Expand Up @@ -249,7 +249,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
// Use VS Code command to check if inline suggestion is actually visible on screen
// This command only executes when inlineSuggestionVisible context is true
await vscode.commands.executeCommand('aws.amazonq.checkInlineSuggestionVisibility')
const isInlineSuggestionVisible = performance.now() - session.lastVisibleTime < 50
const isInlineSuggestionVisible = Date.now() - session.lastVisibleTime < 50
return isInlineSuggestionVisible
}

Expand Down Expand Up @@ -278,7 +278,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
sessionId: session.sessionId,
completionSessionResult,
firstCompletionDisplayLatency: session.firstCompletionDisplayLatency,
totalSessionDisplayTime: performance.now() - session.requestStartTime,
totalSessionDisplayTime: Date.now() - session.requestStartTime,
}
this.languageClient.sendNotification(this.logSessionResultMessageName, params)
}
Expand Down Expand Up @@ -309,7 +309,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
// when hitting other keystrokes, the context.triggerKind is Automatic (1)
// we only mark option + C as manual trigger
// this is a workaround since the inlineSuggest.trigger command take no params
const isAutoTrigger = performance.now() - vsCodeState.lastManualTriggerTime > 50
const isAutoTrigger = Date.now() - vsCodeState.lastManualTriggerTime > 50
if (isAutoTrigger && !CodeSuggestionsState.instance.isSuggestionsEnabled()) {
// return early when suggestions are disabled with auto trigger
return []
Expand All @@ -318,9 +318,9 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
// yield event loop to let the document listen catch updates
await sleep(1)

let logstr = `GenerateCompletion metadata:\\n`
let logstr = `GenerateCompletion activity:\\n`
try {
const t0 = performance.now()
const t0 = Date.now()
vsCodeState.isRecommendationsActive = true
// handling previous session
const prevSession = this.sessionManager.getActiveSession()
Expand Down Expand Up @@ -365,7 +365,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
// re-use previous suggestions as long as new typed prefix matches
if (prevItemMatchingPrefix.length > 0) {
logstr += `- not call LSP and reuse previous suggestions that match user typed characters
- duration between trigger to completion suggestion is displayed ${performance.now() - t0}`
- duration between trigger to completion suggestion is displayed ${Date.now() - t0}`
void this.checkWhetherInlineCompletionWasShown()
return prevItemMatchingPrefix
}
Expand All @@ -381,7 +381,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
},
},
firstCompletionDisplayLatency: prevSession.firstCompletionDisplayLatency,
totalSessionDisplayTime: performance.now() - prevSession.requestStartTime,
totalSessionDisplayTime: Date.now() - prevSession.requestStartTime,
}
this.languageClient.sendNotification(this.logSessionResultMessageName, params)
this.sessionManager.clear()
Expand All @@ -396,7 +396,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
TelemetryHelper.instance.setInvokeSuggestionStartTime()
TelemetryHelper.instance.setTriggerType(context.triggerKind)

const t1 = performance.now()
const t1 = Date.now()

await this.recommendationService.getAllRecommendations(
this.languageClient,
Expand All @@ -418,7 +418,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
// eslint-disable-next-line @typescript-eslint/no-base-to-string
const itemLog = items[0] ? `${items[0].insertText.toString()}` : `no suggestion`

const t2 = performance.now()
const t2 = Date.now()

logstr += `- number of suggestions: ${items.length}
- sessionId: ${this.sessionManager.getActiveSession()?.sessionId}
Expand Down Expand Up @@ -468,7 +468,7 @@ ${itemLog}
const lastDocumentChange = this.documentEventListener.getLastDocumentChangeEvent(document.uri.fsPath)
if (
lastDocumentChange &&
performance.now() - lastDocumentChange.timestamp < CodeWhispererConstants.inlineSuggestionShowDelay
Date.now() - lastDocumentChange.timestamp < CodeWhispererConstants.inlineSuggestionShowDelay
) {
await sleep(CodeWhispererConstants.showRecommendationTimerPollPeriod)
} else {
Expand All @@ -486,7 +486,7 @@ ${itemLog}
// Check if Next Edit Prediction feature flag is enabled
if (Experiments.instance.get('amazonqLSPNEP', true)) {
await showEdits(item, editor, session, this.languageClient, this)
logstr += `- duration between trigger to edits suggestion is displayed: ${performance.now() - t0}ms`
logstr += `- duration between trigger to edits suggestion is displayed: ${Date.now() - t0}ms`
}
return []
}
Expand Down Expand Up @@ -530,7 +530,7 @@ ${itemLog}

this.sessionManager.updateCodeReferenceAndImports()
// suggestions returned here will be displayed on screen
logstr += `- duration between trigger to completion suggestion is displayed: ${performance.now() - t0}ms`
logstr += `- duration between trigger to completion suggestion is displayed: ${Date.now() - t0}ms`
void this.checkWhetherInlineCompletionWasShown()
return itemsMatchingTypeahead as InlineCompletionItem[]
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions packages/amazonq/src/app/inline/documentEventListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class DocumentEventListener {
if (this.lastDocumentChangeEventMap.size > this._maxDocument) {
this.lastDocumentChangeEventMap.clear()
}
this.lastDocumentChangeEventMap.set(e.document.uri.fsPath, { event: e, timestamp: performance.now() })
this.lastDocumentChangeEventMap.set(e.document.uri.fsPath, { event: e, timestamp: Date.now() })
// The VS Code provideInlineCompletionCallback may not trigger when Enter is pressed, especially in Python files
// manually make this trigger. In case of duplicate, the provideInlineCompletionCallback is already debounced
if (this.isEnter(e) && vscode.window.activeTextEditor) {
Expand All @@ -37,7 +37,7 @@ export class DocumentEventListener {
const eventTime = result.timestamp
const isDelete =
(event && event.contentChanges.length === 1 && event.contentChanges[0].text === '') || false
const timeDiff = Math.abs(performance.now() - eventTime)
const timeDiff = Math.abs(Date.now() - eventTime)
return timeDiff < 500 && isDelete
}
return false
Expand Down
6 changes: 3 additions & 3 deletions packages/amazonq/src/app/inline/editSuggestionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
*/
export class EditSuggestionState {
private static isEditSuggestionCurrentlyActive = false
private static displayStartTime = performance.now()
private static displayStartTime = Date.now()

static setEditSuggestionActive(active: boolean): void {
this.isEditSuggestionCurrentlyActive = active
if (active) {
this.displayStartTime = performance.now()
this.displayStartTime = Date.now()
}
}

Expand All @@ -22,6 +22,6 @@ export class EditSuggestionState {
}

static isEditSuggestionDisplayingOverOneSecond(): boolean {
return this.isEditSuggestionActive() && performance.now() - this.displayStartTime > 1000
return this.isEditSuggestionActive() && Date.now() - this.displayStartTime > 1000
}
}
8 changes: 4 additions & 4 deletions packages/amazonq/src/app/inline/recommendationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class RecommendationService {
if (document.uri.scheme === 'vscode-notebook-cell') {
request.fileContextOverride = extractFileContextInNotebooks(document, position)
}
const requestStartTime = performance.now()
const requestStartTime = Date.now()
const statusBar = CodeWhispererStatusBarManager.instance

// Only track telemetry if enabled
Expand All @@ -126,7 +126,7 @@ export class RecommendationService {
nextToken: request.partialResultToken,
},
})
const t0 = performance.now()
const t0 = Date.now()

// Best effort estimate of deletion
const isTriggerByDeletion = documentEventListener.isLastEventDeletion(document.uri.fsPath)
Expand Down Expand Up @@ -176,7 +176,7 @@ export class RecommendationService {

getLogger().info('Received inline completion response from LSP: %O', {
sessionId: result.sessionId,
latency: performance.now() - t0,
latency: Date.now() - t0,
itemCount: result.items?.length || 0,
items: result.items?.map((item) => ({
itemId: item.itemId,
Expand Down Expand Up @@ -228,7 +228,7 @@ export class RecommendationService {
}
TelemetryHelper.instance.setFirstSuggestionShowTime()

const firstCompletionDisplayLatency = performance.now() - requestStartTime
const firstCompletionDisplayLatency = Date.now() - requestStartTime
this.sessionManager.startSession(
result.sessionId,
result.items,
Expand Down
2 changes: 1 addition & 1 deletion packages/amazonq/src/app/inline/sessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class SessionManager {
public checkInlineSuggestionVisibility() {
if (this.activeSession) {
this.activeSession.displayed = true
this.activeSession.lastVisibleTime = performance.now()
this.activeSession.lastVisibleTime = Date.now()
}
}

Expand Down
12 changes: 6 additions & 6 deletions packages/amazonq/src/app/inline/telemetryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ export class TelemetryHelper {

public setInvokeSuggestionStartTime() {
this.resetClientComponentLatencyTime()
this._invokeSuggestionStartTime = performance.now()
this._invokeSuggestionStartTime = Date.now()
}

get invokeSuggestionStartTime(): number {
return this._invokeSuggestionStartTime
}

public setPreprocessEndTime() {
this._preprocessEndTime = performance.now()
this._preprocessEndTime = Date.now()
}

get preprocessEndTime(): number {
Expand All @@ -58,7 +58,7 @@ export class TelemetryHelper {

public setSdkApiCallStartTime() {
if (this._sdkApiCallStartTime === 0) {
this._sdkApiCallStartTime = performance.now()
this._sdkApiCallStartTime = Date.now()
}
}

Expand All @@ -68,7 +68,7 @@ export class TelemetryHelper {

public setSdkApiCallEndTime() {
if (this._sdkApiCallEndTime === 0 && this._sdkApiCallStartTime !== 0) {
this._sdkApiCallEndTime = performance.now()
this._sdkApiCallEndTime = Date.now()
}
}

Expand All @@ -78,7 +78,7 @@ export class TelemetryHelper {

public setAllPaginationEndTime() {
if (this._allPaginationEndTime === 0 && this._sdkApiCallEndTime !== 0) {
this._allPaginationEndTime = performance.now()
this._allPaginationEndTime = Date.now()
}
}

Expand All @@ -88,7 +88,7 @@ export class TelemetryHelper {

public setFirstSuggestionShowTime() {
if (this._firstSuggestionShowTime === 0 && this._sdkApiCallEndTime !== 0) {
this._firstSuggestionShowTime = performance.now()
this._firstSuggestionShowTime = Date.now()
}
}

Expand Down
12 changes: 6 additions & 6 deletions packages/amazonq/test/unit/app/inline/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('AmazonQInlineCompletionItemProvider', function () {
const session = {
sessionId: 'test-session',
firstCompletionDisplayLatency: 100,
requestStartTime: performance.now() - 1000,
requestStartTime: Date.now() - 1000,
}

provider.batchDiscardTelemetryForEditSuggestion(items, session)
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('AmazonQInlineCompletionItemProvider', function () {
const session = {
sessionId: 'test-session',
firstCompletionDisplayLatency: 100,
requestStartTime: performance.now() - 1000,
requestStartTime: Date.now() - 1000,
}

provider.batchDiscardTelemetryForEditSuggestion(items, session)
Expand All @@ -108,7 +108,7 @@ describe('AmazonQInlineCompletionItemProvider', function () {
const session = {
sessionId: 'test-session',
firstCompletionDisplayLatency: 100,
requestStartTime: performance.now() - 1000,
requestStartTime: Date.now() - 1000,
}

provider.batchDiscardTelemetryForEditSuggestion(items, session)
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('AmazonQInlineCompletionItemProvider', function () {
mockSessionManager.getActiveSession.returns({
displayed: true,
suggestions: [{ isInlineEdit: true }],
lastVisibleTime: performance.now(),
lastVisibleTime: Date.now(),
})

const result = await provider.isCompletionActive()
Expand All @@ -176,7 +176,7 @@ describe('AmazonQInlineCompletionItemProvider', function () {
})

it('should return true when VS Code command executes successfully', async function () {
const currentTime = performance.now()
const currentTime = Date.now()
mockSessionManager.getActiveSession.returns({
displayed: true,
suggestions: [{ isInlineEdit: false }],
Expand All @@ -192,7 +192,7 @@ describe('AmazonQInlineCompletionItemProvider', function () {
})

it('should return false when VS Code command fails', async function () {
const oldTime = performance.now() - 100 // Old timestamp (>50ms ago)
const oldTime = Date.now() - 100 // Old timestamp (>50ms ago)
mockSessionManager.getActiveSession.returns({
displayed: true,
suggestions: [{ isInlineEdit: false }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class InlineCompletionService {
this._showRecommendationTimer = undefined
}
this._showRecommendationTimer = setInterval(() => {
const delay = performance.now() - vsCodeState.lastUserModificationTime
const delay = Date.now() - vsCodeState.lastUserModificationTime
if (delay < CodeWhispererConstants.inlineSuggestionShowDelay) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class KeyStrokeHandler {
return
}
this.idleTriggerTimer = setInterval(() => {
const duration = (performance.now() - RecommendationHandler.instance.lastInvocationTime) / 1000
const duration = (Date.now() - RecommendationHandler.instance.lastInvocationTime) / 1000
if (duration < CodeWhispererConstants.invocationTimeIntervalThreshold) {
return
}
Expand Down
Loading
Loading