Skip to content

Commit 1286ee2

Browse files
committed
add process as str to telemetry
1 parent fee1fcb commit 1286ee2

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
"type": "int",
66
"description": "A generic size for when units are clear"
77
},
8+
{
9+
"name": "childProcess",
10+
"type": "string",
11+
"description": "A string representation of a ChildProcess"
12+
},
813
{
914
"name": "systemResource",
1015
"type": "string",
@@ -400,6 +405,10 @@
400405
{
401406
"type": "systemResource",
402407
"required": true
408+
},
409+
{
410+
"type": "childProcess",
411+
"required": true
403412
}
404413
]
405414
},

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,18 @@ export class ChildProcessTracker {
113113
}
114114
const warn = (resource: keyof ProcessStats, value: number) => {
115115
telemetry.ide_childProcessWarning.run((span) => {
116-
this.logger.warn(`Process ${pid} exceeded ${resource} threshold: ${value}`)
117-
span.record({ systemResource: resource })
116+
this.logger.warn(`Process ${this.getProcessAsStr(pid)} exceeded ${resource} threshold: ${value}`)
117+
span.record({ systemResource: resource, childProcess: this.getProcessAsStr(pid) })
118118
})
119119
}
120120

121121
if (!this.#pids.has(pid)) {
122-
this.logger.warn(`Missing process with id ${pid}`)
122+
this.logger.warn(`Missing process with pid ${pid}`)
123123
return
124124
}
125125
const stats = await this.getUsage(pid)
126126
if (!stats) {
127-
this.logger.warn(`Failed to get process stats for ${pid}`)
127+
this.logger.warn(`Failed to get process stats for process with pid ${pid}`)
128128
return
129129
}
130130
for (const resource of Object.keys(ChildProcessTracker.thresholds) as (keyof ProcessStats)[]) {
@@ -134,6 +134,15 @@ export class ChildProcessTracker {
134134
}
135135
}
136136

137+
public getProcessAsStr(pid: pid): string {
138+
try {
139+
return this.#processByPid.get(pid)!.toString()
140+
} catch (e) {
141+
this.logger.warn(`Missing process with pid ${pid}`)
142+
return `pid: ${pid}`
143+
}
144+
}
145+
137146
public add(childProcess: ChildProcess) {
138147
const pid = childProcess.pid()
139148
this.#processByPid.set(pid, childProcess)

packages/core/src/test/shared/utilities/processUtils.test.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,10 @@ describe('ChildProcessTracker', function () {
472472

473473
await clock.tickAsync(ChildProcessTracker.pollingInterval)
474474
assertLogsContain('exceeded cpu threshold', false, 'warn')
475-
assertTelemetry('ide_childProcessWarning', { systemResource: 'cpu' })
475+
assertTelemetry('ide_childProcessWarning', {
476+
systemResource: 'cpu',
477+
childProcess: runningProcess.childProcess.toString(),
478+
})
476479

477480
await stopAndWait(runningProcess)
478481
})
@@ -488,7 +491,10 @@ describe('ChildProcessTracker', function () {
488491
usageMock.resolves(highMemory)
489492
await clock.tickAsync(ChildProcessTracker.pollingInterval)
490493
assertLogsContain('exceeded memory threshold', false, 'warn')
491-
assertTelemetry('ide_childProcessWarning', { systemResource: 'memory' })
494+
assertTelemetry('ide_childProcessWarning', {
495+
systemResource: 'memory',
496+
childProcess: runningProcess.childProcess.toString(),
497+
})
492498

493499
await stopAndWait(runningProcess)
494500
})
@@ -525,7 +531,6 @@ describe('ChildProcessTracker', function () {
525531
})
526532

527533
it('logAllUsage includes only active processes', async function () {
528-
console.log('start')
529534
const runningProcess1 = startSleepProcess()
530535
const runningProcess2 = startSleepProcess()
531536

@@ -541,7 +546,6 @@ describe('ChildProcessTracker', function () {
541546
console.log('logAllUsage called')
542547
assert.throws(() => assertLogsContain(runningProcess1.childProcess.pid().toString(), false, 'info'))
543548
assertLogsContain(runningProcess2.childProcess.pid().toString(), false, 'info')
544-
console.log('end')
545549
})
546550

547551
it('logAllUsage defaults to empty message when empty', async function () {
@@ -564,4 +568,11 @@ describe('ChildProcessTracker', function () {
564568
await tracker.logAllUsage()
565569
assertTelemetry('ide_logActiveProcesses', { size: size })
566570
})
571+
572+
it('getProcessAsStr logs warning when its missing', async function () {
573+
const runningProcess1 = startSleepProcess()
574+
tracker.clear()
575+
tracker.getProcessAsStr(runningProcess1.childProcess.pid())
576+
assertLogsContain(runningProcess1.childProcess.pid().toString(), false, 'warn')
577+
})
567578
})

0 commit comments

Comments
 (0)