X-Git-Url: https://jfr.im/git/erebus.git/blobdiff_plain/a62d0d18bbb5926d22df18db5eba53eb21a10817..c3ff1486929923f394c219e6999df301a5a5bf04:/modules/resources.py diff --git a/modules/resources.py b/modules/resources.py index 016e4bd..35136a8 100644 --- a/modules/resources.py +++ b/modules/resources.py @@ -1,4 +1,5 @@ # Erebus IRC bot - Author: Erebus Team +# vim: fileencoding=utf-8 # resource-usage module # This file is released into the public domain; see http://unlicense.org/ @@ -6,7 +7,7 @@ modinfo = { 'author': 'Erebus Team', 'license': 'public domain', - 'compatible': [1,2], + 'compatible': [0], 'depends': [], 'softdeps': ['help'], } @@ -18,12 +19,12 @@ modstart = lib.modstart modstop = lib.modstop # module code -import resource +import resource, time -@lib.hook(needchan=False, glevel=lib.MANAGER) +@lib.hook(needchan=False, wantchan=True, glevel=lib.MANAGER) @lib.help(None, "show RAM usage") def ram(bot, user, chan, realtarget, *args): - if chan is not None and realtarget == chan.name: replyto = chan + if chan is not None: replyto = chan else: replyto = user try: @@ -33,12 +34,16 @@ def ram(bot, user, chan, realtarget, *args): bot.fastmsg(replyto, "Memory usage (MiB): %r" % (res.ru_maxrss/1024.0)) -@lib.hook(needchan=False, glevel=lib.MANAGER) +@lib.hook(needchan=False, wantchan=True, glevel=lib.MANAGER) @lib.help(None, "show resource usage") def resources(bot, user, chan, realtarget, *args): - if chan is not None and realtarget == chan.name: replyto = chan + 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.")