mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 09:16:38 -04:00
Created the --benchmark command line option
https://anki.tenderapp.com/discussions/ankidesktop/41106-card-audio-playback-changes-bug-in-212x Based on the snippet: https://gist.github.com/evandrocoan/961d46e10424e53ba8946fac66e0efac
This commit is contained in:
parent
36ea980725
commit
b63bfc83d8
1 changed files with 35 additions and 0 deletions
|
@ -308,6 +308,13 @@ def parseArgs(argv):
|
||||||
parser.add_argument("-b", "--base", help="path to base folder", default="")
|
parser.add_argument("-b", "--base", help="path to base folder", default="")
|
||||||
parser.add_argument("-p", "--profile", help="profile name to load", default="")
|
parser.add_argument("-p", "--profile", help="profile name to load", default="")
|
||||||
parser.add_argument("-l", "--lang", help="interface language (en, de, etc)")
|
parser.add_argument("-l", "--lang", help="interface language (en, de, etc)")
|
||||||
|
parser.add_argument(
|
||||||
|
"-bm",
|
||||||
|
"--benchmark",
|
||||||
|
type=int,
|
||||||
|
help="reports anki run time performance to stdout (pass the number of characters to report)",
|
||||||
|
default=None,
|
||||||
|
)
|
||||||
return parser.parse_known_args(argv[1:])
|
return parser.parse_known_args(argv[1:])
|
||||||
|
|
||||||
|
|
||||||
|
@ -347,6 +354,21 @@ def setupGL(pm):
|
||||||
os.environ["QT_OPENGL"] = mode
|
os.environ["QT_OPENGL"] = mode
|
||||||
|
|
||||||
|
|
||||||
|
def printBenchmark(argumentsNamespace, profiller):
|
||||||
|
if argumentsNamespace.benchmark and profiller:
|
||||||
|
import io
|
||||||
|
import pstats
|
||||||
|
|
||||||
|
profiller.disable()
|
||||||
|
outputstream = io.StringIO()
|
||||||
|
profiller_status = pstats.Stats(profiller, stream=outputstream)
|
||||||
|
profiller_status.sort_stats("time")
|
||||||
|
profiller_status.print_stats()
|
||||||
|
sys.stderr.write(
|
||||||
|
f"\n{outputstream.getvalue()[:argumentsNamespace.benchmark]}\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
try:
|
try:
|
||||||
_run()
|
_run()
|
||||||
|
@ -370,6 +392,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
|
||||||
|
profiller = None
|
||||||
|
|
||||||
if argv is None:
|
if argv is None:
|
||||||
argv = sys.argv
|
argv = sys.argv
|
||||||
|
@ -377,6 +400,12 @@ def _run(argv=None, exec=True):
|
||||||
# parse args
|
# parse args
|
||||||
opts, args = parseArgs(argv)
|
opts, args = parseArgs(argv)
|
||||||
|
|
||||||
|
if opts.benchmark:
|
||||||
|
import cProfile
|
||||||
|
|
||||||
|
profiller = cProfile.Profile()
|
||||||
|
profiller.enable()
|
||||||
|
|
||||||
# profile manager
|
# profile manager
|
||||||
pm = None
|
pm = None
|
||||||
try:
|
try:
|
||||||
|
@ -409,6 +438,7 @@ def _run(argv=None, exec=True):
|
||||||
app = AnkiApp(argv)
|
app = AnkiApp(argv)
|
||||||
if app.secondInstance():
|
if app.secondInstance():
|
||||||
# we've signaled the primary instance, so we should close
|
# we've signaled the primary instance, so we should close
|
||||||
|
printBenchmark(opts, profiller)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not pm:
|
if not pm:
|
||||||
|
@ -419,6 +449,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(opts, profiller)
|
||||||
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 +483,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(opts, profiller)
|
||||||
return
|
return
|
||||||
|
|
||||||
if pmLoadResult.firstTime:
|
if pmLoadResult.firstTime:
|
||||||
|
@ -490,4 +522,7 @@ environment points to a valid, writable folder.""",
|
||||||
if exec:
|
if exec:
|
||||||
app.exec()
|
app.exec()
|
||||||
else:
|
else:
|
||||||
|
printBenchmark(opts, profiller)
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
printBenchmark(opts, profiller)
|
||||||
|
|
Loading…
Reference in a new issue