Less indirection for save template callback
[stgit.git] / stg-prof
blob52fca38dca1fa7aeb634df62b91aefbeb10e4c9f
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # -*- python-mode -*-
4 """Run stg with profiling enabled."""
5 from __future__ import (
6 absolute_import,
7 division,
8 print_function,
9 unicode_literals,
12 import os
13 import profile
14 import pstats
15 import sys
16 import time
18 __copyright__ = """
19 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
21 This program is free software; you can redistribute it and/or modify
22 it under the terms of the GNU General Public License version 2 as
23 published by the Free Software Foundation.
25 This program is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 GNU General Public License for more details.
30 You should have received a copy of the GNU General Public License
31 along with this program; if not, see http://www.gnu.org/licenses/.
32 """
34 if __name__ == '__main__':
35 # Try to detect where it is run from and set prefix and the search path.
36 # It is assumed that the user installed StGIT using the --prefix= option
37 prefix, bin = os.path.split(sys.path[0])
39 if bin == 'bin' and prefix != sys.prefix:
40 sys.prefix = prefix
41 sys.exec_prefix = prefix
43 major, minor = sys.version_info[0:2]
44 local_path = [
45 os.path.join(prefix, 'lib', 'python'),
46 os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor)),
47 os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor),
48 'site-packages')]
49 sys.path = local_path + sys.path
51 from stgit.main import main # noqa
53 start_time = time.time()
55 def timer():
56 return time.time() - start_time
58 prof = profile.Profile(timer)
59 try:
60 prof.run('main()')
61 except SystemExit:
62 pass
63 stats = pstats.Stats(prof)
64 stats.strip_dirs().sort_stats(-1).print_stats().print_callees()