From 2f57c646e0f4b40c9bf77fc4398505740e7f9a32 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 5 May 2020 16:28:49 +1000 Subject: [PATCH] benchmark->profile, and remove from error branches --- qt/aqt/__init__.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/qt/aqt/__init__.py b/qt/aqt/__init__.py index aca1ecc49..fe0d2633d 100644 --- a/qt/aqt/__init__.py +++ b/qt/aqt/__init__.py @@ -348,17 +348,19 @@ def setupGL(pm): os.environ["QT_OPENGL"] = mode -def printBenchmark(): - if os.environ.get("ANKI_RUN_BENCHMARK"): - import io - import pstats +PROFILE_CODE = os.environ.get("ANKI_PROFILE_CODE") - profiler.disable() - outputstream = io.StringIO() - profiler_status = pstats.Stats(profiler, stream=outputstream) - profiler_status.sort_stats("time") - profiler_status.print_stats() - sys.stderr.write(f"\n{outputstream.getvalue()}\n") + +def print_profile_results(): + import io + import pstats + + profiler.disable() + outputstream = io.StringIO() + profiler_status = pstats.Stats(profiler, stream=outputstream) + profiler_status.sort_stats("time") + profiler_status.print_stats() + sys.stderr.write(f"\n{outputstream.getvalue()}\n") def run(): @@ -392,7 +394,7 @@ def _run(argv=None, exec=True): # parse args opts, args = parseArgs(argv) - if os.environ.get("ANKI_RUN_BENCHMARK"): + if PROFILE_CODE: import cProfile profiler = cProfile.Profile() @@ -440,7 +442,6 @@ def _run(argv=None, exec=True): Anki could not create its data folder. Please see the File Locations \ section of the manual, and ensure that location is not read-only.""", ) - printBenchmark() return # disable icons on mac; this must be done before window created @@ -474,7 +475,6 @@ section of the manual, and ensure that location is not read-only.""", No usable temporary folder found. Make sure C:\\temp exists or TEMP in your \ environment points to a valid, writable folder.""", ) - printBenchmark() return if pmLoadResult.firstTime: @@ -515,4 +515,5 @@ environment points to a valid, writable folder.""", else: return app - printBenchmark() + if PROFILE_CODE: + print_profile_results()