]> jfr.im git - erebus.git/blobdiff - modules/resources.py
update comments
[erebus.git] / modules / resources.py
index e5b7de1b02d063a5497cf197aca4412816a84bb3..5fc4309a9c135b5c90d0b97daa9c00a8129ec390 100644 (file)
@@ -1,5 +1,6 @@
 # Erebus IRC bot - Author: Erebus Team
-# resource-usage module
+# vim: fileencoding=utf-8
+# resource-usage reporting module
 # This file is released into the public domain; see http://unlicense.org/
 
 # module info
@@ -18,7 +19,7 @@ modstart = lib.modstart
 modstop = lib.modstop
 
 # module code
-import resource
+import resource, time
 
 @lib.hook(needchan=False, wantchan=True, glevel=lib.MANAGER)
 @lib.help(None, "show RAM usage")
@@ -39,6 +40,10 @@ def resources(bot, user, chan, realtarget, *args):
        if chan is not None: replyto = chan
        else: replyto = user
 
+       uptime = time.time() - bot.parent.starttime
+       m, s = divmod(uptime, 60)
+       h, m = divmod(m, 60)
+       d, h = divmod(h, 24)
        try:
                res = resource.getrusage(resource.RUSAGE_BOTH)
        except:
@@ -46,6 +51,7 @@ def resources(bot, user, chan, realtarget, *args):
 
        bot.slowmsg(replyto, "Resource usage:")
        for i, v in (
+               ('uptime (s)', "%d (%d days %02d:%02d:%02d)" % (uptime, d, h, m, s)),
                ('utime (s)', res.ru_utime),
                ('stime (s)', res.ru_stime),
                ('memory (MiB)', (res.ru_maxrss/1024.0)),
@@ -55,5 +61,5 @@ def resources(bot, user, chan, realtarget, *args):
                ('context switches (voluntary)', res.ru_nvcsw),
                ('context switches (involuntary)', res.ru_nivcsw),
        ):
-               bot.slowmsg(replyto, "- %s: %r" % (i, v))
+               bot.slowmsg(replyto, "- %s: %s" % (i, v))
        bot.slowmsg(replyto, "EOL.")