Skip to content

fix: replace deprecated wmic process stats with CIM query#2791

Open
peschuster wants to merge 1 commit into
aws:mainfrom
peschuster:up/wmic-cim
Open

fix: replace deprecated wmic process stats with CIM query#2791
peschuster wants to merge 1 commit into
aws:mainfrom
peschuster:up/wmic-cim

Conversation

@peschuster

Copy link
Copy Markdown

Problem

ChildProcessTracker polls per-process CPU/memory stats on Windows via
execFileSync('wmic', ...). wmic has been deprecated for years and is
removed from current Windows 11 builds (24H2+), so usage polling silently
fails on up-to-date systems.

There are two additional issues in the same code path:

  • The memory value is overstated 1024x: WorkingSetSize is reported in
    bytes, but the code multiplies by 1024 as if it were KB. The 100 MB
    warning threshold therefore effectively fired at ~100 KB for every
    tracked process.
  • The two execFileSync calls block the event loop on every 10-second
    polling tick, and their column-based text output is locale-sensitive.

Solution

Replace the two blocking wmic calls with a single async PowerShell
Get-CimInstance query. Win32_PerfFormattedData_PerfProc_Process
provides both PercentProcessorTime and WorkingSet in one call, and
ConvertTo-Json makes the output locale-independent and robustly
parseable. Parsing lives in an exported parseCimProcessStats helper with
unit tests (single object, array result, empty output for an
already-exited process, missing properties, malformed output).

Testing

processUtils.test.ts on Windows 11 (German locale): 13 passing with this
change. Note: one pre-existing "after each" hook failure in the
ChildProcess suite (mock-fs/rimraf cleanup on Windows) occurs identically
with and without this change on current main.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

wmic is removed on current Windows 11 builds, so process usage polling
in ChildProcessTracker silently failed. Replace the two blocking
execFileSync('wmic', ...) calls with a single async PowerShell
Get-CimInstance query; Win32_PerfFormattedData_PerfProc_Process
provides both cpu percentage and working set, and ConvertTo-Json keeps
the output locale-independent.

Also fixes memory usage being overstated 1024x: WorkingSetSize is
reported in bytes, not KB, so the 100 MB warning threshold effectively
fired at ~100 KB for every tracked process.
@peschuster
peschuster requested a review from a team as a code owner July 22, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant