qutebrowser/scripts/run_profile.py
2014-04-22 07:20:25 +02:00

28 lines
655 B
Python
Executable File

"""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
from qutebrowser.app import QuteBrowser
tempdir = mkdtemp()
if '--keep' in sys.argv:
sys.argv.remove('--keep')
profilefile = os.path.join(getcwd(), 'profile')
else:
profilefile = os.path.join(tempdir, 'profile')
callgraphfile = os.path.join(tempdir, 'callgraph')
profiler = cProfile.Profile()
profiler.run('app = QuteBrowser(); app.exec_()')
profiler.dump_stats(profilefile)
call(['pyprof2calltree', '-k', '-i', profilefile, '-o', callgraphfile])
rmtree(tempdir)