fix: replace deprecated wmic process stats with CIM query#2791
Open
peschuster wants to merge 1 commit into
Open
fix: replace deprecated wmic process stats with CIM query#2791peschuster wants to merge 1 commit into
peschuster wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ChildProcessTrackerpolls per-process CPU/memory stats on Windows viaexecFileSync('wmic', ...).wmichas been deprecated for years and isremoved 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:
WorkingSetSizeis reported inbytes, 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.
execFileSynccalls block the event loop on every 10-secondpolling tick, and their column-based text output is locale-sensitive.
Solution
Replace the two blocking
wmiccalls with a single async PowerShellGet-CimInstancequery.Win32_PerfFormattedData_PerfProc_Processprovides both
PercentProcessorTimeandWorkingSetin one call, andConvertTo-Jsonmakes the output locale-independent and robustlyparseable. Parsing lives in an exported
parseCimProcessStatshelper withunit tests (single object, array result, empty output for an
already-exited process, missing properties, malformed output).
Testing
processUtils.test.tson Windows 11 (German locale): 13 passing with thischange. Note: one pre-existing
"after each"hook failure in theChildProcesssuite (mock-fs/rimraf cleanup on Windows) occurs identicallywith 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.