mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 00:36:38 -04:00
Merge pull request #605 from evandroforks/benchmark_option
Created the --benchmark command line option
This commit is contained in:
commit
e7ebcc7c75
1 changed files with 25 additions and 0 deletions
|
@ -35,6 +35,7 @@ appHelpSite = HELP_SITE
|
||||||
from aqt.main import AnkiQt # isort:skip
|
from aqt.main import AnkiQt # isort:skip
|
||||||
from aqt.profiles import ProfileManager # isort:skip
|
from aqt.profiles import ProfileManager # isort:skip
|
||||||
|
|
||||||
|
profiler = None
|
||||||
mw: Optional[AnkiQt] = None # set on init
|
mw: Optional[AnkiQt] = None # set on init
|
||||||
|
|
||||||
moduleDir = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
|
moduleDir = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
|
||||||
|
@ -347,6 +348,19 @@ def setupGL(pm):
|
||||||
os.environ["QT_OPENGL"] = mode
|
os.environ["QT_OPENGL"] = mode
|
||||||
|
|
||||||
|
|
||||||
|
def printBenchmark():
|
||||||
|
if os.environ.get("ANKI_RUN_BENCHMARK"):
|
||||||
|
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():
|
def run():
|
||||||
try:
|
try:
|
||||||
_run()
|
_run()
|
||||||
|
@ -370,6 +384,7 @@ def _run(argv=None, exec=True):
|
||||||
If no 'argv' is supplied then 'sys.argv' will be used.
|
If no 'argv' is supplied then 'sys.argv' will be used.
|
||||||
"""
|
"""
|
||||||
global mw
|
global mw
|
||||||
|
global profiler
|
||||||
|
|
||||||
if argv is None:
|
if argv is None:
|
||||||
argv = sys.argv
|
argv = sys.argv
|
||||||
|
@ -377,6 +392,12 @@ 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"):
|
||||||
|
import cProfile
|
||||||
|
|
||||||
|
profiler = cProfile.Profile()
|
||||||
|
profiler.enable()
|
||||||
|
|
||||||
# profile manager
|
# profile manager
|
||||||
pm = None
|
pm = None
|
||||||
try:
|
try:
|
||||||
|
@ -419,6 +440,7 @@ 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
|
||||||
|
@ -452,6 +474,7 @@ 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:
|
||||||
|
@ -491,3 +514,5 @@ environment points to a valid, writable folder.""",
|
||||||
app.exec()
|
app.exec()
|
||||||
else:
|
else:
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
printBenchmark()
|
||||||
|
|
Loading…
Reference in a new issue