From 1290d2e3ebb3a82e96b64b7e9841923073b115c8 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Tue, 17 Aug 2004 20:28:00 +0000 Subject: [PATCH] Added profiling information as well as the threads command. --- plugins/Status.py | 22 +++++++++++++++++++--- scripts/supybot | 1 + src/world.py | 4 +++- test/test_Status.py | 3 +++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/plugins/Status.py b/plugins/Status.py index c93d73cdb..6fcdbc212 100644 --- a/plugins/Status.py +++ b/plugins/Status.py @@ -58,7 +58,7 @@ 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 + registry.Boolean(False, """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 @@ -98,7 +98,23 @@ class Status(callbacks.Privmsg): networks.sort() networks = ['%s as %s' % (net, utils.commaAndify(nicks)) for (net, nicks) in networks] - irc.reply('I am connected to %s.' % utils.commaAndify(networks)) + L = ['I am connected to %s.' % utils.commaAndify(networks)] + if world.profiling: + L.append('I am current in code profiling mode.') + irc.reply(' '.join(L)) + + def threads(self, irc, msg, args): + """takes no arguments + + Returns the current threads that are active. + """ + threads = [t.getName() for t in threading.enumerate()] + threads.sort() + s = 'I have spawned %s; %s %s still currently active: %s.' % \ + (utils.nItems('thread', world.threadsSpawned), + utils.nItems('thread', len(threads)), utils.be(len(threads)), + utils.commaAndify(threads)) + irc.reply(s) def net(self, irc, msg, args): """takes no arguments @@ -156,7 +172,7 @@ class Status(callbacks.Privmsg): finally: r.close() elif sys.platform.startswith('netbsd'): - mem = '%s kB' % os.stat('/proc/%s/mem')[7] + mem = '%s kB' % os.stat('/proc/%s/mem' % pid)[7] response += ' I\'m taking up %s kB of memory.' % mem except Exception: self.log.exception('Uncaught exception in cpu.memory:') diff --git a/scripts/supybot b/scripts/supybot index 98568c051..488e90169 100755 --- a/scripts/supybot +++ b/scripts/supybot @@ -325,6 +325,7 @@ if __name__ == '__main__': if options.profile: import hotshot profiler = hotshot.Profile('%s-%i.prof' % (nick, time.time())) + world.profiling = True profiler.run('main()') else: main() diff --git a/src/world.py b/src/world.py index bf43b6110..c2fccab45 100644 --- a/src/world.py +++ b/src/world.py @@ -173,8 +173,10 @@ atexit.register(startDying) ################################################## ################################################## ################################################## -testing = False dying = False +testing = False +starting = False +profiling = False documenting = False diff --git a/test/test_Status.py b/test/test_Status.py index 1903752d9..7dcf160bc 100644 --- a/test/test_Status.py +++ b/test/test_Status.py @@ -71,6 +71,9 @@ class StatusTestCase(PluginTestCase, PluginDocumentation): self.assertNotError('upkeep') self.assertNotError('logfile') + def testThreads(self): + self.assertNotError('threads') + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: