Changed method of formatting memory usage.
This commit is contained in:
parent
ac86a78e2c
commit
a54a061793
1 changed files with 13 additions and 4 deletions
|
@ -6,6 +6,15 @@ from util import hook
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
|
|
||||||
|
def convert_kilobytes(kilobytes):
|
||||||
|
if kilobytes >= 1024:
|
||||||
|
megabytes = kilobytes / 1024
|
||||||
|
size = '%.2f MB' % megabytes
|
||||||
|
else:
|
||||||
|
size = '%.2f KB' % kilobytes
|
||||||
|
return size
|
||||||
|
|
||||||
|
|
||||||
@hook.command(autohelp=False)
|
@hook.command(autohelp=False)
|
||||||
def system(inp):
|
def system(inp):
|
||||||
".system -- Retrieves information about the host system."
|
".system -- Retrieves information about the host system."
|
||||||
|
@ -30,7 +39,7 @@ def memory(inp):
|
||||||
# get the data we need and process it
|
# get the data we need and process it
|
||||||
data = s['VmRSS'], s['VmSize'], s['VmPeak'], s['VmStk'], s['VmData']
|
data = s['VmRSS'], s['VmSize'], s['VmPeak'], s['VmStk'], s['VmData']
|
||||||
data = [float(i.replace(' kB', '')) for i in data]
|
data = [float(i.replace(' kB', '')) for i in data]
|
||||||
strings = [str(round(i / 1024, 2)) + ' MB' for i in data]
|
strings = [convert_kilobytes(i) for i in data]
|
||||||
# prepare the output
|
# prepare the output
|
||||||
out = "Threads: \x02%s\x02, Real Memory: \x02%s\x02, Allocated Memory: \x02%s\x02, Peak " \
|
out = "Threads: \x02%s\x02, Real Memory: \x02%s\x02, Allocated Memory: \x02%s\x02, Peak " \
|
||||||
"Allocated Memory: \x02%s\x02, Stack Size: \x02%s\x02, Heap " \
|
"Allocated Memory: \x02%s\x02, Stack Size: \x02%s\x02, Heap " \
|
||||||
|
@ -44,9 +53,9 @@ def memory(inp):
|
||||||
out = os.popen(cmd).read()
|
out = os.popen(cmd).read()
|
||||||
memory = 0
|
memory = 0
|
||||||
for amount in re.findall(r'([,0-9]+) K', out):
|
for amount in re.findall(r'([,0-9]+) K', out):
|
||||||
memory += int(amount.replace(',', ''))
|
memory += float(amount.replace(',', ''))
|
||||||
memory = str(round(float(memory) / 1024, 2))
|
memory = convert_kilobytes(memory)
|
||||||
return "Memory Usage: \x02%s MB\x02" % memory
|
return "Memory Usage: \x02%s\x02" % memory
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return "Sorry, this command is not supported on your OS."
|
return "Sorry, this command is not supported on your OS."
|
||||||
|
|
Reference in a new issue