-
Notifications
You must be signed in to change notification settings - Fork 749
fix(childprocess): noisy "memory threshold" logs #7017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import * as crossSpawn from 'cross-spawn' | |
| import * as logger from '../logger/logger' | ||
| import { Timeout, CancellationError, waitUntil } from './timeoutUtils' | ||
| import { PollingSet } from './pollingSet' | ||
| import { CircularBuffer } from './collectionUtils' | ||
|
|
||
| export interface RunParameterContext { | ||
| /** Reports an error parsed from the stdin/stdout streams. */ | ||
|
|
@@ -73,6 +74,7 @@ export class ChildProcessTracker { | |
| cpu: 50, | ||
| } | ||
| static readonly logger = logger.getLogger('childProcess') | ||
| static readonly #loggedPids = new CircularBuffer(1000) | ||
|
||
| #processByPid: Map<number, ChildProcess> = new Map<number, ChildProcess>() | ||
| #pids: PollingSet<number> | ||
|
|
||
|
|
@@ -100,21 +102,28 @@ export class ChildProcessTracker { | |
|
|
||
| private async checkProcessUsage(pid: number): Promise<void> { | ||
| if (!this.#pids.has(pid)) { | ||
| ChildProcessTracker.logger.warn(`Missing process with id ${pid}`) | ||
| ChildProcessTracker.logOnce(pid, `Missing process with id ${pid}`) | ||
| return | ||
| } | ||
| const stats = this.getUsage(pid) | ||
| if (stats) { | ||
| ChildProcessTracker.logger.debug(`Process ${pid} usage: %O`, stats) | ||
| if (stats.memory > ChildProcessTracker.thresholds.memory) { | ||
| ChildProcessTracker.logger.warn(`Process ${pid} exceeded memory threshold: ${stats.memory}`) | ||
| ChildProcessTracker.logOnce(pid, `Process ${pid} exceeded memory threshold: ${stats.memory}`) | ||
| } | ||
| if (stats.cpu > ChildProcessTracker.thresholds.cpu) { | ||
| ChildProcessTracker.logger.warn(`Process ${pid} exceeded cpu threshold: ${stats.cpu}`) | ||
| ChildProcessTracker.logOnce(pid, `Process ${pid} exceeded cpu threshold: ${stats.cpu}`) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static logOnce(pid: number, msg: string) { | ||
| if (!ChildProcessTracker.#loggedPids.contains(pid)) { | ||
| ChildProcessTracker.#loggedPids.add(pid) | ||
| ChildProcessTracker.logger.warn(msg) | ||
| } | ||
| } | ||
|
|
||
| public add(childProcess: ChildProcess) { | ||
| const pid = childProcess.pid() | ||
| this.#processByPid.set(pid, childProcess) | ||
|
|
@@ -147,7 +156,7 @@ export class ChildProcessTracker { | |
| // isWin() leads to circular dependency. | ||
| return process.platform === 'win32' ? getWindowsUsage() : getUnixUsage() | ||
| } catch (e) { | ||
| ChildProcessTracker.logger.warn(`Failed to get process stats for ${pid}: ${e}`) | ||
| ChildProcessTracker.logOnce(pid, `Failed to get process stats for ${pid}: ${e}`) | ||
| return { cpu: 0, memory: 0 } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.