mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
abbreviated garbage list printout, GarbageReport accepts timeslice param
This commit is contained in:
parent
8c616a75a9
commit
46cc183430
@ -21,11 +21,11 @@ class GarbageReport(TaskThreaded):
|
|||||||
NotGarbage = 'NG'
|
NotGarbage = 'NG'
|
||||||
|
|
||||||
def __init__(self, name, log=True, verbose=False, fullReport=False, findCycles=True,
|
def __init__(self, name, log=True, verbose=False, fullReport=False, findCycles=True,
|
||||||
threaded=False, doneCallback=None):
|
threaded=False, timeslice=None, doneCallback=None):
|
||||||
# if log is True, GarbageReport will self-destroy after logging
|
# if log is True, GarbageReport will self-destroy after logging
|
||||||
# if false, caller is responsible for calling destroy()
|
# if false, caller is responsible for calling destroy()
|
||||||
# if threaded is True, processing will be performed over multiple frames
|
# if threaded is True, processing will be performed over multiple frames
|
||||||
TaskThreaded.__init__(self, name, threaded)
|
TaskThreaded.__init__(self, name, threaded, timeslice=timeslice)
|
||||||
# stick the arguments onto a ScratchPad so we can access them from the thread
|
# stick the arguments onto a ScratchPad so we can access them from the thread
|
||||||
# functions and delete them all at once
|
# functions and delete them all at once
|
||||||
self._args = ScratchPad(name=name, log=log, verbose=verbose, fullReport=fullReport,
|
self._args = ScratchPad(name=name, log=log, verbose=verbose, fullReport=fullReport,
|
||||||
@ -57,6 +57,7 @@ class GarbageReport(TaskThreaded):
|
|||||||
|
|
||||||
self.cycles = []
|
self.cycles = []
|
||||||
self.cycleSets = []
|
self.cycleSets = []
|
||||||
|
self.cycleIds = set()
|
||||||
|
|
||||||
# grab the referrers (pointing to garbage)
|
# grab the referrers (pointing to garbage)
|
||||||
class GetReferrers(TaskThread):
|
class GetReferrers(TaskThread):
|
||||||
@ -116,6 +117,9 @@ class GarbageReport(TaskThreaded):
|
|||||||
def run(self):
|
def run(self):
|
||||||
for i in xrange(self.index, self.parent.numGarbage):
|
for i in xrange(self.index, self.parent.numGarbage):
|
||||||
self.parent.cycles.extend(self.parent._getCycles(i, self.parent.cycleSets))
|
self.parent.cycles.extend(self.parent._getCycles(i, self.parent.cycleSets))
|
||||||
|
# if we're not doing a full report, add this cycle's IDs to the master set
|
||||||
|
if not self.parent._args.fullReport:
|
||||||
|
self.parent.cycleIds.update(set(self.parent.cycles[-1]))
|
||||||
if (not (i & 0x0F)) and (not self.timeLeft()):
|
if (not (i & 0x0F)) and (not self.timeLeft()):
|
||||||
# we've run out of time, save the index
|
# we've run out of time, save the index
|
||||||
self.index = i+1
|
self.index = i+1
|
||||||
@ -133,11 +137,22 @@ class GarbageReport(TaskThreaded):
|
|||||||
else:
|
else:
|
||||||
self.curPhase = 0
|
self.curPhase = 0
|
||||||
self.index = 0
|
self.index = 0
|
||||||
|
# make a list of the ids we will actually be printing
|
||||||
|
if self.parent._args.fullReport:
|
||||||
|
self.garbageIds = range(self.parent.numGarbage)
|
||||||
|
else:
|
||||||
|
self.garbageIds = list(self.parent.cycleIds)
|
||||||
|
self.garbageIds.sort()
|
||||||
|
self.numGarbage = len(self.garbageIds)
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.curPhase == 0:
|
if self.curPhase == 0:
|
||||||
# log each individual item with a number in front of it
|
# log each individual item with a number in front of it
|
||||||
if self.index == 0:
|
if self.index == 0:
|
||||||
self.s.append('\n===== Garbage Items =====')
|
if not self.parent._args.fullReport:
|
||||||
|
abbrev = '(abbreviated) '
|
||||||
|
else:
|
||||||
|
abbrev = ''
|
||||||
|
self.s.append('\n===== Garbage Items %s=====' % abbrev)
|
||||||
digits = 0
|
digits = 0
|
||||||
n = self.parent.numGarbage
|
n = self.parent.numGarbage
|
||||||
while n > 0:
|
while n > 0:
|
||||||
@ -145,8 +160,9 @@ class GarbageReport(TaskThreaded):
|
|||||||
n /= 10
|
n /= 10
|
||||||
self.digits = digits
|
self.digits = digits
|
||||||
self.format = '%0' + '%s' % digits + 'i:%s \t%s'
|
self.format = '%0' + '%s' % digits + 'i:%s \t%s'
|
||||||
for i in xrange(self.index, self.parent.numGarbage):
|
for i in xrange(self.index, self.numGarbage):
|
||||||
self.s.append(self.format % (i, type(self.parent.garbage[i]), self.parent.garbage[i]))
|
id = self.garbageIds[i]
|
||||||
|
self.s.append(self.format % (id, type(self.parent.garbage[id]), self.parent.garbage[id]))
|
||||||
if (not (i & 0x7F)) and (not self.timeLeft()):
|
if (not (i & 0x7F)) and (not self.timeLeft()):
|
||||||
# we've run out of time, save the index
|
# we've run out of time, save the index
|
||||||
self.index = i+1
|
self.index = i+1
|
||||||
|
@ -9,10 +9,12 @@ class TaskThreaded:
|
|||||||
|
|
||||||
_Serial = SerialNum()
|
_Serial = SerialNum()
|
||||||
|
|
||||||
def __init__(self, name, threaded=True, timeslice=.01):
|
def __init__(self, name, threaded=True, timeslice=None):
|
||||||
# timeslice is how long this thread should take every frame.
|
# timeslice is how long this thread should take every frame.
|
||||||
self.__name = name
|
self.__name = name
|
||||||
self.__threaded=threaded
|
self.__threaded=threaded
|
||||||
|
if timeslice is None:
|
||||||
|
timeslice = .01
|
||||||
self.__timeslice = timeslice
|
self.__timeslice = timeslice
|
||||||
self.__taskNames = set()
|
self.__taskNames = set()
|
||||||
self._taskStartTime = None
|
self._taskStartTime = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user