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