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