benchmark->profile, and remove from error branches

This commit is contained in:
Damien Elmes 2020-05-05 16:28:49 +10:00
parent e7ebcc7c75
commit 2f57c646e0

View File

@ -348,17 +348,19 @@ def setupGL(pm):
os.environ["QT_OPENGL"] = mode os.environ["QT_OPENGL"] = mode
def printBenchmark(): PROFILE_CODE = os.environ.get("ANKI_PROFILE_CODE")
if os.environ.get("ANKI_RUN_BENCHMARK"):
import io
import pstats
profiler.disable()
outputstream = io.StringIO() def print_profile_results():
profiler_status = pstats.Stats(profiler, stream=outputstream) import io
profiler_status.sort_stats("time") import pstats
profiler_status.print_stats()
sys.stderr.write(f"\n{outputstream.getvalue()}\n") 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(): def run():
@ -392,7 +394,7 @@ def _run(argv=None, exec=True):
# parse args # parse args
opts, args = parseArgs(argv) opts, args = parseArgs(argv)
if os.environ.get("ANKI_RUN_BENCHMARK"): if PROFILE_CODE:
import cProfile import cProfile
profiler = cProfile.Profile() 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 \ Anki could not create its data folder. Please see the File Locations \
section of the manual, and ensure that location is not read-only.""", section of the manual, and ensure that location is not read-only.""",
) )
printBenchmark()
return return
# disable icons on mac; this must be done before window created # 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 \ No usable temporary folder found. Make sure C:\\temp exists or TEMP in your \
environment points to a valid, writable folder.""", environment points to a valid, writable folder.""",
) )
printBenchmark()
return return
if pmLoadResult.firstTime: if pmLoadResult.firstTime:
@ -515,4 +515,5 @@ environment points to a valid, writable folder.""",
else: else:
return app return app
printBenchmark() if PROFILE_CODE:
print_profile_results()