stg rebase must delete stale files
[stgit.git] / stg-prof
blob2b4d6598881d85705f9b96ac40255212a672367a
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 # Try to detect where it is run from and set prefix and the search path.
14 # It is assumed that the user installed StGIT using the --prefix= option
15 prefix, bin = os.path.split(sys.path[0])
17 if bin == 'bin' and prefix != sys.prefix:
18 sys.prefix = prefix
19 sys.exec_prefix = prefix
21 major, minor = sys.version_info[0:2]
22 local_path = [os.path.join(prefix, 'lib', 'python'),
23 os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor)),
24 os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor),
25 'site-packages')]
26 sys.path = local_path + sys.path
28 from stgit.main import main
30 __copyright__ = """
31 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
33 This program is free software; you can redistribute it and/or modify
34 it under the terms of the GNU General Public License version 2 as
35 published by the Free Software Foundation.
37 This program is distributed in the hope that it will be useful,
38 but WITHOUT ANY WARRANTY; without even the implied warranty of
39 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 GNU General Public License for more details.
42 You should have received a copy of the GNU General Public License
43 along with this program; if not, see http://www.gnu.org/licenses/.
44 """
46 if __name__ == '__main__':
47 start_time = time.time()
48 def timer():
49 return time.time() - start_time
51 prof = profile.Profile(timer)
52 try:
53 prof.run('main()')
54 except SystemExit:
55 pass
56 pstats.Stats(prof).strip_dirs().sort_stats(-1).print_stats().print_callees()