2

My objective is simply to list the top 5 processes hogging memory, and exactly how much memory they are "using". I have read through the docs and it seems that process.memory_info().rss is what I want, however this number comes out significantly smaller than what the windows task manager is telling me is in the 'Private Working Set'.

Even when I list out the whole contents of memory_info none of the values even come close to the task manager values.

I realize from reading articles by Giampalo that this is a complex topic, and I know very little about system memory. However the simplicity of what I need is to get a number out of psutil which matches the windows task manager (I don't need all of the other metics). How can I get/calculate this?

EXAMPLE

from pprint import pprint as pp
import psutil

procs = [(proc.info['name'], proc.info['memory_full_info']) for proc in psutil.process_iter(attrs=['name', 'memory_full_info'])]

pp(procs)

Gives me the following data for "AfterFX.exe":

('AfterFX.exe', pfullmem(rss=4294967295L, vms=4294967295L, num_page_faults=42058243, peak_wset=4294967295L, wset=4294967295L, peak_paged_pool=2791656, paged_pool=2657304, peak_nonpaged_pool=13270384, nonpaged_pool=13147944, pagefile=4294967295L, peak_pagefile=4294967295L, private=4294967295L, uss=376668160L)),

Yet task manager gives me: AfterFX.exe 50,561,764 K

Spencer
  • 1,931
  • 1
  • 21
  • 44

1 Answers1

2

I am writing from my phone so I can’t link you the specific doc but memory_full_info().uss should be what you are looking for.

Giampaolo Rodolà
  • 12,488
  • 6
  • 68
  • 60
  • Thanks Giampaolo, maybe this is the solution but when I tried it I got an AccessDenied error. Needless to say I don't have Admin rights... – Spencer Apr 07 '18 at 16:40
  • Ok printing a list comprehension with `psutil.process_iter(attrs=['memory_full_info'])` somehow got me around the permissions but still isn't giving me an accurate number. For my top process I get "uss=376672256" yet task mgr gives me 50,561,776 K. Interestingly this is lower than other processes, yet task manager (and logically I know) that's my 'biggest' process. – Spencer Apr 07 '18 at 16:47
  • On Windows psutil exposes different metrics from the PROCESS_MEMORY_COUNTERS_EX struct. taskmgr.exe should be using one of those: http://psutil.readthedocs.io/en/latest/#psutil.Process.memory_info – Giampaolo Rodolà Apr 12 '18 at 08:34