Skip to content

fix(process-explorer): report memory footprint on macOS - #331139

Open
DJL (aidaodedjl) wants to merge 2 commits into
microsoft:mainfrom
aidaodedjl:fix/process-explorer-macos-footprint
Open

DJL (aidaodedjl) wants to merge 2 commits into
microsoft:mainfrom
aidaodedjl:fix/process-explorer-macos-footprint

Conversation

@aidaodedjl

Copy link
Copy Markdown

Fixes #194322

Root cause

On macOS the process explorer's memory column is derived from the %mem column of ps, 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 top reports the physical footprint of a process, which is the same value Activity Monitor displays (verified against footprint -p <pid>, which prints phys_footprint directly):

process ps RSS-based (before) top MEM / footprint (after)
Google Chrome 232 MB 333 MB
Electron renderer 457 MB 667 MB
node with 256 MB Buffer 295 MB 268 MB

Unlike vmmap (discussed in the issue), top is preinstalled on every macOS system, and the Linux code path is untouched.

What changed

  • After the process tree is built from ps output as before, darwin now runs a single top -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 handles top's K/M/G/T suffixes and the + compressed-memory marker.
  • If top fails 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

  • Added unit tests for the top output parser in src/vs/base/test/node/ps.test.ts (npm run test-node).
  • Manual: open the Process Explorer (Help > Open Process Explorer) on macOS and compare the Memory column with Activity Monitor for the same pids — the values now match Activity Monitor instead of being consistently lower.

Copilot AI balanced review requested due to automatic review settings August 17, 2026 03:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 parseTopMemoryOutput to parse top output 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.

Comment thread src/vs/base/node/ps.ts
Comment on lines +170 to +171
for (const pid of map.keys()) {
cmd += ` -pid ${pid}`;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/vs/base/node/ps.ts Outdated
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));

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@aidaodedjl
DJL (aidaodedjl) force-pushed the fix/process-explorer-macos-footprint branch from bc85bb1 to 720df96 Compare September 4, 2026 05:42

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Process Explorer memory usage doesn't add up to Activity Monitor

3 participants