Skip to content

Commit 2df7506

Browse files
committed
use topic logger
1 parent 61e6fbf commit 2df7506

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

packages/core/src/shared/logger/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as vscode from 'vscode'
77

8-
export type LogTopic = 'crashMonitoring' | 'dev/beta' | 'notifications' | 'test' | 'unknown'
8+
export type LogTopic = 'crashMonitoring' | 'dev/beta' | 'notifications' | 'test' | 'childProcess' | 'unknown'
99

1010
class ErrorLog {
1111
constructor(

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export class ChildProcessTracker {
7676
cpu: 50,
7777
elapsed: 30 * 1000, // 30 seconds
7878
}
79+
static readonly logger = getLogger('childProcess')
7980
#processByPid: Map<number, ChildProcess> = new Map<number, ChildProcess>()
8081
#pids: PollingSet<number>
8182

@@ -94,28 +95,34 @@ export class ChildProcessTracker {
9495

9596
private async monitor() {
9697
this.cleanUp()
97-
getLogger().debug(`Active running processes size: ${this.#pids.size}`)
98+
ChildProcessTracker.logger.debug(`Active running processes size: ${this.#pids.size}`)
9899

99100
for (const pid of this.#pids.values()) {
100101
await this.checkProcessUsage(pid)
101102
}
102103
}
103104

104105
private async checkProcessUsage(pid: number): Promise<void> {
105-
if (this.#pids.has(pid)) {
106-
const stats = await this.getUsage(pid)
107-
getLogger().debug(`stats for ${pid}: %O`, stats)
106+
if (!this.#pids.has(pid)) {
107+
ChildProcessTracker.logger.warn(`ChildProcess: Missing process with id ${pid}`)
108+
return
109+
}
110+
const stats = await this.getUsage(pid)
111+
if (stats) {
112+
ChildProcessTracker.logger.debug(`stats for ${pid}: %O`, stats)
108113
if (stats.memory > ChildProcessTracker.thresholds.memory) {
109-
getLogger().warn(`Process ${pid} exceeded memory threshold: ${stats.memory}`)
114+
ChildProcessTracker.logger.warn(
115+
`ChildProcess: Process ${pid} exceeded memory threshold: ${stats.memory}`
116+
)
110117
}
111118
if (stats.cpu > ChildProcessTracker.thresholds.cpu) {
112-
getLogger().warn(`Process ${pid} exceeded cpu threshold: ${stats.cpu}`)
119+
ChildProcessTracker.logger.warn(`ChildProcess: Process ${pid} exceeded cpu threshold: ${stats.cpu}`)
113120
}
114121
if (stats.elapsed > ChildProcessTracker.thresholds.elapsed) {
115-
getLogger().warn(`Process ${pid} exceeded time threshold: ${stats.elapsed}`)
122+
ChildProcessTracker.logger.warn(
123+
`ChildProcess: Process ${pid} exceeded time threshold: ${stats.elapsed}`
124+
)
116125
}
117-
} else {
118-
getLogger().warn(`Missing process with id ${pid}`)
119126
}
120127
}
121128

0 commit comments

Comments
 (0)