mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +01:00
Added memory reporting stuff to cpustats.
This commit is contained in:
parent
6acd477e5a
commit
aa088ef6d9
@ -174,17 +174,41 @@ class Status(callbacks.Privmsg):
|
|||||||
'running.')
|
'running.')
|
||||||
return
|
return
|
||||||
activeThreads = threading.activeCount()
|
activeThreads = threading.activeCount()
|
||||||
response = 'I have taken %s seconds of user time and %s seconds of '\
|
response = ('I have taken %.2f seconds of user time and %.2f seconds '
|
||||||
'system time, for a total of %s seconds of CPU time. My '\
|
'of system time, for a total of %.2f seconds of CPU '
|
||||||
'children have taken %s seconds of user time and %s seconds'\
|
'time. My children have taken %.2f seconds of user time '
|
||||||
' of system time for a total of %s seconds of CPU time. ' \
|
'and %.2f seconds of system time for a total of %.2f '
|
||||||
'I\'ve taken a total of %s%% of this computer\'s time. ' \
|
'seconds of CPU time. I\'ve taken a total of %.2f%% of '
|
||||||
'Out of %s I have %s active. ' % \
|
'this computer\'s time. Out of %s I have %s active.' %
|
||||||
(user, system, user + system,
|
(user, system, user + system,
|
||||||
childUser, childSystem, childUser + childSystem,
|
childUser, childSystem, childUser + childSystem,
|
||||||
(user+system+childUser+childSystem)/timeRunning,
|
(user+system+childUser+childSystem)/timeRunning,
|
||||||
utils.nItems(world.threadsSpawned, 'thread', 'spawned'),
|
utils.nItems(world.threadsSpawned, 'thread', 'spawned'),
|
||||||
activeThreads)
|
activeThreads))
|
||||||
|
mem = None
|
||||||
|
pid = os.getpid()
|
||||||
|
try:
|
||||||
|
if sys.platform.startswith('linux'):
|
||||||
|
mem = 0
|
||||||
|
fd = file('/proc/%s/status' % pid)
|
||||||
|
for line in fd:
|
||||||
|
if line.startswith('VmSize'):
|
||||||
|
line = line.rstrip()
|
||||||
|
mem = int(line.split()[1])
|
||||||
|
break
|
||||||
|
assert mem, 'Format changed in /proc/<pid>/status'
|
||||||
|
elif sys.platform.startswith('netbsd'):
|
||||||
|
mem = os.stat('/proc/%s/mem')[7]
|
||||||
|
elif sys.platform.startswith('freebsd') or \
|
||||||
|
sys.platform.startswith('openbsd'):
|
||||||
|
r = os.popen('/bin/ps -l -p %s' % pid)
|
||||||
|
line = r.readline()
|
||||||
|
line = line.strip()
|
||||||
|
r.close()
|
||||||
|
mem = int(line.split()[20])
|
||||||
|
response += ' I\'m taking up %s kB of memory.' % mem
|
||||||
|
except Exception, e:
|
||||||
|
debug.msg(debug.exnToString(e))
|
||||||
irc.reply(msg, response)
|
irc.reply(msg, response)
|
||||||
|
|
||||||
def cmdstats(self, irc, msg, args):
|
def cmdstats(self, irc, msg, args):
|
||||||
|
@ -31,6 +31,8 @@
|
|||||||
|
|
||||||
from test import *
|
from test import *
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
import world
|
import world
|
||||||
|
|
||||||
class StatusTestCase(PluginTestCase, PluginDocumentation):
|
class StatusTestCase(PluginTestCase, PluginDocumentation):
|
||||||
@ -51,6 +53,9 @@ class StatusTestCase(PluginTestCase, PluginDocumentation):
|
|||||||
self.assertError('cpustats')
|
self.assertError('cpustats')
|
||||||
world.startedAt = 0
|
world.startedAt = 0
|
||||||
self.assertNotError('cpustats')
|
self.assertNotError('cpustats')
|
||||||
|
for s in ['linux', 'freebsd', 'openbsd', 'netbsd']:
|
||||||
|
if sys.platform.startswith(s):
|
||||||
|
self.assertRegexp('cpustats', 'kB')
|
||||||
finally:
|
finally:
|
||||||
world.startedAt = original
|
world.startedAt = original
|
||||||
def testUptime(self):
|
def testUptime(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user