added support for optional printing of object instances and referrers, print types with small number of instances first

This commit is contained in:
Darren Ranalli 2007-11-14 01:53:21 +00:00
parent 50a3d5d0ac
commit 6907ad6543

View File

@ -13,15 +13,16 @@ class Diff:
def __init__(self, lost, gained): def __init__(self, lost, gained):
self.lost=lost self.lost=lost
self.gained=gained self.gained=gained
def printOut(self): def printOut(self, full=False):
print 'lost %s objects, gained %s objects' % (len(self.lost), len(self.gained)) print 'lost %s objects, gained %s objects' % (len(self.lost), len(self.gained))
print '\n\nself.lost\n' print '\n\nself.lost\n'
print self.lost.typeFreqStr() print self.lost.typeFreqStr()
print '\n\nself.gained\n' print '\n\nself.gained\n'
print self.gained.typeFreqStr() print self.gained.typeFreqStr()
self.gained.printObjsByType() if full:
print '\n\nGAINED-OBJECT REFERRERS\n' self.gained.printObjsByType()
self.gained.printReferrers(1) print '\n\nGAINED-OBJECT REFERRERS\n'
self.gained.printReferrers(1)
class ObjectPool: class ObjectPool:
"""manipulate a pool of Python objects""" """manipulate a pool of Python objects"""
@ -102,7 +103,9 @@ class ObjectPool:
print '\n============================' print '\n============================'
counts = list(set(self._count2types.keys())) counts = list(set(self._count2types.keys()))
counts.sort() counts.sort()
counts.reverse() # print types with the smallest number of instances first, in case
# there's a large group that waits a long time before printing
#counts.reverse()
for count in counts: for count in counts:
types = makeList(self._count2types[count]) types = makeList(self._count2types[count])
for typ in types: for typ in types: