mem.py -- reports memory usage. windows path from ipsum's TCbot fork

This commit is contained in:
Ryan Hitchman 2010-03-11 18:14:57 -07:00
parent b69bd212a3
commit a89b558395
1 changed files with 30 additions and 0 deletions

30
plugins/mem.py Normal file
View File

@ -0,0 +1,30 @@
import os
import re
from util import hook
@hook.command
def mem(inp):
".mem -- returns bot's current memory usage -- linux/windows only"
if os.name == 'posix':
status_file = open("/proc/%d/status" % os.getpid()).read()
line_pairs = re.findall(r"^(\w+):\s*(.*)\s*$", status_file, re.M)
status = dict(line_pairs)
keys = 'VmSize VmLib VmData VmExe VmRSS VmStk'.split()
return ', '.join(key + ':' + status[key] for key in keys)
elif os.name == 'nt':
cmd = "tasklist /FI \"PID eq %s\" /FO CSV /NH" % os.getpid()
out = os.popen(cmd).read()
total = 0
for amount in re.findall(r'([,0-9]+) K', out):
total += int(amount.replace(',', ''))
return 'memory usage: %d kB' % total
return mem.__doc__
print mem('')