Added a semi-accurate refcount measure to objects.

This commit is contained in:
Jeremy Fincher 2003-08-11 05:06:41 +00:00
parent 0cf850dfc1
commit 1bbcfa9a5e

View File

@ -486,6 +486,7 @@ class FunCommands(callbacks.Privmsg):
dicts = 0 dicts = 0
lists = 0 lists = 0
tuples = 0 tuples = 0
refcounts = 0
objs = gc.get_objects() objs = gc.get_objects()
for obj in objs: for obj in objs:
if isinstance(obj, tuple): if isinstance(obj, tuple):
@ -500,11 +501,12 @@ class FunCommands(callbacks.Privmsg):
classes += 1 classes += 1
elif inspect.ismodule(obj): elif inspect.ismodule(obj):
modules += 1 modules += 1
refcounts += sys.getrefcount(obj)
response = 'I have %s objects: %s modules, %s classes, %s functions, '\ response = 'I have %s objects: %s modules, %s classes, %s functions, '\
'%s dictionaries, %s lists, and %s tuples (and a few other'\ '%s dictionaries, %s lists, and %s tuples (and a few other'\
' different types).' %\ ' different types). I have a total of %s references.' %\
(len(objs), modules, classes, functions, (len(objs), modules, classes, functions,
dicts, lists, tuples) dicts, lists, tuples, refcounts)
irc.reply(msg, response) irc.reply(msg, response)
def last(self, irc, msg, args): def last(self, irc, msg, args):