mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Registry values for Status.cpu.
This commit is contained in:
parent
cdc61d18f5
commit
86f2cb8efa
@ -48,8 +48,20 @@ import supybot.conf as conf
|
|||||||
import supybot.utils as utils
|
import supybot.utils as utils
|
||||||
import supybot.world as world
|
import supybot.world as world
|
||||||
import supybot.privmsgs as privmsgs
|
import supybot.privmsgs as privmsgs
|
||||||
|
import supybot.registry as registry
|
||||||
import supybot.callbacks as callbacks
|
import supybot.callbacks as callbacks
|
||||||
|
|
||||||
|
conf.registerPlugin('Status')
|
||||||
|
conf.registerGroup(conf.supybot.plugins.Status, 'cpu')
|
||||||
|
conf.registerChannelValue(conf.supybot.plugins.Status.cpu, 'children',
|
||||||
|
registry.Boolean(True, """Determines whether the cpu command will list the
|
||||||
|
time taken by children as well as the bot's process."""))
|
||||||
|
conf.registerChannelValue(conf.supybot.plugins.Status.cpu, 'threads',
|
||||||
|
registry.Boolean(True, """Determines whether the cpu command will provide
|
||||||
|
the number of threads spawned and active."""))
|
||||||
|
conf.registerChannelValue(conf.supybot.plugins.Status.cpu, 'memory',
|
||||||
|
registry.Boolean(True, """Determines whether the cpu command will report
|
||||||
|
the amount of memory being used by the bot."""))
|
||||||
|
|
||||||
class Status(callbacks.Privmsg):
|
class Status(callbacks.Privmsg):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -110,8 +122,10 @@ class Status(callbacks.Privmsg):
|
|||||||
"""
|
"""
|
||||||
(user, system, childUser, childSystem, elapsed) = os.times()
|
(user, system, childUser, childSystem, elapsed) = os.times()
|
||||||
now = time.time()
|
now = time.time()
|
||||||
|
target = msg.args[0]
|
||||||
timeRunning = now - world.startedAt
|
timeRunning = now - world.startedAt
|
||||||
if user+system < timeRunning+1: # Fudge for FPU inaccuracies.
|
if self.registryValue('cpu.children', target) and \
|
||||||
|
user+system < timeRunning+1: # Fudge for FPU inaccuracies.
|
||||||
children = 'My children have taken %.2f seconds of user time ' \
|
children = 'My children have taken %.2f seconds of user time ' \
|
||||||
'and %.2f seconds of system time ' \
|
'and %.2f seconds of system time ' \
|
||||||
'for a total of %.2f seconds of CPU time. ' % \
|
'for a total of %.2f seconds of CPU time. ' % \
|
||||||
@ -119,32 +133,33 @@ class Status(callbacks.Privmsg):
|
|||||||
else:
|
else:
|
||||||
children = ''
|
children = ''
|
||||||
activeThreads = threading.activeCount()
|
activeThreads = threading.activeCount()
|
||||||
response = ('I have taken %.2f seconds of user time and %.2f seconds '
|
response = 'I have taken %.2f seconds of user time and %.2f seconds ' \
|
||||||
'of system time, for a total of %.2f seconds of CPU '
|
'of system time, for a total of %.2f seconds of CPU ' \
|
||||||
'time. %s'
|
'time. %s' % (user, system, user + system, children)
|
||||||
'I have spawned %s; I currently have %s still running.' %
|
if self.registryValue('cpu.threads', target):
|
||||||
(user, system, user + system, children,
|
spawned = utils.nItems('thread', world.threadsSpawned)
|
||||||
utils.nItems('thread', world.threadsSpawned),
|
response += 'I have spawned %s; I currently have %s still ' \
|
||||||
activeThreads))
|
'running.' % (spawned, activeThreads)
|
||||||
mem = 'an unknown amount'
|
if self.registryValue('cpu.memory', target):
|
||||||
pid = os.getpid()
|
mem = 'an unknown amount'
|
||||||
plat = sys.platform
|
pid = os.getpid()
|
||||||
try:
|
plat = sys.platform
|
||||||
if plat.startswith('linux') or plat.startswith('sunos') or \
|
try:
|
||||||
plat.startswith('freebsd') or plat.startswith('openbsd') or \
|
if plat.startswith('linux') or plat.startswith('sunos') or \
|
||||||
plat.startswith('darwin'):
|
plat.startswith('freebsd') or plat.startswith('openbsd') or \
|
||||||
try:
|
plat.startswith('darwin'):
|
||||||
r = os.popen('ps -o rss -p %s' % pid)
|
try:
|
||||||
r.readline() # VSZ Header.
|
r = os.popen('ps -o rss -p %s' % pid)
|
||||||
mem = r.readline().strip()
|
r.readline() # VSZ Header.
|
||||||
finally:
|
mem = r.readline().strip()
|
||||||
r.close()
|
finally:
|
||||||
elif sys.platform.startswith('netbsd'):
|
r.close()
|
||||||
mem = '%s kB' % os.stat('/proc/%s/mem')[7]
|
elif sys.platform.startswith('netbsd'):
|
||||||
response += ' I\'m taking up %s kB of memory.' % mem
|
mem = '%s kB' % os.stat('/proc/%s/mem')[7]
|
||||||
except Exception:
|
response += ' I\'m taking up %s kB of memory.' % mem
|
||||||
self.log.exception('Uncaught exception in cpu:')
|
except Exception:
|
||||||
irc.reply(response)
|
self.log.exception('Uncaught exception in cpu.memory:')
|
||||||
|
irc.reply(utils.normalizeWhitespace(response))
|
||||||
|
|
||||||
def cmd(self, irc, msg, args):
|
def cmd(self, irc, msg, args):
|
||||||
"""takes no arguments
|
"""takes no arguments
|
||||||
|
Loading…
Reference in New Issue
Block a user