Fix percentage display for swap
This commit is contained in:
parent
9bba73fa6d
commit
cf3da2ba2e
1 changed files with 9 additions and 3 deletions
12
smem
12
smem
|
|
@ -216,11 +216,11 @@ def fromunits(x):
|
||||||
def pidusername(pid):
|
def pidusername(pid):
|
||||||
return src.username(src.piduser(pid))
|
return src.username(src.piduser(pid))
|
||||||
|
|
||||||
def showamount(a):
|
def showamount(a, total):
|
||||||
if options.abbreviate:
|
if options.abbreviate:
|
||||||
return units(a * 1024)
|
return units(a * 1024)
|
||||||
elif options.percent:
|
elif options.percent:
|
||||||
return "%.2f%%" % (100.0 * a / totalmem())
|
return "%.2f%%" % (100.0 * a / total)
|
||||||
return a
|
return a
|
||||||
|
|
||||||
def filter(opt, arg, *sources):
|
def filter(opt, arg, *sources):
|
||||||
|
|
@ -479,6 +479,9 @@ def showtable(rows, fields, columns, sort):
|
||||||
if options.bar:
|
if options.bar:
|
||||||
columns.append(options.bar)
|
columns.append(options.bar)
|
||||||
|
|
||||||
|
mt = totalmem()
|
||||||
|
st = memory()['swaptotal']
|
||||||
|
|
||||||
for n in columns:
|
for n in columns:
|
||||||
if n not in fields:
|
if n not in fields:
|
||||||
showfields(fields, n)
|
showfields(fields, n)
|
||||||
|
|
@ -486,7 +489,10 @@ def showtable(rows, fields, columns, sort):
|
||||||
|
|
||||||
f = fields[n][2]
|
f = fields[n][2]
|
||||||
if 'a' in f:
|
if 'a' in f:
|
||||||
formatter.append(showamount)
|
if n == 'swap':
|
||||||
|
formatter.append(lambda x: showamount(x, st))
|
||||||
|
else:
|
||||||
|
formatter.append(lambda x: showamount(x, mt))
|
||||||
f = f.replace('a', 's')
|
f = f.replace('a', 's')
|
||||||
else:
|
else:
|
||||||
formatter.append(lambda x: x)
|
formatter.append(lambda x: x)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue