microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.41k stars 28.95k forks source link

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

Open alex-statsig opened 1 year ago

alex-statsig commented 1 year ago

Type: Bug

Following the vscode performance debugging guide, I tried using "Process Explorer" to pinpoint which extension may be causing a high memory usage I observed in Activity Monitor ("Code - Insiders Helper (Plugin)"). However, the memory usages in process explorer did not add up anywhere close to what I saw in Activity Monitor (4GB for one plugin process in Activity Monitor, a total of <1GB accounted for in vscode explorer), making it very hard to understand which process caused it.

Additionally I tried following the steps to "Profile Running Extensions", but clicking the record button did nothing (can file a separate issue for that if needed).

Process Explorer Mac Activity Monitor
Screenshot 2023-09-27 at 9 57 24 AM Screenshot 2023-09-27 at 9 57 33 AM

VS Code version: Code - Insiders 1.83.0-insider (Universal) (f36df69328ed10f76d4be03e8a82b61794b49711, 2023-09-13T05:34:48.836Z) OS version: Darwin arm64 22.6.0 Modes:

System Info |Item|Value| |---|---| |CPUs|Apple M1 (8 x 24)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|4, 6, 6| |Memory (System)|16.00GB (0.05GB free)| |Process Argv|--crash-reporter-id 5e012cc3-e213-44a2-b238-d6c15248dd24| |Screen Reader|yes| |VM|0%|
Extensions (39) Extension|Author (truncated)|Version ---|---|--- sort-imports|ama|6.3.1 vscode-eslint|dba|2.4.2 prettier-vscode|esb|10.1.0 vscode-terminals|fab|1.15.0 figma-vscode-extension|fig|0.2.7 copilot|Git|1.116.440 copilot-chat|Git|0.8.2023092501 copilot-labs|Git|0.15.1019 vscode-pull-request-github|Git|0.73.2023092609 vscode-graphql|Gra|0.8.19 vscode-graphql-execution|Gra|0.2.4 vscode-graphql-syntax|Gra|1.2.2 relay|met|1.0.2 sapling-scm|met|0.1.27 git-graph|mhu|1.30.0 vscode-kubernetes-tools|ms-|1.3.14 remote-containers|ms-|0.313.0 remote-ssh|ms-|0.106.4 remote-ssh-edit|ms-|0.86.0 remote-wsl|ms-|0.81.4 vscode-remote-extensionpack|ms-|0.24.0 remote-explorer|ms-|0.4.1 remote-server|ms-|1.4.3 vscode-jest|Ort|5.2.3 vscode-thunder-client|ran|2.12.3 java|red|1.22.1 vscode-commons|red|0.0.6 vscode-yaml|red|1.14.0 statsig-dev|sta|0.0.1 intellicode-api-usage-examples|Vis|0.2.8 vscodeintellicode|Vis|1.2.30 vscode-java-debug|vsc|0.54.0 vscode-java-dependency|vsc|0.23.1 vscode-java-pack|vsc|0.25.14 vscode-java-test|vsc|0.40.0 vscode-maven|vsc|0.42.0 console-ninja|Wal|0.0.226 fig|wit|0.0.7 vscode-import-cost|wix|3.3.0 (2 theme extensions excluded)
A/B Experiments ``` vsliv695:30137379 vsins829:30139715 vsliv368cf:30146710 vsreu685:30147344 python383:30185418 vspor879:30202332 vspor708:30202333 vspor363:30204092 vslsvsres303:30308271 pythontb:30258533 pythonptprofiler:30281269 vsdfh931cf:30280410 vshan820:30294714 vscod805cf:30301675 bridge0708:30335490 bridge0723:30353136 vsaa593cf:30376535 pythonvs932:30404738 py29gd2263:30784851 vscaat:30438846 vsclangdf:30492506 c4g48928:30535728 dsvsc012:30540252 pynewext54:30618038 a9j8j154:30646983 showlangstatbar:30737417 24365598:30687740 pythonfmttext:30716741 fixshowwlkth:30771523 showindicator:30805243 pythongtdpath:30726887 i26e3531:30792625 welcomedialog:30812478 pythonnosmt12:30779711 pythonidxpt:30768918 pythonnoceb:30776497 copilotsettingt:30808721 dsvsc013:30777762 dsvsc014:30777825 diffeditorv2:30786206 pythonlinttypecf:30823782 pythonmpsinfo:30842935 dsvsc015:30821418 pythontestfixt:30826906 pythonfb280951:30830809 pythonregdiag:30842812 pythonmypyd1:30841190 ```
Tyriar commented 1 year ago

Can you look into the processes in Activity Monitor and get the full command line (executable and arguments)?

alex-statsig commented 1 year ago

Yeah that was helpful, and thanks for the quick reply. I couldn't see it directly, but with a ps lookup by pid I could. Looks like tsserver, eslintserver, and something else ("NodeService"?). I'll debug the first two on my own (it is a large monorepo).

