more info in stats

This commit is contained in:
Josh Wilson 2010-08-02 16:43:15 +00:00
parent 40cb319ad1
commit 1d6518f65d

View File

@ -9,8 +9,9 @@ class ReferrerSearch(Job):
Job.__init__(self, 'ReferrerSearch') Job.__init__(self, 'ReferrerSearch')
self.obj = obj self.obj = obj
self.maxRefs = maxRefs self.maxRefs = maxRefs
self.found = set() self.visited = set()
self.depth = 0 self.depth = 0
self.found = 0
self.shouldPrintStats = False self.shouldPrintStats = False
def __call__(self): def __call__(self):
@ -18,7 +19,7 @@ class ReferrerSearch(Job):
info = safeReprNotify.getInfo() info = safeReprNotify.getInfo()
safeReprNotify.setInfo(0) safeReprNotify.setInfo(0)
self.found = set() self.visited = set()
try: try:
self.step(0, [self.obj]) self.step(0, [self.obj])
finally: finally:
@ -35,7 +36,7 @@ class ReferrerSearch(Job):
print 'RefPath(%s): Beginning ReferrerSearch for %s' %(self._id, fastRepr(self.obj)) print 'RefPath(%s): Beginning ReferrerSearch for %s' %(self._id, fastRepr(self.obj))
self.found = set() self.visited = set()
for x in self.stepGenerator(0, [self.obj]): for x in self.stepGenerator(0, [self.obj]):
yield None yield None
pass pass
@ -97,16 +98,17 @@ class ReferrerSearch(Job):
at = path[-1] at = path[-1]
if id(at) in self.found: if id(at) in self.visited:
# don't continue down this path # don't continue down this path
return return
# check for success # check for success
if (self.isAtRoot(at, path)): if (self.isAtRoot(at, path)):
self.found += 1
return return
# mark our progress after checking goal # mark our progress after checking goal
self.found.add(id(at)) self.visited.add(id(at))
referrers = [ref for ref in gc.get_referrers(at) \ referrers = [ref for ref in gc.get_referrers(at) \
if not (ref is path or \ if not (ref is path or \
@ -114,7 +116,7 @@ class ReferrerSearch(Job):
(isinstance(ref, dict) and \ (isinstance(ref, dict) and \
ref.keys() == locals().keys()) or \ ref.keys() == locals().keys()) or \
ref is self.__dict__ or \ ref is self.__dict__ or \
id(ref) in self.found) ] id(ref) in self.visited) ]
if (self.isManyRef(at, path, referrers)): if (self.isManyRef(at, path, referrers)):
return return
@ -136,16 +138,17 @@ class ReferrerSearch(Job):
at = path[-1] at = path[-1]
if id(at) in self.found: if id(at) in self.visited:
# don't continue down this path # don't continue down this path
raise StopIteration raise StopIteration
# check for success # check for success
if (self.isAtRoot(at, path)): if (self.isAtRoot(at, path)):
self.found += 1
raise StopIteration raise StopIteration
# mark our progress after checking goal # mark our progress after checking goal
self.found.add(id(at)) self.visited.add(id(at))
referrers = [ref for ref in gc.get_referrers(at) \ referrers = [ref for ref in gc.get_referrers(at) \
if not (ref is path or \ if not (ref is path or \
@ -153,7 +156,7 @@ class ReferrerSearch(Job):
(isinstance(ref, dict) and \ (isinstance(ref, dict) and \
ref.keys() == locals().keys()) or \ ref.keys() == locals().keys()) or \
ref is self.__dict__ or \ ref is self.__dict__ or \
id(ref) in self.found) ] id(ref) in self.visited) ]
if (self.isManyRef(at, path, referrers)): if (self.isManyRef(at, path, referrers)):
raise StopIteration raise StopIteration
@ -173,8 +176,8 @@ class ReferrerSearch(Job):
def printStats(self, path): def printStats(self, path):
path = list(reversed(path)) path = list(reversed(path))
path.insert(0,0) path.insert(0,0)
print 'RefPath(%s) - Stats - found(%s) | depth(%s) | CurrentPath(%s)' % \ print 'RefPath(%s) - Stats - visited(%s) | found(%s) | depth(%s) | CurrentPath(%s)' % \
(self._id, len(self.found), self.depth, ''.join(self.myrepr(path[x], path[x+1]) for x in xrange(len(path)-1))) (self._id, len(self.visited), self.found, self.depth, ''.join(self.myrepr(path[x], path[x+1]) for x in xrange(len(path)-1)))
pass pass
def isAtRoot(self, at, path): def isAtRoot(self, at, path):