profiler
This commit is contained in:
parent
7bfb1a5b37
commit
947411d3ed
19
pgfw/Game.py
19
pgfw/Game.py
|
@ -16,6 +16,7 @@ class Game(GameChild):
|
|||
resource_path = None
|
||||
|
||||
def __init__(self, config_rel_path=None, type_declarations=None):
|
||||
self.init_profiler()
|
||||
GameChild.__init__(self)
|
||||
self.print_debug(pygame.version.ver)
|
||||
self.config_rel_path = config_rel_path
|
||||
|
@ -27,6 +28,16 @@ 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,
|
||||
|
@ -59,3 +70,11 @@ 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"))
|
||||
|
|
|
@ -59,14 +59,17 @@ class GameChild:
|
|||
format(section, option))
|
||||
|
||||
def is_shared_mode(self):
|
||||
return "-s" in argv
|
||||
return self.check_command_line("s")
|
||||
|
||||
def check_command_line(self, flag):
|
||||
return "-" + flag in argv
|
||||
|
||||
def print_debug(self, statement):
|
||||
if self.is_debug_mode():
|
||||
print statement
|
||||
|
||||
def is_debug_mode(self):
|
||||
return "-d" in argv
|
||||
return self.check_command_line("d")
|
||||
|
||||
def is_absolute_path(self, path):
|
||||
return normpath(path) == abspath(path)
|
||||
|
|
Loading…
Reference in New Issue