]>
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 def ram(bot
, user
, chan
, realtarget
, *args
):
24 if chan
is not None and realtarget
== chan
.name
: replyto
= chan
28 res
= resource
.getrusage(resource
.RUSAGE_BOTH
)
30 res
= resource
.getrusage(resource
.RUSAGE_SELF
)
32 bot
.msg(replyto
, "Memory usage (MiB): %r" % (res
.ru_maxrss
/1024.0))
34 @lib.hook(needchan
=False, glevel
=lib
.MANAGER
)
35 def resources(bot
, user
, chan
, realtarget
, *args
):
36 if chan
is not None and realtarget
== chan
.name
: replyto
= chan
40 res
= resource
.getrusage(resource
.RUSAGE_BOTH
)
42 res
= resource
.getrusage(resource
.RUSAGE_SELF
)
44 bot
.msg(replyto
, "Resource usage:")
46 ('utime (s)', res
.ru_utime
),
47 ('stime (s)', res
.ru_stime
),
48 ('memory (MiB)', (res
.ru_maxrss
/1024.0))
49 ('I/O (blocks)', res
.ru_inblock
+res
.ru_oublock
),
50 ('page faults', res
.ru_majflt
),
51 ('signals', res
.ru_nsignals
),
52 ('context switches (voluntary)', res
.ru_nvcsw
),
53 ('context switches (involuntary)', res
.ru_nivcsw
),
55 bot
.msg(replyto
, "- %s: %r" % (i
, v
))
56 bot
.msg(replyto
, "EOL.")