Repository navigation
fix(process-explorer): report memory footprint on macOS - #331139
DJL (aidaodedjl) wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Improve macOS process memory reporting by overriding ps-derived memory values with top’s physical footprint output, and add parsing + tests for top memory rows.
Changes:
- Add macOS-specific memory footprint override using
top -l 1 -stats pid,mem. - Introduce
parseTopMemoryOutputto parsetopoutput into pid → bytes mapping. - Add unit tests covering suffixes, compression marker, decimals, and header/global lines.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/vs/base/test/node/ps.test.ts | Adds test coverage for parsing macOS top memory output into pid/bytes. |
| src/vs/base/node/ps.ts | Adds top-based memory override on macOS and implements parseTopMemoryOutput. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| for (const pid of map.keys()) { | ||
| cmd += ` -pid ${pid}`; |
There was a problem hiding this comment.
Multiple -pid flags are supported on macOS — the man page says "This option may be specified multiple times", and top -l 1 -pid 1 -pid 8184 -pid 24755 -stats pid,mem correctly returns one row per pid. The comma-separated form does not exist on macOS top.
| for (const line of lines) { | ||
| const matches = PID_MEM.exec(line); | ||
| if (matches) { | ||
| result.set(parseInt(matches[1]), parseFloat(matches[2]) * (TOP_MEMORY_MULTIPLIERS[matches[3]] ?? 1)); |
There was a problem hiding this comment.
Good catch on the fractional bytes — fixed by rounding to whole bytes in bc85bb1 (with a test for the 0.1M case). On the radix: left parseInt as-is to stay consistent with the existing parsePsOutput in this file, which parses pids the same way.
The memory column of the process explorer is derived from the %mem column of ps, which is based on the resident set size. RSS ignores compressed memory and shared frameworks, so the reported values diverge significantly from what Activity Monitor shows (issue microsoft#194322 reports 4 GB in Activity Monitor vs <1 GB accounted for in total). On macOS the MEM column of top reports the physical footprint of a process, the same value Activity Monitor shows. After building the process tree from ps output, override the memory values with the footprints reported by a single top invocation limited to the tree's pids. If top fails, the ps-derived values are kept as a fallback.
bc85bb1 to
720df96
Compare
Fixes #194322
Root cause
On macOS the process explorer's memory column is derived from the
%memcolumn ofps, which is based on the resident set size (RSS). RSS ignores compressed memory, so the values diverge significantly from what Activity Monitor shows — the issue reporter saw 4 GB for one helper process in Activity Monitor while the process explorer accounted for less than 1 GB in total.The MEM column of macOS
topreports the physical footprint of a process, which is the same value Activity Monitor displays (verified againstfootprint -p <pid>, which printsphys_footprintdirectly):Unlike
vmmap(discussed in the issue),topis preinstalled on every macOS system, and the Linux code path is untouched.What changed
psoutput as before, darwin now runs a singletop -l 1 -stats pid,mem -pid <pid>...invocation limited to the pids of the tree (~1s, comparable to the existing 1s CPU sampling on Linux) and overrides the memory values with the reported footprints in bytes. This also handlestop'sK/M/G/Tsuffixes and the+compressed-memory marker.topfails or omits a pid, the ps-derived value is kept as a fallback, so behavior degrades to the status quo instead of breaking.How to test
topoutput parser insrc/vs/base/test/node/ps.test.ts(npm run test-node).