2014-09-22 20:21:00 +02:00
|
|
|
#!/usr/bin/env python3
|
2014-06-19 09:04:37 +02:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
2016-01-04 07:12:39 +01:00
|
|
|
# Copyright 2014-2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
2014-06-19 08:28:05 +02:00
|
|
|
#
|
|
|
|
# This file is part of qutebrowser.
|
|
|
|
#
|
|
|
|
# qutebrowser is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# qutebrowser is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2014-02-26 21:18:53 +01:00
|
|
|
"""Profile qutebrowser."""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import cProfile
|
|
|
|
import os.path
|
2014-08-26 19:10:14 +02:00
|
|
|
import os
|
|
|
|
import tempfile
|
|
|
|
import subprocess
|
|
|
|
import shutil
|
2014-02-26 21:18:53 +01:00
|
|
|
|
2015-06-28 22:31:30 +02:00
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir,
|
|
|
|
os.pardir))
|
2014-05-13 23:17:22 +02:00
|
|
|
|
2015-07-24 15:01:18 +02:00
|
|
|
import qutebrowser.qutebrowser
|
2014-02-26 21:18:53 +01:00
|
|
|
|
2014-08-26 19:10:14 +02:00
|
|
|
tempdir = tempfile.mkdtemp()
|
2014-02-26 21:18:53 +01:00
|
|
|
|
2014-06-04 14:49:50 +02:00
|
|
|
if '--profile-keep' in sys.argv:
|
|
|
|
sys.argv.remove('--profile-keep')
|
2014-08-26 19:10:14 +02:00
|
|
|
profilefile = os.path.join(os.getcwd(), 'profile')
|
2014-02-26 21:18:53 +01:00
|
|
|
else:
|
|
|
|
profilefile = os.path.join(tempdir, 'profile')
|
2015-05-21 07:45:20 +02:00
|
|
|
|
2014-06-04 14:50:06 +02:00
|
|
|
if '--profile-noconv' in sys.argv:
|
|
|
|
sys.argv.remove('--profile-noconv')
|
|
|
|
noconv = True
|
2014-08-04 18:15:15 +02:00
|
|
|
else:
|
|
|
|
noconv = False
|
2014-02-26 21:18:53 +01:00
|
|
|
|
2015-05-21 07:45:20 +02:00
|
|
|
if '--profile-dot' in sys.argv:
|
|
|
|
sys.argv.remove('--profile-dot')
|
|
|
|
dot = True
|
|
|
|
else:
|
|
|
|
dot = False
|
|
|
|
|
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()
|
2015-07-24 15:01:18 +02:00
|
|
|
profiler.runcall(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:
|
2015-05-21 07:45:20 +02:00
|
|
|
if dot:
|
|
|
|
subprocess.call('gprof2dot -f pstats profile | dot -Tpng | feh -F -',
|
|
|
|
shell=True) # yep, shell=True. I know what I'm doing.
|
|
|
|
else:
|
|
|
|
subprocess.call(['pyprof2calltree', '-k', '-i', profilefile,
|
|
|
|
'-o', callgraphfile])
|
2014-08-26 19:10:14 +02:00
|
|
|
shutil.rmtree(tempdir)
|