diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2021-09-10 13:43:33 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2021-09-10 13:43:33 +0200 |
commit | 778f5e61babfda3998f6ea0e051e1e15791f6466 (patch) | |
tree | 9d2c6aa5720630cc25deded160de0de8d0a97b37 /scripts | |
parent | ac898c7c8cd4d232c602b70d58fc53474e8b9154 (diff) | |
download | psutil-778f5e61babfda3998f6ea0e051e1e15791f6466.tar.gz |
top.py: report mem usage in GB
Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/top.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/scripts/top.py b/scripts/top.py index 3c297d9a..989f8306 100755 --- a/scripts/top.py +++ b/scripts/top.py @@ -125,13 +125,15 @@ def print_header(procs_status, num_procs): dashes, empty_dashes = get_dashes(perc) line = " CPU%-2s [%s%s] %5s%%" % (cpu_num, dashes, empty_dashes, perc) printl(line, color=get_color(perc)) + + # memory usage mem = psutil.virtual_memory() dashes, empty_dashes = get_dashes(mem.percent) line = " Mem [%s%s] %5s%% %6s / %s" % ( dashes, empty_dashes, mem.percent, - str(int(mem.used / 1024 / 1024)) + "M", - str(int(mem.total / 1024 / 1024)) + "M" + bytes2human(mem.used), + bytes2human(mem.total), ) printl(line, color=get_color(mem.percent)) @@ -141,8 +143,8 @@ def print_header(procs_status, num_procs): line = " Swap [%s%s] %5s%% %6s / %s" % ( dashes, empty_dashes, swap.percent, - str(int(swap.used / 1024 / 1024)) + "M", - str(int(swap.total / 1024 / 1024)) + "M" + bytes2human(swap.used), + bytes2human(swap.total), ) printl(line, color=get_color(swap.percent)) |