2014-02-26 21:18:53 +01:00
|
|
|
"""Profile qutebrowser."""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import cProfile
|
|
|
|
import os.path
|
|
|
|
from os import getcwd
|
|
|
|
from tempfile import mkdtemp
|
|
|
|
from subprocess import call
|
|
|
|
from shutil import rmtree
|
|
|
|
|
2014-05-13 23:17:22 +02:00
|
|
|
sys.path.insert(0, getcwd())
|
|
|
|
|
2014-06-04 14:49:07 +02:00
|
|
|
import qutebrowser.qutebrowser # pylint: disable=unused-import
|
2014-02-26 21:18:53 +01:00
|
|
|
|
|
|
|
tempdir = mkdtemp()
|
|
|
|
|
2014-06-04 14:49:50 +02:00
|
|
|
if '--profile-keep' in sys.argv:
|
|
|
|
sys.argv.remove('--profile-keep')
|
2014-02-26 21:18:53 +01:00
|
|
|
profilefile = os.path.join(getcwd(), 'profile')
|
|
|
|
else:
|
|
|
|
profilefile = os.path.join(tempdir, 'profile')
|
2014-06-04 14:50:06 +02:00
|
|
|
if '--profile-noconv' in sys.argv:
|
|
|
|
sys.argv.remove('--profile-noconv')
|
|
|
|
noconv = True
|
2014-02-26 21:18:53 +01:00
|
|
|
|
2014-06-04 14:50:06 +02:00
|
|
|
callgraphfile = os.path.join(tempdir, 'callgraph')
|
2014-02-26 21:18:53 +01:00
|
|
|
profiler = cProfile.Profile()
|
2014-06-04 14:49:07 +02:00
|
|
|
profiler.run('qutebrowser.qutebrowser.main()')
|
2014-02-26 21:18:53 +01:00
|
|
|
profiler.dump_stats(profilefile)
|
|
|
|
|
2014-06-04 14:50:06 +02:00
|
|
|
if not noconv:
|
|
|
|
call(['pyprof2calltree', '-k', '-i', profilefile, '-o', callgraphfile])
|
2014-02-26 21:18:53 +01:00
|
|
|
rmtree(tempdir)
|