import cProfile from time import strftime from os import mkdir from os.path import join, exists 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): if self.requested(): root = "stat/" if not exists(root): mkdir(root) self.disable() self.create_stats() self.dump_stats(join(root, strftime("%Y%m%d-%H%M_%S.stat")))