mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
working frame profiler
This commit is contained in:
parent
81b8b3165e
commit
e757a0b769
@ -103,9 +103,9 @@ class ProfileSession:
|
||||
# if true, accumulate profile results every time we run
|
||||
# if false, throw out old results every time we run
|
||||
self._aggregate = False
|
||||
self._lines = 200
|
||||
self._lines = 500
|
||||
self._sorts = ['cumulative', 'time', 'calls']
|
||||
self._callInfo = False
|
||||
self._callInfo = True
|
||||
self._totalTime = None
|
||||
self._reset()
|
||||
self.acquire()
|
||||
|
@ -42,6 +42,7 @@ class FrameProfiler:
|
||||
|
||||
def _setEnabled(self, enabled):
|
||||
if enabled:
|
||||
self.notify.info('frame profiler started')
|
||||
self._startTime = globalClock.getFrameTime()
|
||||
self._profileCounter = 0
|
||||
self._jitter = None
|
||||
@ -59,6 +60,7 @@ class FrameProfiler:
|
||||
if self._lastSession:
|
||||
self._lastSession.release()
|
||||
del self._lastSession
|
||||
self.notify.info('frame profiler stopped')
|
||||
|
||||
def _startProfiling(self, task):
|
||||
self._scheduleNextProfile()
|
||||
@ -89,27 +91,40 @@ class FrameProfiler:
|
||||
'FrameProfiler-%s' % serialNum())
|
||||
|
||||
def _frameProfileTask(self, task):
|
||||
p2ap = self._period2aggregateProfile
|
||||
|
||||
if self._lastSession:
|
||||
p2ap = self._period2aggregateProfile
|
||||
# always add this profile to the first aggregated profile
|
||||
period = self._logSchedule[0]
|
||||
if period not in self._period2aggregateProfile:
|
||||
self._lastSession.setLines(500)
|
||||
p2ap[period] = self._lastSession.getReference()
|
||||
if self._lastSession.profileSucceeded():
|
||||
# always add this profile to the first aggregated profile
|
||||
period = self._logSchedule[0]
|
||||
if period not in self._period2aggregateProfile:
|
||||
p2ap[period] = self._lastSession.getReference()
|
||||
else:
|
||||
p2ap[period].aggregate(self._lastSession)
|
||||
else:
|
||||
p2ap[period].aggregate(self._lastSession)
|
||||
# log profiles when it's time, and aggregate them upwards into the
|
||||
# next-larger profile
|
||||
for period in self._logSchedule:
|
||||
if (self._timeElapsed % period) == 0:
|
||||
ap = p2ap[period]
|
||||
self.notify.warning('frame profile did not succeed')
|
||||
|
||||
# always release the last-recorded profile
|
||||
self._lastSession.release()
|
||||
self._lastSession = None
|
||||
|
||||
# log profiles when it's time, and aggregate them upwards into the
|
||||
# next-longer profile
|
||||
for pi in xrange(len(self._logSchedule)):
|
||||
period = self._logSchedule[pi]
|
||||
if (self._timeElapsed % period) == 0:
|
||||
if period in p2ap:
|
||||
self.notify.info('aggregate profile of sampled frames over last %s\n%s' %
|
||||
(formatTimeExact(period), ap.getResults()))
|
||||
(formatTimeExact(period), p2ap[period].getResults()))
|
||||
# aggregate this profile into the next larger profile
|
||||
nextPeriod = period * 2
|
||||
# make sure the next larger log period is in the schedule
|
||||
if period == self._logSchedule[-1]:
|
||||
nextIndex = pi + 1
|
||||
if nextIndex >= len(self._logSchedule):
|
||||
# if we're adding a new period to the end of the log period table,
|
||||
# set it to double the duration of the current longest period
|
||||
nextPeriod = period * 2
|
||||
self._logSchedule.append(nextPeriod)
|
||||
else:
|
||||
nextPeriod = self._logSchedule[nextIndex]
|
||||
if nextPeriod not in p2ap:
|
||||
p2ap[nextPeriod] = p2ap[period].getReference()
|
||||
else:
|
||||
@ -118,14 +133,10 @@ class FrameProfiler:
|
||||
# throw it out
|
||||
p2ap[period].release()
|
||||
del p2ap[period]
|
||||
else:
|
||||
# current time is not divisible evenly into selected period, and all higher
|
||||
# periods are multiples of this one
|
||||
break
|
||||
|
||||
# always release the last-recorded profile
|
||||
self._lastSession.release()
|
||||
self._lastSession = None
|
||||
else:
|
||||
# current time is not divisible evenly into selected period, and all higher
|
||||
# periods are multiples of this one
|
||||
break
|
||||
|
||||
self._scheduleNextProfile()
|
||||
return task.done
|
||||
|
@ -123,11 +123,13 @@ class TaskProfiler:
|
||||
|
||||
def _setEnabled(self, enabled):
|
||||
if enabled:
|
||||
self.notify.info('task profiler started')
|
||||
self._taskName = 'profile-tasks-%s' % id(self)
|
||||
taskMgr.add(self._doProfileTasks, self._taskName, priority=-200)
|
||||
else:
|
||||
taskMgr.remove(self._taskName)
|
||||
del self._taskName
|
||||
self.notify.info('task profiler stopped')
|
||||
|
||||
def _doProfileTasks(self, task=None):
|
||||
# gather data from the previous frame
|
||||
|
Loading…
x
Reference in New Issue
Block a user