mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-18 12:43:44 -04:00
added pstats-eventmanager config
This commit is contained in:
parent
99b64f5e9d
commit
77a4ea9542
@ -13,6 +13,8 @@ from direct.task.Task import Task
|
|||||||
# downloaded.
|
# downloaded.
|
||||||
#from pandac.PandaModules import *
|
#from pandac.PandaModules import *
|
||||||
|
|
||||||
|
from pandac.PandaModules import PStatCollector
|
||||||
|
|
||||||
class EventManager:
|
class EventManager:
|
||||||
|
|
||||||
notify = None
|
notify = None
|
||||||
@ -33,12 +35,22 @@ class EventManager:
|
|||||||
self.eventQueue = eventQueue
|
self.eventQueue = eventQueue
|
||||||
self.eventHandler = None
|
self.eventHandler = None
|
||||||
|
|
||||||
|
self._wantPstats = None # no config at this point
|
||||||
|
|
||||||
def doEvents(self):
|
def doEvents(self):
|
||||||
"""
|
"""
|
||||||
Process all the events on the C++ event queue
|
Process all the events on the C++ event queue
|
||||||
"""
|
"""
|
||||||
|
if self._wantPstats is None:
|
||||||
|
self._wantPstats = config.GetBool('pstats-eventmanager', 0)
|
||||||
|
# use different methods for handling events with and without pstats tracking
|
||||||
|
# for efficiency
|
||||||
|
if self._wantPstats:
|
||||||
|
processFunc = self.processEventPstats
|
||||||
|
else:
|
||||||
|
processFunc = self.processEvent
|
||||||
while (not self.eventQueue.isQueueEmpty()):
|
while (not self.eventQueue.isQueueEmpty()):
|
||||||
self.processEvent(self.eventQueue.dequeueEvent())
|
processFunc(self.eventQueue.dequeueEvent())
|
||||||
|
|
||||||
def eventLoopTask(self, task):
|
def eventLoopTask(self, task):
|
||||||
"""
|
"""
|
||||||
@ -79,7 +91,48 @@ class EventManager:
|
|||||||
def processEvent(self, event):
|
def processEvent(self, event):
|
||||||
"""
|
"""
|
||||||
Process a C++ event
|
Process a C++ event
|
||||||
|
Duplicate any changes in processEventPstats
|
||||||
"""
|
"""
|
||||||
|
# **************************************************************
|
||||||
|
# ******** Duplicate any changes in processEventPstats *********
|
||||||
|
# **************************************************************
|
||||||
|
# Get the event name
|
||||||
|
eventName = event.getName()
|
||||||
|
if eventName:
|
||||||
|
paramList = []
|
||||||
|
for i in range(event.getNumParameters()):
|
||||||
|
eventParameter = event.getParameter(i)
|
||||||
|
eventParameterData = self.parseEventParameter(eventParameter)
|
||||||
|
paramList.append(eventParameterData)
|
||||||
|
# Do not print the new frame debug, it is too noisy!
|
||||||
|
if (EventManager.notify.getDebug() and eventName != 'NewFrame'):
|
||||||
|
EventManager.notify.debug('received C++ event named: ' + eventName +
|
||||||
|
' parameters: ' + `paramList`)
|
||||||
|
# **************************************************************
|
||||||
|
# ******** Duplicate any changes in processEventPstats *********
|
||||||
|
# **************************************************************
|
||||||
|
# Send the event, we used to send it with the event
|
||||||
|
# name as a parameter, but now you can use extraArgs for that
|
||||||
|
if paramList:
|
||||||
|
messenger.send(eventName, paramList)
|
||||||
|
else:
|
||||||
|
messenger.send(eventName)
|
||||||
|
# Also send the event down into C++ land
|
||||||
|
if self.eventHandler:
|
||||||
|
self.eventHandler.dispatchEvent(event)
|
||||||
|
|
||||||
|
else:
|
||||||
|
# An unnamed event from C++ is probably a bad thing
|
||||||
|
EventManager.notify.warning('unnamed event in processEvent')
|
||||||
|
|
||||||
|
def processEventPstats(self, event):
|
||||||
|
"""
|
||||||
|
Process a C++ event with pstats tracking
|
||||||
|
Duplicate any changes in processEvent
|
||||||
|
"""
|
||||||
|
# ********************************************************
|
||||||
|
# ******** Duplicate any changes in processEvent *********
|
||||||
|
# ********************************************************
|
||||||
# Get the event name
|
# Get the event name
|
||||||
eventName = event.getName()
|
eventName = event.getName()
|
||||||
if eventName:
|
if eventName:
|
||||||
@ -94,13 +147,37 @@ class EventManager:
|
|||||||
' parameters: ' + `paramList`)
|
' parameters: ' + `paramList`)
|
||||||
# Send the event, we used to send it with the event
|
# Send the event, we used to send it with the event
|
||||||
# name as a parameter, but now you can use extraArgs for that
|
# name as a parameter, but now you can use extraArgs for that
|
||||||
|
# ********************************************************
|
||||||
|
# ******** Duplicate any changes in processEvent *********
|
||||||
|
# ********************************************************
|
||||||
|
if self._wantPstats:
|
||||||
|
name = eventName
|
||||||
|
hyphen = name.find('-')
|
||||||
|
if hyphen >= 0:
|
||||||
|
name = name[0:hyphen]
|
||||||
|
pstatCollector = PStatCollector('App:Show code:eventManager:' + name)
|
||||||
|
pstatCollector.start()
|
||||||
|
if self.eventHandler:
|
||||||
|
cppPstatCollector = PStatCollector(
|
||||||
|
'App:Show code:eventManager:' + name + ':C++')
|
||||||
|
|
||||||
if paramList:
|
if paramList:
|
||||||
messenger.send(eventName, paramList)
|
messenger.send(eventName, paramList)
|
||||||
else:
|
else:
|
||||||
messenger.send(eventName)
|
messenger.send(eventName)
|
||||||
# Also send the event down into C++ land
|
# Also send the event down into C++ land
|
||||||
if self.eventHandler:
|
if self.eventHandler:
|
||||||
|
if self._wantPstats:
|
||||||
|
cppPstatCollector.start()
|
||||||
self.eventHandler.dispatchEvent(event)
|
self.eventHandler.dispatchEvent(event)
|
||||||
|
# ********************************************************
|
||||||
|
# ******** Duplicate any changes in processEvent *********
|
||||||
|
# ********************************************************
|
||||||
|
|
||||||
|
if self._wantPstats:
|
||||||
|
if self.eventHandler:
|
||||||
|
cppPstatCollector.stop()
|
||||||
|
pstatCollector.stop()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# An unnamed event from C++ is probably a bad thing
|
# An unnamed event from C++ is probably a bad thing
|
||||||
|
Loading…
x
Reference in New Issue
Block a user