Skip to content

Commit 7e948c5

Browse files
authored
perf(toolkit): add additional metrics for measuring performance (aws#5517)
## Problem - Right now we can't really corelate cpuusage to anything because we don't know how big users projects are (file size or total files) ## Solution - Add additional metrics for file size and total file count
1 parent acd0cbc commit 7e948c5

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

packages/core/src/shared/telemetry/spans.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ export class TelemetrySpan<T extends MetricBase = MetricBase> {
228228
systemCpuUsage: performanceMetrics.systemCpuUsage,
229229
heapTotal: performanceMetrics.heapTotal,
230230
functionName: this.#options.functionId?.name ?? this.name,
231+
architecture: process.arch,
231232
} as any)
232233
}
233234
}

packages/core/src/shared/telemetry/vscodeTelemetry.json

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,21 @@
300300
"name": "webviewName",
301301
"type": "string",
302302
"description": "The name of the webview"
303+
},
304+
{
305+
"name": "architecture",
306+
"type": "string",
307+
"description": "The CPU architecture"
308+
},
309+
{
310+
"name": "totalFileSizeInMB",
311+
"type": "int",
312+
"description": "The total size of all files being sent to Amazon Q"
313+
},
314+
{
315+
"name": "totalFiles",
316+
"type": "int",
317+
"description": "The total number of files being sent to Amazon Q"
303318
}
304319
],
305320
"metrics": [
@@ -1110,15 +1125,27 @@
11101125
"metadata": [
11111126
{
11121127
"type": "userCpuUsage",
1113-
"required": true
1128+
"required": false
11141129
},
11151130
{
11161131
"type": "systemCpuUsage",
1117-
"required": true
1132+
"required": false
1133+
},
1134+
{
1135+
"type": "totalFiles",
1136+
"required": false
1137+
},
1138+
{
1139+
"type": "totalFileSizeInMB",
1140+
"required": false
1141+
},
1142+
{
1143+
"type": "architecture",
1144+
"required": false
11181145
},
11191146
{
11201147
"type": "heapTotal",
1121-
"required": true
1148+
"required": false
11221149
},
11231150
{
11241151
"type": "functionName",

packages/core/src/shared/utilities/workspaceUtils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ export async function collectFiles(
319319
}[]
320320
> {
321321
return telemetry.function_call.run(
322-
async () => {
322+
async (span) => {
323323
const storage: Awaited<ReturnType<typeof collectFiles>> = []
324324

325325
const workspaceFoldersMapping = getWorkspaceFoldersByPrefixes(workspaceFolders)
@@ -344,12 +344,15 @@ export async function collectFiles(
344344
}
345345

346346
let totalSizeBytes = 0
347+
let totalFiles = 0
347348
for (const rootPath of sourcePaths) {
348349
const allFiles = await vscode.workspace.findFiles(
349350
new vscode.RelativePattern(rootPath, '**'),
350351
getExcludePattern()
351352
)
353+
352354
const files = respectGitIgnore ? await filterOutGitignoredFiles(rootPath, allFiles) : allFiles
355+
totalFiles += files.length
353356

354357
for (const file of files) {
355358
const relativePath = getWorkspaceRelativePath(file.fsPath, { workspaceFolders })
@@ -382,6 +385,7 @@ export async function collectFiles(
382385
})
383386
}
384387
}
388+
span.record({ totalFiles, totalFileSizeInMB: totalSizeBytes / (1024 * 1024) })
385389
return storage
386390
},
387391
{

packages/core/src/testInteg/globalSetup.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import * as sinon from 'sinon'
1515
import * as tokenProvider from '../auth/sso/ssoAccessTokenProvider'
1616
import * as testUtil from '../test/testUtil'
1717
import { DeviceFlowAuthorization } from '../auth/sso/ssoAccessTokenProvider'
18+
import { globals } from '../shared'
1819

1920
// ASSUMPTION: Tests are not run concurrently
2021

@@ -57,6 +58,10 @@ export async function mochaGlobalTeardown(this: Mocha.Context) {
5758
}
5859

5960
export const mochaHooks = {
61+
beforeEach(this: Mocha.Context) {
62+
globals.telemetry.clearRecords()
63+
globals.telemetry.logger.clear()
64+
},
6065
afterEach(this: Mocha.Context) {
6166
patchWindow()
6267
},

packages/core/src/testInteg/shared/utilities/workspaceUtils.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
import { getTestWorkspaceFolder } from '../../integrationTestsUtilities'
1919
import globals from '../../../shared/extensionGlobals'
2020
import { CodelensRootRegistry } from '../../../shared/fs/codelensRootRegistry'
21-
import { createTestWorkspace, createTestWorkspaceFolder, toFile } from '../../../test/testUtil'
21+
import { assertTelemetry, createTestWorkspace, createTestWorkspaceFolder, toFile } from '../../../test/testUtil'
2222
import sinon from 'sinon'
2323

2424
describe('findParentProjectFile', async function () {
@@ -297,6 +297,12 @@ describe('collectFiles', function () {
297297
] satisfies typeof result,
298298
result
299299
)
300+
301+
assertTelemetry('function_call', {
302+
totalFiles: 8,
303+
totalFileSizeInMB: 0.0002593994140625,
304+
functionName: 'collectFiles',
305+
})
300306
})
301307

302308
it('does not return license files', async function () {

0 commit comments

Comments
 (0)