mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
itemize intervals in pstats
This commit is contained in:
parent
e829db1d60
commit
c9b1445b7c
@ -5,8 +5,9 @@ __all__ = ['Interval']
|
|||||||
from direct.directnotify.DirectNotifyGlobal import directNotify
|
from direct.directnotify.DirectNotifyGlobal import directNotify
|
||||||
from direct.showbase.DirectObject import DirectObject
|
from direct.showbase.DirectObject import DirectObject
|
||||||
from pandac.PandaModules import *
|
from pandac.PandaModules import *
|
||||||
from direct.task import Task
|
from direct.task.Task import Task, TaskManager
|
||||||
from direct.showbase import PythonUtil
|
from direct.showbase import PythonUtil
|
||||||
|
from pandac.PandaModules import *
|
||||||
import math
|
import math
|
||||||
|
|
||||||
class Interval(DirectObject):
|
class Interval(DirectObject):
|
||||||
@ -33,6 +34,11 @@ class Interval(DirectObject):
|
|||||||
self.__doLoop = 0
|
self.__doLoop = 0
|
||||||
self.__loopCount = 0
|
self.__loopCount = 0
|
||||||
|
|
||||||
|
self.pstats = None
|
||||||
|
if __debug__ and TaskManager.taskTimerVerbose:
|
||||||
|
self.pname = name.split('-', 1)[0]
|
||||||
|
self.pstats = PStatCollector("App:Show code:ivalLoop:%s" % (self.pname))
|
||||||
|
|
||||||
# Set true if the interval should be invoked if it was
|
# Set true if the interval should be invoked if it was
|
||||||
# completely skipped over during initialize or finalize, false
|
# completely skipped over during initialize or finalize, false
|
||||||
# if it should be ignored in this case.
|
# if it should be ignored in this case.
|
||||||
@ -171,6 +177,8 @@ class Interval(DirectObject):
|
|||||||
return self.doneEvent
|
return self.doneEvent
|
||||||
|
|
||||||
def privDoEvent(self, t, event):
|
def privDoEvent(self, t, event):
|
||||||
|
if self.pstats:
|
||||||
|
self.pstats.start()
|
||||||
if event == CInterval.ETStep:
|
if event == CInterval.ETStep:
|
||||||
self.privStep(t)
|
self.privStep(t)
|
||||||
elif event == CInterval.ETFinalize:
|
elif event == CInterval.ETFinalize:
|
||||||
@ -189,6 +197,8 @@ class Interval(DirectObject):
|
|||||||
self.privReverseInitialize(t)
|
self.privReverseInitialize(t)
|
||||||
else:
|
else:
|
||||||
self.notify.error('Invalid event type: %s' % (event))
|
self.notify.error('Invalid event type: %s' % (event))
|
||||||
|
if self.pstats:
|
||||||
|
self.pstats.stop()
|
||||||
|
|
||||||
|
|
||||||
def privInitialize(self, t):
|
def privInitialize(self, t):
|
||||||
@ -344,17 +354,20 @@ class Interval(DirectObject):
|
|||||||
def privPostEvent(self):
|
def privPostEvent(self):
|
||||||
# Call after calling any of the priv* methods to do any required
|
# Call after calling any of the priv* methods to do any required
|
||||||
# Python finishing steps.
|
# Python finishing steps.
|
||||||
|
if self.pstats:
|
||||||
|
self.pstats.start()
|
||||||
t = self.getT()
|
t = self.getT()
|
||||||
if hasattr(self, "setTHooks"):
|
if hasattr(self, "setTHooks"):
|
||||||
for func in self.setTHooks:
|
for func in self.setTHooks:
|
||||||
func(t)
|
func(t)
|
||||||
|
if self.pstats:
|
||||||
|
self.pstats.stop()
|
||||||
|
|
||||||
def __spawnTask(self):
|
def __spawnTask(self):
|
||||||
# Spawn task
|
# Spawn task
|
||||||
from direct.task import Task
|
|
||||||
self.__removeTask()
|
self.__removeTask()
|
||||||
taskName = self.getName() + '-play'
|
taskName = self.getName() + '-play'
|
||||||
task = Task.Task(self.__playTask)
|
task = Task(self.__playTask)
|
||||||
task.interval = self
|
task.interval = self
|
||||||
taskMgr.add(task, taskName)
|
taskMgr.add(task, taskName)
|
||||||
|
|
||||||
@ -369,7 +382,6 @@ class Interval(DirectObject):
|
|||||||
taskMgr.remove(task)
|
taskMgr.remove(task)
|
||||||
|
|
||||||
def __playTask(self, task):
|
def __playTask(self, task):
|
||||||
from direct.task import Task
|
|
||||||
again = self.stepPlay()
|
again = self.stepPlay()
|
||||||
self.privPostEvent()
|
self.privPostEvent()
|
||||||
if again:
|
if again:
|
||||||
|
@ -17,50 +17,21 @@ class IntervalManager(CIntervalManager):
|
|||||||
# the Python extensions is to add support for Python-based
|
# the Python extensions is to add support for Python-based
|
||||||
# intervals (like MetaIntervals).
|
# intervals (like MetaIntervals).
|
||||||
|
|
||||||
if PandaModules.__dict__.has_key("Dtool_PyNavtiveInterface"):
|
def __init__(self, globalPtr = 0):
|
||||||
def __init__(self, globalPtr = 0):
|
# Pass globalPtr == 1 to the constructor to trick it into
|
||||||
# Pass globalPtr == 1 to the constructor to trick it into
|
# "constructing" a Python wrapper around the global
|
||||||
# "constructing" a Python wrapper around the global
|
# CIntervalManager object.
|
||||||
# CIntervalManager object.
|
if globalPtr:
|
||||||
##self.cObj = CIntervalManager.getGlobalPtr()
|
self.cObj = CIntervalManager.getGlobalPtr()
|
||||||
##Dtool_BarrowThisRefrence(self, self.cObj)
|
Dtool_BorrowThisReference(self, self.cObj)
|
||||||
##self.dd = self
|
self.dd = self
|
||||||
if globalPtr:
|
else:
|
||||||
self.cObj = CIntervalManager.getGlobalPtr()
|
CIntervalManager.__init__(self)
|
||||||
# Temporary try..except for old Panda.
|
self.eventQueue = EventQueue()
|
||||||
try:
|
self.MyEventmanager = EventManager.EventManager(self.eventQueue)
|
||||||
Dtool_BorrowThisReference(self, self.cObj)
|
self.setEventQueue(self.eventQueue)
|
||||||
except:
|
self.ivals = []
|
||||||
Dtool_BarrowThisRefrence(self, self.cObj)
|
self.removedIvals = {}
|
||||||
self.dd = self
|
|
||||||
else:
|
|
||||||
CIntervalManager.__init__(self)
|
|
||||||
self.eventQueue = EventQueue()
|
|
||||||
self.MyEventmanager = EventManager.EventManager(self.eventQueue)
|
|
||||||
self.setEventQueue(self.eventQueue)
|
|
||||||
self.ivals = []
|
|
||||||
self.removedIvals = {}
|
|
||||||
else: ## the old interface
|
|
||||||
def __init__(self, globalPtr = 0):
|
|
||||||
# Pass globalPtr == 1 to the constructor to trick it into
|
|
||||||
# "constructing" a Python wrapper around the global
|
|
||||||
# CIntervalManager object.
|
|
||||||
if globalPtr:
|
|
||||||
#CIntervalManager.__init__(self, None)
|
|
||||||
cObj = CIntervalManager.getGlobalPtr()
|
|
||||||
self.this = cObj.this
|
|
||||||
self.userManagesMemory = 0
|
|
||||||
else:
|
|
||||||
CIntervalManager.__init__(self)
|
|
||||||
# Set up a custom event queue for handling C++ events from
|
|
||||||
# intervals.
|
|
||||||
self.eventQueue = EventQueue()
|
|
||||||
self.MyEventmanager = EventManager.EventManager(self.eventQueue)
|
|
||||||
self.setEventQueue(self.eventQueue)
|
|
||||||
self.ivals = []
|
|
||||||
self.removedIvals = {}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def addInterval(self, interval):
|
def addInterval(self, interval):
|
||||||
index = self.addCInterval(interval, 1)
|
index = self.addCInterval(interval, 1)
|
||||||
@ -154,10 +125,6 @@ class IntervalManager(CIntervalManager):
|
|||||||
assert self.ivals[index] == None or self.ivals[index] == interval
|
assert self.ivals[index] == None or self.ivals[index] == interval
|
||||||
self.ivals[index] = interval
|
self.ivals[index] = interval
|
||||||
|
|
||||||
|
|
||||||
#def __repr__(self):
|
|
||||||
# return self.__str__()
|
|
||||||
|
|
||||||
# The global IntervalManager object.
|
# The global IntervalManager object.
|
||||||
ivalMgr = IntervalManager(1)
|
ivalMgr = IntervalManager(1)
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ from pandac.PandaModules import *
|
|||||||
from direct.directnotify.DirectNotifyGlobal import *
|
from direct.directnotify.DirectNotifyGlobal import *
|
||||||
from IntervalManager import ivalMgr
|
from IntervalManager import ivalMgr
|
||||||
import Interval
|
import Interval
|
||||||
from direct.task import Task
|
from direct.task.Task import Task, TaskManager
|
||||||
import types
|
import types
|
||||||
if __debug__:
|
if __debug__:
|
||||||
import direct.showbase.PythonUtil as PythonUtil
|
import direct.showbase.PythonUtil as PythonUtil
|
||||||
@ -97,6 +97,11 @@ class MetaInterval(CMetaInterval):
|
|||||||
self.setAutoPause(autoPause)
|
self.setAutoPause(autoPause)
|
||||||
self.setAutoFinish(autoFinish)
|
self.setAutoFinish(autoFinish)
|
||||||
|
|
||||||
|
self.pstats = None
|
||||||
|
if __debug__ and TaskManager.taskTimerVerbose:
|
||||||
|
self.pname = name.split('-', 1)[0]
|
||||||
|
self.pstats = PStatCollector("App:Show code:ivalLoop:%s" % (self.pname))
|
||||||
|
|
||||||
self.pythonIvals = []
|
self.pythonIvals = []
|
||||||
|
|
||||||
# If we are running in debug mode, we validate the intervals
|
# If we are running in debug mode, we validate the intervals
|
||||||
@ -319,6 +324,8 @@ class MetaInterval(CMetaInterval):
|
|||||||
# It's a Python-style Interval, so add it as an external.
|
# It's a Python-style Interval, so add it as an external.
|
||||||
index = len(self.pythonIvals)
|
index = len(self.pythonIvals)
|
||||||
self.pythonIvals.append(ival)
|
self.pythonIvals.append(ival)
|
||||||
|
if self.pstats:
|
||||||
|
ival.pstats = PStatCollector(self.pstats, ival.pname)
|
||||||
self.addExtIndex(index, ival.getName(), ival.getDuration(),
|
self.addExtIndex(index, ival.getName(), ival.getDuration(),
|
||||||
ival.getOpenEnded(), relTime, relTo)
|
ival.getOpenEnded(), relTime, relTo)
|
||||||
|
|
||||||
@ -482,12 +489,20 @@ class MetaInterval(CMetaInterval):
|
|||||||
def privDoEvent(self, t, event):
|
def privDoEvent(self, t, event):
|
||||||
# This function overrides the C++ function to initialize the
|
# This function overrides the C++ function to initialize the
|
||||||
# intervals first if necessary.
|
# intervals first if necessary.
|
||||||
|
if self.pstats:
|
||||||
|
self.pstats.start()
|
||||||
self.__updateIvals()
|
self.__updateIvals()
|
||||||
CMetaInterval.privDoEvent(self, t, event)
|
CMetaInterval.privDoEvent(self, t, event)
|
||||||
|
if self.pstats:
|
||||||
|
self.pstats.stop()
|
||||||
|
|
||||||
def privPostEvent(self):
|
def privPostEvent(self):
|
||||||
|
if self.pstats:
|
||||||
|
self.pstats.start()
|
||||||
self.__doPythonCallbacks()
|
self.__doPythonCallbacks()
|
||||||
CMetaInterval.privPostEvent(self)
|
CMetaInterval.privPostEvent(self)
|
||||||
|
if self.pstats:
|
||||||
|
self.pstats.stop()
|
||||||
|
|
||||||
def setIntervalStartTime(self, *args, **kw):
|
def setIntervalStartTime(self, *args, **kw):
|
||||||
# This function overrides from the parent level to force it to
|
# This function overrides from the parent level to force it to
|
||||||
|
@ -22,10 +22,21 @@
|
|||||||
#include "clockObject.h"
|
#include "clockObject.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "eventQueue.h"
|
#include "eventQueue.h"
|
||||||
#include <math.h>
|
#include "pStatTimer.h"
|
||||||
|
|
||||||
|
PStatCollector CInterval::_root_pcollector("App:Show code:ivalLoop");
|
||||||
TypeHandle CInterval::_type_handle;
|
TypeHandle CInterval::_type_handle;
|
||||||
|
|
||||||
|
static inline string
|
||||||
|
get_pstats_name(const string &name) {
|
||||||
|
string pname = name;
|
||||||
|
size_t hyphen = pname.find('-');
|
||||||
|
if (hyphen != string::npos) {
|
||||||
|
pname = pname.substr(0, hyphen);
|
||||||
|
}
|
||||||
|
return pname;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: CInterval::Constructor
|
// Function: CInterval::Constructor
|
||||||
// Access: Public
|
// Access: Public
|
||||||
@ -36,9 +47,11 @@ CInterval(const string &name, double duration, bool open_ended) :
|
|||||||
_state(S_initial),
|
_state(S_initial),
|
||||||
_curr_t(0.0),
|
_curr_t(0.0),
|
||||||
_name(name),
|
_name(name),
|
||||||
|
_pname(get_pstats_name(name)),
|
||||||
_duration(max(duration, 0.0)),
|
_duration(max(duration, 0.0)),
|
||||||
_open_ended(open_ended),
|
_open_ended(open_ended),
|
||||||
_dirty(false)
|
_dirty(false),
|
||||||
|
_ival_pcollector(_root_pcollector, _pname)
|
||||||
{
|
{
|
||||||
_auto_pause = false;
|
_auto_pause = false;
|
||||||
_auto_finish = false;
|
_auto_finish = false;
|
||||||
@ -283,6 +296,7 @@ is_playing() const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void CInterval::
|
void CInterval::
|
||||||
priv_do_event(double t, EventType event) {
|
priv_do_event(double t, EventType event) {
|
||||||
|
PStatTimer timer(_ival_pcollector);
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case ET_initialize:
|
case ET_initialize:
|
||||||
priv_initialize(t);
|
priv_initialize(t);
|
||||||
@ -497,6 +511,7 @@ void CInterval::
|
|||||||
setup_play(double start_t, double end_t, double play_rate, bool do_loop) {
|
setup_play(double start_t, double end_t, double play_rate, bool do_loop) {
|
||||||
nassertv(start_t < end_t || end_t < 0.0);
|
nassertv(start_t < end_t || end_t < 0.0);
|
||||||
nassertv(play_rate != 0.0);
|
nassertv(play_rate != 0.0);
|
||||||
|
PStatTimer timer(_ival_pcollector);
|
||||||
|
|
||||||
double duration = get_duration();
|
double duration = get_duration();
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "typedReferenceCount.h"
|
#include "typedReferenceCount.h"
|
||||||
#include "pvector.h"
|
#include "pvector.h"
|
||||||
#include "config_interval.h"
|
#include "config_interval.h"
|
||||||
|
#include "pStatCollector.h"
|
||||||
|
|
||||||
class CIntervalManager;
|
class CIntervalManager;
|
||||||
|
|
||||||
@ -139,6 +140,7 @@ protected:
|
|||||||
State _state;
|
State _state;
|
||||||
double _curr_t;
|
double _curr_t;
|
||||||
string _name;
|
string _name;
|
||||||
|
string _pname;
|
||||||
string _done_event;
|
string _done_event;
|
||||||
double _duration;
|
double _duration;
|
||||||
|
|
||||||
@ -168,6 +170,9 @@ private:
|
|||||||
// dirty.
|
// dirty.
|
||||||
typedef pvector<CInterval *> Parents;
|
typedef pvector<CInterval *> Parents;
|
||||||
Parents _parents;
|
Parents _parents;
|
||||||
|
|
||||||
|
static PStatCollector _root_pcollector;
|
||||||
|
PStatCollector _ival_pcollector;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static TypeHandle get_class_type() {
|
static TypeHandle get_class_type() {
|
||||||
|
@ -144,6 +144,7 @@ add_c_interval(CInterval *c_interval,
|
|||||||
nassertr(c_interval != (CInterval *)NULL, -1);
|
nassertr(c_interval != (CInterval *)NULL, -1);
|
||||||
|
|
||||||
c_interval->_parents.push_back(this);
|
c_interval->_parents.push_back(this);
|
||||||
|
c_interval->_ival_pcollector = PStatCollector(_ival_pcollector, c_interval->_pname);
|
||||||
_defs.push_back(IntervalDef());
|
_defs.push_back(IntervalDef());
|
||||||
IntervalDef &def = _defs.back();
|
IntervalDef &def = _defs.back();
|
||||||
def._type = DT_c_interval;
|
def._type = DT_c_interval;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user