Make system memory reporting more robust
- totalmem should return kB when provided manually - firmware size never goes below zero - add comments - calculate kernel portion of cached by subtracting mapped rather than anonymous - get rid of sum() bits for silly column totals
This commit is contained in:
parent
383d6480df
commit
c8bb8425b2
1 changed files with 17 additions and 9 deletions
26
smem
26
smem
|
|
@ -77,7 +77,7 @@ def totalmem():
|
||||||
global _totalmem
|
global _totalmem
|
||||||
if not _totalmem:
|
if not _totalmem:
|
||||||
if options.realmem:
|
if options.realmem:
|
||||||
_totalmem = fromunits(options.realmem)
|
_totalmem = fromunits(options.realmem) / 1024
|
||||||
else:
|
else:
|
||||||
_totalmem = memory()['memtotal']
|
_totalmem = memory()['memtotal']
|
||||||
return _totalmem
|
return _totalmem
|
||||||
|
|
@ -373,26 +373,34 @@ def showusers():
|
||||||
|
|
||||||
def showsystem():
|
def showsystem():
|
||||||
t = totalmem()
|
t = totalmem()
|
||||||
k = kernelsize()
|
ki = kernelsize()
|
||||||
m = memory()
|
m = memory()
|
||||||
|
|
||||||
mt = m['memtotal']
|
mt = m['memtotal']
|
||||||
fh = t - mt - k
|
|
||||||
f = m['memfree']
|
f = m['memfree']
|
||||||
|
|
||||||
|
# total amount used by hardware
|
||||||
|
fh = max(t - mt - ki, 0)
|
||||||
|
|
||||||
|
# total amount mapped into userspace (ie mapped an unmapped pages)
|
||||||
u = m['anonpages'] + m['mapped']
|
u = m['anonpages'] + m['mapped']
|
||||||
|
|
||||||
|
# total amount allocated by kernel not for userspace
|
||||||
kd = mt - f - u
|
kd = mt - f - u
|
||||||
kdd = (m['buffers'] + m['sreclaimable'] +
|
|
||||||
(m['cached'] - m['anonpages']))
|
# total amount in kernel caches
|
||||||
|
kdc = m['buffers'] + m['sreclaimable'] + (m['cached'] - m['mapped'])
|
||||||
|
|
||||||
l = [("firmware/hardware", fh, 0),
|
l = [("firmware/hardware", fh, 0),
|
||||||
("kernel image", k, 0),
|
("kernel image", ki, 0),
|
||||||
("kernel dynamic memory", kd, kdd),
|
("kernel dynamic memory", kd, kdc),
|
||||||
("userspace memory", u, m['mapped']),
|
("userspace memory", u, m['mapped']),
|
||||||
("free memory", f, f)]
|
("free memory", f, f)]
|
||||||
|
|
||||||
fields = dict(
|
fields = dict(
|
||||||
order=('Order', lambda n: n, '% 1s', lambda x: len(p),
|
order=('Order', lambda n: n, '% 1s', lambda x: '',
|
||||||
'hierarchical order'),
|
'hierarchical order'),
|
||||||
area=('Area', lambda n: l[n][0], '%-24s', lambda x: len(l),
|
area=('Area', lambda n: l[n][0], '%-24s', lambda x: '',
|
||||||
'memory area'),
|
'memory area'),
|
||||||
used=('Used', lambda n: l[n][1], '%10a', sum,
|
used=('Used', lambda n: l[n][1], '%10a', sum,
|
||||||
'area in use'),
|
'area in use'),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue