save profile stats to file instead of generating report

Can use an external tool like snakeviz to query them after a run.
This commit is contained in:
Damien Elmes 2020-05-16 12:53:01 +10:00
parent f6767d1cff
commit 578b60c104
2 changed files with 5 additions and 10 deletions

1
.gitignore vendored
View file

@ -10,3 +10,4 @@ dist
pyenv
.mypy_cache
__pycache__
anki.prof

View file

@ -351,16 +351,10 @@ def setupGL(pm):
PROFILE_CODE = os.environ.get("ANKI_PROFILE_CODE")
def print_profile_results():
import io
import pstats
def write_profile_results():
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")
profiler.dump_stats("anki.prof")
print("profile stats written to anki.prof")
def run():
@ -516,4 +510,4 @@ environment points to a valid, writable folder.""",
return app
if PROFILE_CODE:
print_profile_results()
write_profile_results()