Skip to content

Commit 762b7b4

Browse files
authored
refactor(core): Remove trackPerformance from telemetry (#5708)
## Problem - withPerformance was an experiment to see if we could correlate cpu/memory with number of files ## Solution - Cpu usage/memory usage in the extension host is way too volitile so we might as well clean up this code --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 1e462f9 commit 762b7b4

File tree

6 files changed

+2
-98
lines changed

6 files changed

+2
-98
lines changed

packages/core/src/shared/performance/performance.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import assert from 'assert'
77
import { getLogger } from '../logger'
8-
import { isWeb } from '../extensionGlobals'
98

109
interface PerformanceMetrics {
1110
/**
@@ -46,10 +45,6 @@ export class PerformanceTracker {
4645

4746
constructor(private readonly name: string) {}
4847

49-
static enabled(name: string, trackPerformance: boolean): boolean {
50-
return name === 'function_call' && trackPerformance && !isWeb()
51-
}
52-
5348
start() {
5449
this.#startPerformance = {
5550
cpuUsage: process.cpuUsage(),

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
getTelemetryResult,
2424
} from '../errors'
2525
import { entries, NumericKeys } from '../utilities/tsUtils'
26-
import { PerformanceTracker } from '../performance/performance'
2726
import { randomUUID } from '../crypto'
2827

2928
const AsyncLocalStorage: typeof AsyncLocalStorageClass =
@@ -135,10 +134,7 @@ export type SpanOptions = {
135134
*/
136135
export class TelemetrySpan<T extends MetricBase = MetricBase> {
137136
#startTime?: Date
138-
#options: SpanOptions & {
139-
trackPerformance: boolean
140-
}
141-
#performance?: PerformanceTracker
137+
#options: SpanOptions
142138

143139
private readonly state: Partial<T> = {}
144140
private readonly definition = definitions[this.name] ?? {
@@ -163,10 +159,6 @@ export class TelemetrySpan<T extends MetricBase = MetricBase> {
163159
// do emit by default
164160
emit: options?.emit === undefined ? true : options.emit,
165161
functionId: options?.functionId,
166-
trackPerformance: PerformanceTracker.enabled(
167-
this.name,
168-
this.definition.trackPerformance && (options?.emit ?? false) // only track the performance if we are also emitting
169-
),
170162
}
171163

172164
this.metricId = randomUUID()
@@ -209,10 +201,6 @@ export class TelemetrySpan<T extends MetricBase = MetricBase> {
209201
*/
210202
public start(): this {
211203
this.#startTime = new globals.clock.Date()
212-
if (this.#options.trackPerformance) {
213-
;(this.#performance ??= new PerformanceTracker(this.name)).start()
214-
}
215-
216204
return this
217205
}
218206

@@ -224,21 +212,6 @@ export class TelemetrySpan<T extends MetricBase = MetricBase> {
224212
public stop(err?: unknown): void {
225213
const duration = this.startTime !== undefined ? globals.clock.Date.now() - this.startTime.getTime() : undefined
226214

227-
if (this.#options.trackPerformance) {
228-
// TODO add these to the global metrics, right now it just forces them in the telemetry and ignores the type
229-
// if someone enables this action
230-
const performanceMetrics = this.#performance?.stop()
231-
if (performanceMetrics) {
232-
this.record({
233-
userCpuUsage: performanceMetrics.userCpuUsage,
234-
systemCpuUsage: performanceMetrics.systemCpuUsage,
235-
heapTotal: performanceMetrics.heapTotal,
236-
functionName: this.#options.functionId?.name ?? this.name,
237-
architecture: process.arch,
238-
} as any)
239-
}
240-
}
241-
242215
if (this.#options.emit) {
243216
this.emit({
244217
duration,

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -307,16 +307,6 @@
307307
"type": "string",
308308
"description": "The CPU architecture"
309309
},
310-
{
311-
"name": "totalFileSizeInMB",
312-
"type": "int",
313-
"description": "The total size of all files being sent to Amazon Q"
314-
},
315-
{
316-
"name": "totalFiles",
317-
"type": "int",
318-
"description": "The total number of files being sent to Amazon Q"
319-
},
320310
{
321311
"name": "traceId",
322312
"type": "string",
@@ -1165,14 +1155,6 @@
11651155
"type": "systemCpuUsage",
11661156
"required": false
11671157
},
1168-
{
1169-
"type": "totalFiles",
1170-
"required": false
1171-
},
1172-
{
1173-
"type": "totalFileSizeInMB",
1174-
"required": false
1175-
},
11761158
{
11771159
"type": "architecture",
11781160
"required": false
@@ -1186,8 +1168,7 @@
11861168
"required": true
11871169
}
11881170
],
1189-
"passive": true,
1190-
"trackPerformance": true
1171+
"passive": true
11911172
},
11921173
{
11931174
"name": "webview_load",

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,15 +344,13 @@ export async function collectFiles(
344344
}
345345

346346
let totalSizeBytes = 0
347-
let totalFiles = 0
348347
for (const rootPath of sourcePaths) {
349348
const allFiles = await vscode.workspace.findFiles(
350349
new vscode.RelativePattern(rootPath, '**'),
351350
getExcludePattern()
352351
)
353352

354353
const files = respectGitIgnore ? await filterOutGitignoredFiles(rootPath, allFiles) : allFiles
355-
totalFiles += files.length
356354

357355
for (const file of files) {
358356
const relativePath = getWorkspaceRelativePath(file.fsPath, { workspaceFolders })
@@ -385,7 +383,6 @@ export async function collectFiles(
385383
})
386384
}
387385
}
388-
span.record({ totalFiles, totalFileSizeInMB: totalSizeBytes / (1024 * 1024) })
389386
return storage
390387
},
391388
{

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

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { sleep } from '../../../shared'
1414
import { withTelemetryContext } from '../../../shared/telemetry/util'
1515
import { SinonSandbox } from 'sinon'
1616
import sinon from 'sinon'
17-
import { stubPerformance } from '../../utilities/performance'
1817
import * as crypto from '../../../shared/crypto'
1918

2019
describe('TelemetrySpan', function () {
@@ -77,23 +76,6 @@ describe('TelemetrySpan', function () {
7776
{ result: 'Succeeded', duration: 100 },
7877
])
7978
})
80-
81-
it('records performance', function () {
82-
const { expectedUserCpuUsage, expectedSystemCpuUsage, expectedHeapTotal } = stubPerformance(sandbox)
83-
const span = new TelemetrySpan('function_call', {
84-
emit: true,
85-
})
86-
span.start()
87-
clock.tick(90)
88-
span.stop()
89-
assertTelemetry('function_call', {
90-
userCpuUsage: expectedUserCpuUsage,
91-
systemCpuUsage: expectedSystemCpuUsage,
92-
heapTotal: expectedHeapTotal,
93-
duration: 90,
94-
result: 'Succeeded',
95-
})
96-
})
9779
})
9880

9981
describe('TelemetryTracer', function () {
@@ -269,28 +251,6 @@ describe('TelemetryTracer', function () {
269251
assert.match(metric.requestId ?? '', /[a-z0-9-]+/)
270252
})
271253

272-
it('records performance', function () {
273-
clock = installFakeClock()
274-
const { expectedUserCpuUsage, expectedSystemCpuUsage, expectedHeapTotal } = stubPerformance(sandbox)
275-
tracer.run(
276-
'function_call',
277-
() => {
278-
clock?.tick(90)
279-
},
280-
{
281-
emit: true,
282-
}
283-
)
284-
285-
assertTelemetry('function_call', {
286-
userCpuUsage: expectedUserCpuUsage,
287-
systemCpuUsage: expectedSystemCpuUsage,
288-
heapTotal: expectedHeapTotal,
289-
duration: 90,
290-
result: 'Succeeded',
291-
})
292-
})
293-
294254
describe('nested run()', function () {
295255
let uuidStub: sinon.SinonStub
296256
const nestedName = 'nested_metric' as MetricName

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,6 @@ describe('collectFiles', function () {
301301
)
302302

303303
assertTelemetry('function_call', {
304-
totalFiles: 8,
305-
totalFileSizeInMB: 0.0002593994140625,
306304
functionName: 'collectFiles',
307305
})
308306
})

0 commit comments

Comments
 (0)