changeset 116:c6b9e63a51d8

* Profiling support for Rio de hola by jasoka * Engines segfaults while exiting (after pressing ESC) if ProfilingOn is set to True in settings.py * Segfault-related ticket: #334
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 29 Jul 2008 00:30:17 +0000
parents c94c76346027
children 5f32bfdc4232
files clients/rio_de_hola/run.py clients/rio_de_hola/settings.py
diffstat 2 files changed, 32 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/clients/rio_de_hola/run.py	Mon Jul 28 23:53:03 2008 +0000
+++ b/clients/rio_de_hola/run.py	Tue Jul 29 00:30:17 2008 +0000
@@ -33,10 +33,10 @@
 			fife.Key.RIGHT,
 			fife.Key.UP,
 			fife.Key.DOWN])
-		
+
 		self.quit = False
 		self.aboutWindow = None
-		
+
 		self.rootpanel = pychan.loadXML('gui/rootpanel.xml')
 		self.rootpanel.mapEvents({ 
 			'quitButton' : self.onQuitButtonPress,
@@ -57,7 +57,7 @@
 		elif keystr == 'p':
 			self.engine.getRenderBackend().captureScreen('screenshot.png')
 			evt.consume()
-	
+
 	def onCommand(self, command):
 		self.quit = (command.getCommandType() == fife.CMD_QUIT_GAME)
 		if self.quit:
@@ -87,7 +87,7 @@
 		cmd.setSource(None)
 		cmd.setCommandType(fife.CMD_QUIT_GAME)
 		self.engine.getEventManager().dispatchCommand(cmd)
-		
+
 	def onAboutButtonPress(self):
 		if not self.aboutWindow:
 			self.aboutWindow = pychan.loadXML('gui/help.xml')
@@ -103,10 +103,10 @@
 		self.world = world.World(self.engine)
 		self.listener = ApplicationListener(self.engine, self.world)
 		self.world.load(TDS.MapFile)
-		
+
 		self.soundmanager = self.engine.getSoundManager()
 		self.soundmanager.init()
-		
+
 		if TDS.PlaySounds:
 			# play track as background music
 			emitter = self.soundmanager.createEmitter()
@@ -117,7 +117,7 @@
 
 	def createListener(self):
 		pass # already created in constructor
-		
+
 	def _pump(self):
 		if self.listener.quit:
 			self.breakRequested = True
@@ -131,14 +131,27 @@
 
 
 if __name__ == '__main__':
-	if TDS.UsePsyco:
-		# Import Psyco if available
-		try:
-			import psyco
-			psyco.full()
-			print "Psyco acceleration in use"
-		except ImportError:
+	if TDS.ProfilingOn:
+		import hotshot, hotshot.stats
+		print "Starting profiler"
+		prof = hotshot.Profile("fife.prof")
+		prof.runcall(main)
+		prof.close()
+		print "analysing profiling results"
+		stats = hotshot.stats.load("fife.prof")
+		stats.strip_dirs()
+		stats.sort_stats('time', 'calls')
+		stats.print_stats(20)
+	else:
+		if TDS.UsePsyco:
+			# Import Psyco if available
+			try:
+				import psyco
+				psyco.full()
+				print "Psyco acceleration in use"
+			except ImportError:
+				print "Psyco acceleration not used"
+		else:
 			print "Psyco acceleration not used"
-	else:
-		print "Psyco acceleration not used"
+
 	main()
--- a/clients/rio_de_hola/settings.py	Mon Jul 28 23:53:03 2008 +0000
+++ b/clients/rio_de_hola/settings.py	Tue Jul 29 00:30:17 2008 +0000
@@ -6,8 +6,8 @@
 SDLRemoveFakeAlpha  = 1
 ScreenWidth         = 1024
 ScreenHeight        = 768
-WindowTitle			= 'FIFE - Rio de hola'
-WindowIcon			= ''
+WindowTitle         = 'FIFE - Rio de hola'
+WindowIcon          = ''
 
 MapFile             = 'maps/shrine.xml'
 Font                = 'fonts/samanata.ttf'
@@ -19,6 +19,7 @@
 LogToFile           = 0
 UsePsyco            = False
 ImageChunkSize      = 256
+ProfilingOn         = False
 
 CoordinateLayerName = "TechdemoMapTileLayer"
 QuadTreeLayerName = "" #"TechdemoMapObjectLayer"