83047 ??        12:16.83 /Applications/VSCode.app/Contents/Frameworks/Code - Insiders Helper (Plugin).app/Contents/MacOS/Code - Insiders Helper (Plugin) --type=utility --utility-sub-type=node.mojom.NodeService --lang=en-US --service-sandbox-type=none --dns-result-order=ipv4first --inspect-port=0 --user-data-dir=/Users/alex/Library/Application Support/Code - Insiders --standard-schemes=vscode-webview,vscode-file --enable-sandbox --secure-schemes=vscode-webview,vscode-file --bypasscsp-schemes --cors-schemes=vscode-webview,vscode-file --fetch-schemes=vscode-webview,vscode-file --service-worker-schemes=vscode-webview --streaming-schemes --shared-files --field-trial-handle=1718379636,r,1958489062513536701,15286156371794138674,262144 --disable-features=CalculateNativeWinOcclusion,SpareRendererForSitePerProcess

83062 ??        24:15.75 /Applications/VSCode.app/Contents/Frameworks/Code - Insiders Helper (Plugin).app/Contents/MacOS/Code - Insiders Helper (Plugin) --ms-enable-electron-run-as-node --max-old-space-size=3072 /Applications/VSCode.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js --useInferredProjectPerProjectRoot --enableTelemetry --cancellationPipeName /var/folders/hr/39z9xx492d10y86gpdjh0_lw0000gn/T/vscode-typescript501/263a082a8abb8aafa9d5/tscancellation-ebe10b58585b26cc5ba1.tmp* --globalPlugins @vsintellicode/typescript-intellicode-plugin,ms-vsintellicode-typescript --pluginProbeLocations /Users/alex/.vscode-insiders/extensions/visualstudioexptteam.vscodeintellicode-1.2.30,/Users/alex/.vscode-insiders/extensions/visualstudioexptteam.vscodeintellicode-1.2.30 --locale en --noGetErrOnBackgroundUpdate --validateDefaultNpmLocation --useNodeIpc

83135 ??         6:19.00 /Applications/VSCode.app/Contents/Frameworks/Code - Insiders Helper (Plugin).app/Contents/MacOS/Code - Insiders Helper (Plugin) --ms-enable-electron-run-as-node /Users/alex/.vscode-insiders/extensions/dbaeumer.vscode-eslint-2.4.2/server/out/eslintServer.js --node-ipc --clientProcessId=83047

I still think it would be nice if these matched up so I could more easily see from VSCode's tools which ones were using high memory (maybe that's hard because its a subprocess though?).

Tyriar commented 1 year ago

Yeah it looks like a bug that the right numbers aren't coming in, it's probably something as simple as we don't parse gb out correctly. Not sure what NodeService is either, but tsserver is likely the builtin TS support and eslint is the installable eslint extension.

alex-statsig commented 1 year ago

Yeah it looks like a bug that the right numbers aren't coming in, it's probably something as simple as we don't parse gb out correctly. Not sure what NodeService is either, but tsserver is likely the builtin TS support and eslint is the installable eslint extension.

Yeah the PIDs are correct actually (comparing activity monitor to vscode's process explorer); the memory usage just incorrectly says 33MB / 66MB for each of them

lifez commented 1 year ago

I would love to help on this

Tyriar commented 1 year ago

@lifez sure! Here's a pointer for some of the process explorer code: https://github.com/microsoft/vscode/blob/bf926b079f0f007f2f5c200e35b8f0b159060ae9/src/vs/code/electron-sandbox/processExplorer/processExplorerMain.ts

lifez commented 1 year ago

@Tyriar I found the root cause

The way we use to get the amount of memory is using ps.

ps offers a more granular, process-level view, typically showing Resident Set Size (RSS), which is just the portion of a process's memory held in RAM. Activity Monitor provides a user-friendly, aggregated view of memory usage, combining various types of memory.

If we want to see the same amount of memory usage as activity on platform macOS we need to use vmmap command.

So my question is. Should we show the aggregated value like Activity Monitor ?

Screenshot 2023-10-03 at 20 42 55 Screenshot 2023-10-03 at 20 42 46 Screenshot 2023-10-03 at 20 42 43
Tyriar commented 1 year ago

We'll need to use a method that works across macOS and Linux, I see vmmap is not installed by default in my Debian WSL instance which is an issue with that approach. Do large numbers have a G at the end and we're just not handling them? I don't want to overly complicate this particular issue and change the method of fetching memory as a part of this issue, it could be a follow up though.

lifez commented 1 year ago

@Tyriar Currently method is using % memory usage which is not aggregate yet.

I will research more on how we can make this work both on linux and mac.

lifez commented 1 year ago

Activity monitor is combining with App Memory, Wired memory and Compressed memory while 'ps' just offer Resident Set Size memory

lifez commented 1 year ago

@Tyriar After thorough research, it's clear that the ps command cannot provide memory usage metrics that exactly match those displayed in macOS's Activity Monitor. The two tools aggregate and present memory statistics differently.

komagic commented 4 months ago

why image