]>
jfr.im git - erebus.git/blob - modules/resources.py
1 # Erebus IRC bot - Author: Erebus Team
2 # simple module example
3 # This file is released into the public domain; see http://unlicense.org/
7 'author': 'Erebus Team',
8 'license': 'public domain',
9 'compatible': [1], # compatible module API versions
10 'depends': [], # other modules required to work properly?
15 lib
= modlib
.modlib(__name__
)
16 modstart
= lib
.modstart
22 @lib.hook(needchan
=False, glevel
=lib
.MANAGER
)
23 @lib.help(None, "show RAM usage")
24 def ram(bot
, user
, chan
, realtarget
, *args
):
25 if chan
is not None and realtarget
== chan
.name
: replyto
= chan
29 res
= resource
.getrusage(resource
.RUSAGE_BOTH
)
31 res
= resource
.getrusage(resource
.RUSAGE_SELF
)
33 bot
.fastmsg(replyto
, "Memory usage (MiB): %r" % (res
.ru_maxrss
/1024.0))
35 @lib.hook(needchan
=False, glevel
=lib
.MANAGER
)
36 @lib.help(None, "show resource usage")
37 def resources(bot
, user
, chan
, realtarget
, *args
):
38 if chan
is not None and realtarget
== chan
.name
: replyto
= chan
42 res
= resource
.getrusage(resource
.RUSAGE_BOTH
)
44 res
= resource
.getrusage(resource
.RUSAGE_SELF
)
46 bot
.slowmsg(replyto
, "Resource usage:")
48 ('utime (s)', res
.ru_utime
),
49 ('stime (s)', res
.ru_stime
),
50 ('memory (MiB)', (res
.ru_maxrss
/1024.0)),
51 ('I/O (blocks)', res
.ru_inblock
+res
.ru_oublock
),
52 ('page faults', res
.ru_majflt
),
53 ('signals', res
.ru_nsignals
),
54 ('context switches (voluntary)', res
.ru_nvcsw
),
55 ('context switches (involuntary)', res
.ru_nivcsw
),
57 bot
.slowmsg(replyto
, "- %s: %r" % (i
, v
))
58 bot
.slowmsg(replyto
, "EOL.")