qutebrowser/scripts/run_profile.py

34 lines
835 B
Python
Raw Normal View History

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
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()
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')
if '--profile-noconv' in sys.argv:
sys.argv.remove('--profile-noconv')
noconv = True
2014-02-26 21:18:53 +01: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)
if not noconv:
call(['pyprof2calltree', '-k', '-i', profilefile, '-o', callgraphfile])
2014-02-26 21:18:53 +01:00
rmtree(tempdir)