From f53879f961cc0b28d0898d60942464fbda4750ec Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Sun, 2 Jul 2023 09:32:21 -0500 Subject: [PATCH] pyinstrument if you have it --- learn_sql_model/game/game.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/learn_sql_model/game/game.py b/learn_sql_model/game/game.py index 579c6da..ffb0a0b 100644 --- a/learn_sql_model/game/game.py +++ b/learn_sql_model/game/game.py @@ -1,6 +1,5 @@ import atexit -from rich.console import Console from typer import Typer from websocket import create_connection @@ -62,10 +61,13 @@ class Client: return self._ws def run(self): - # from pyinstrument import Profiler + try: + from pyinstrument import Profiler - # profiler = Profiler() - # profiler.start() + profiler = Profiler() + profiler.start() + except ImportError: + profiler = None while self.running: console.print("running") console.print("handle_events") @@ -77,11 +79,12 @@ class Client: time = self.clock.tick(60) self.elapsed = time / 100 self.ticks += 1 - Console().print(self.clock.get_fps()) + # Console().print(self.clock.get_fps()) console.print(f"time: {time}") console.print(f"ticks: {self.ticks}") - # profiler.stop() - # print(profiler.output_text()) + if profiler: + profiler.stop() + print(profiler.output_text()) self.quit() def quit(self):