Misformatted output for negative values.
qwerty007 opened this issue · comments
Before:
$ sudo ps_mem -p 10606,7171
Private + Shared = RAM used Program
366.3 MiB + -3939.5 KiB = 362.4 MiB mpv
445.4 MiB + -29473.5 KiB = 416.6 MiB firefox
---------------------------------
779.1 MiB
=================================
After:
$ sudo ps_mem -p 10606,7171
Private + Shared = RAM used Program
366.3 MiB + -3.9 MiB = 362.4 MiB mpv
444.0 MiB + -28.8 MiB = 415.2 MiB firefox
---------------------------------
777.7 MiB
=================================
My fix:
$ diff -Naur ps_mem.py ps_mem
--- ps_mem.py 2014-10-19 20:13:24.762857984 +0000
+++ ps_mem 2014-10-19 20:13:11.342930686 +0000
@@ -299,7 +299,7 @@
def human(num, power="Ki", units=None):
if units is None:
powers = ["Ki", "Mi", "Gi", "Ti"]
- while num >= 1000: #4 digits
+ while abs(num) >= 1000: #4 digits
num /= 1024.0
power = powers[powers.index(power)+1]
return "%.1f %sB" % (num, power)
I don't speak python and I have no idea if this is the right way to do it.
while the fix looks OK in isolation, the bigger problem is why you're seeing negative values in the first place. Could you attach the smaps file for mpv? I.E. /proc/$(pidof mpv)/smaps
I don't have mpv running atm, I grabbed smaps file of newsbeuter: http://dpaste.com/1KS3121
`$ sudo ps_mem -p $(pgrep newsbeuter)
Private + Shared = RAM used Program
17.0 MiB + -2458.5 KiB = 14.6 MiB newsbeuter
---------------------------------
14.6 MiB
=================================
This looks to be a kernel bug. Pss should never be less than Private mem.
In the smaps you attached you can see there is one section with AnonHugePages,
which is not accounted for in Pss, hence the discrepancy.
I think there is a kernel patch available for the issue at:
https://lkml.org/lkml/2014/10/9/109
b5800000-b6000000 rw-p 00000000 00:00 0 [stack:420]
Size: 8192 kB
Rss: 4096 kB
Pss: 0 kB
Shared_Clean: 0 kB
Shared_Dirty: 0 kB
Private_Clean: 0 kB
Private_Dirty: 4096 kB
Referenced: 4096 kB
Anonymous: 4096 kB
AnonHugePages: 4096 kB
Swap: 0 kB
KernelPageSize: 4 kB
MMUPageSize: 4 kB
Locked: 0 kB