profile
This commit is contained in:
parent
947411d3ed
commit
a8ca15a630
|
@ -30,7 +30,7 @@ class Configuration(RawConfigParser):
|
|||
new = ""
|
||||
if path and path[0] == sep:
|
||||
new += sep
|
||||
return expanduser("%s%s" % (new, join(*path.split(sep))))
|
||||
return expanduser("{0}{1}".format(new, join(*path.split(sep))))
|
||||
|
||||
def set_defaults(self):
|
||||
add_section = self.add_section
|
||||
|
@ -283,7 +283,9 @@ class TypeDeclarations(dict):
|
|||
|
||||
"audio": {"path": "sfx-path"},
|
||||
|
||||
"event": {"int": "command-id-offset"}}
|
||||
"event": {"int": "command-id-offset"},
|
||||
|
||||
}
|
||||
|
||||
additional_defaults = {}
|
||||
|
||||
|
|
22
pgfw/Game.py
22
pgfw/Game.py
|
@ -10,13 +10,14 @@ from Configuration import Configuration
|
|||
from Delegate import Delegate
|
||||
from Input import Input
|
||||
from ScreenGrabber import ScreenGrabber
|
||||
from Profile import Profile
|
||||
|
||||
class Game(GameChild):
|
||||
|
||||
resource_path = None
|
||||
|
||||
def __init__(self, config_rel_path=None, type_declarations=None):
|
||||
self.init_profiler()
|
||||
self.profile = Profile(self)
|
||||
GameChild.__init__(self)
|
||||
self.print_debug(pygame.version.ver)
|
||||
self.config_rel_path = config_rel_path
|
||||
|
@ -28,16 +29,6 @@ class Game(GameChild):
|
|||
self.subscribe(self.end)
|
||||
self.delegate.enable()
|
||||
|
||||
def init_profiler(self):
|
||||
if self.profiling_active():
|
||||
from cProfile import Profile
|
||||
profiler = Profile()
|
||||
profiler.enable()
|
||||
self.profiler = profiler
|
||||
|
||||
def profiling_active(self):
|
||||
return self.check_command_line("p")
|
||||
|
||||
def set_configuration(self):
|
||||
self.configuration = Configuration(self.config_rel_path,
|
||||
self.resource_path,
|
||||
|
@ -70,11 +61,4 @@ class Game(GameChild):
|
|||
def end(self, evt):
|
||||
if evt.type == QUIT or self.delegate.compare(evt, "quit"):
|
||||
self.mainloop.stop()
|
||||
self.disable_profiler()
|
||||
|
||||
def disable_profiler(self):
|
||||
if self.profiling_active():
|
||||
from time import strftime
|
||||
profiler = self.profiler
|
||||
profiler.disable()
|
||||
profiler.dump_stats(strftime("stat/%Y%m%d-%H%M_%S.stat"))
|
||||
self.profile.end()
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
import cProfile
|
||||
from time import strftime
|
||||
from os.path import join
|
||||
|
||||
from GameChild import GameChild
|
||||
|
||||
class Profile(cProfile.Profile, GameChild):
|
||||
|
||||
def __init__(self, parent):
|
||||
GameChild.__init__(self, parent)
|
||||
cProfile.Profile.__init__(self)
|
||||
if self.requested():
|
||||
self.enable()
|
||||
|
||||
def requested(self):
|
||||
return self.check_command_line("p")
|
||||
|
||||
def end(self):
|
||||
self.disable()
|
||||
self.create_stats()
|
||||
self.dump_stats(join("stat/", strftime("%Y%m%d-%H%M_%S.stat")))
|
Loading…
Reference in New Issue