Skip to content

Commit 6046dcb

Browse files
committed
refactor: reuse constant from processUtils
1 parent d23214d commit 6046dcb

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

packages/amazonq/src/lsp/client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
undefinedIfEmpty,
3434
getOptOutPreference,
3535
} from 'aws-core-vscode/shared'
36+
import { processUtils } from 'aws-core-vscode/shared'
3637
import { activate } from './chat/activation'
3738
import { AmazonQResourcePaths } from './lspInstaller'
3839
import { ConfigSection, isValidConfigSection, toAmazonQLSPLogLevel } from './config'
@@ -55,7 +56,7 @@ export async function startLanguageServer(
5556
'--pre-init-encryption',
5657
'--set-credentials-encryption-key',
5758
]
58-
const memoryWarnThreshold = 200 * 1024 * 1024 // 200 MB
59+
const memoryWarnThreshold = 200 * processUtils.oneMB // 200 MB
5960
const serverOptions = createServerOptions({
6061
encryptionKey,
6162
executable: resourcePaths.node,

packages/core/src/amazonq/lsp/lspClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Licensed under the MIT License. See License.txt in the project root for license information.
99
*/
1010
import * as vscode from 'vscode'
11+
import { oneMB } from '../../shared/utilities/processUtils'
1112
import * as path from 'path'
1213
import * as nls from 'vscode-nls'
1314
import * as crypto from 'crypto'
@@ -252,7 +253,7 @@ export async function activate(extensionContext: ExtensionContext, resourcePaths
252253
}
253254

254255
const serverModule = resourcePaths.lsp
255-
const memoryWarnThreshold = 600 * 1024 * 1024 // 600 MB
256+
const memoryWarnThreshold = 600 * oneMB // 600 MB
256257

257258
const serverOptions = createServerOptions({
258259
encryptionKey: key,

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class ChildProcessTracker {
8989
this.#pids = new PollingSet(ChildProcessTracker.pollingInterval, () => this.monitor())
9090
}
9191

92-
private getThreshold(pid: number) {
92+
private getThreshold(pid: number): ProcessStats {
9393
if (!this.#processByPid.has(pid)) {
9494
ChildProcessTracker.logOnce(pid, `Missing process with id ${pid}, returning default threshold`)
9595
return defaultProcessWarnThresholds
@@ -126,10 +126,13 @@ export class ChildProcessTracker {
126126
if (stats) {
127127
ChildProcessTracker.logger.debug(`Process ${pid} usage: %O`, stats)
128128
if (stats.memory > threshold.memory) {
129-
ChildProcessTracker.logOnce(pid, `Process ${pid} exceeded memory threshold: ${stats.memory / oneMB} MB`)
129+
ChildProcessTracker.logOnce(
130+
pid,
131+
`Process ${pid} exceeded memory threshold: ${(stats.memory / oneMB).toFixed(2)} MB`
132+
)
130133
}
131134
if (stats.cpu > threshold.cpu) {
132-
ChildProcessTracker.logOnce(pid, `Process ${pid} exceeded cpu threshold: %${stats.cpu}`)
135+
ChildProcessTracker.logOnce(pid, `Process ${pid} exceeded cpu threshold: ${stats.cpu}%`)
133136
}
134137
}
135138
}

0 commit comments

Comments
 (0)