]> jfr.im git - erebus.git/blame - modules/resources.py
userinfo - use return-to-reply shortcut
[erebus.git] / modules / resources.py
CommitLineData
72137af7 1# Erebus IRC bot - Author: Erebus Team
4477123d 2# vim: fileencoding=utf-8
a62d0d18 3# resource-usage module
72137af7 4# This file is released into the public domain; see http://unlicense.org/
5
6# module info
7modinfo = {
8 'author': 'Erebus Team',
9 'license': 'public domain',
fa93b933 10 'compatible': [0],
a62d0d18 11 'depends': [],
12 'softdeps': ['help'],
72137af7 13}
14
15# preamble
16import modlib
17lib = modlib.modlib(__name__)
18modstart = lib.modstart
19modstop = lib.modstop
20
21# module code
22import resource
23
f5aec865 24@lib.hook(needchan=False, wantchan=True, glevel=lib.MANAGER)
5f03d045 25@lib.help(None, "show RAM usage")
fb20be7c 26def ram(bot, user, chan, realtarget, *args):
f5aec865 27 if chan is not None: replyto = chan
72137af7 28 else: replyto = user
29
30 try:
31 res = resource.getrusage(resource.RUSAGE_BOTH)
32 except:
33 res = resource.getrusage(resource.RUSAGE_SELF)
34
a8657439 35 bot.fastmsg(replyto, "Memory usage (MiB): %r" % (res.ru_maxrss/1024.0))
72137af7 36
f5aec865 37@lib.hook(needchan=False, wantchan=True, glevel=lib.MANAGER)
5f03d045 38@lib.help(None, "show resource usage")
fb20be7c 39def resources(bot, user, chan, realtarget, *args):
f5aec865 40 if chan is not None: replyto = chan
72137af7 41 else: replyto = user
42
43 try:
44 res = resource.getrusage(resource.RUSAGE_BOTH)
45 except:
46 res = resource.getrusage(resource.RUSAGE_SELF)
47
a8657439 48 bot.slowmsg(replyto, "Resource usage:")
10e2a6b9 49 for i, v in (
72137af7 50 ('utime (s)', res.ru_utime),
51 ('stime (s)', res.ru_stime),
10e2a6b9 52 ('memory (MiB)', (res.ru_maxrss/1024.0)),
72137af7 53 ('I/O (blocks)', res.ru_inblock+res.ru_oublock),
54 ('page faults', res.ru_majflt),
55 ('signals', res.ru_nsignals),
56 ('context switches (voluntary)', res.ru_nvcsw),
57 ('context switches (involuntary)', res.ru_nivcsw),
10e2a6b9 58 ):
a8657439 59 bot.slowmsg(replyto, "- %s: %r" % (i, v))
60 bot.slowmsg(replyto, "EOL.")