Add an uninstallable script for profiling
[stgit] / stg-prof
CommitLineData
0ef6699a
CM
1#!/usr/bin/env python
2# -*- python-mode -*-
3"""Takes care of starting the Init function
4"""
5
6__copyright__ = """
7Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
8
9This program is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License version 2 as
11published by the Free Software Foundation.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21"""
22
23import sys, os
24import profile, pstats, time
25
26# Try to detect where it is run from and set prefix and the search path.
27# It is assumed that the user installed StGIT using the --prefix= option
28prefix, bin = os.path.split(sys.path[0])
29
30if bin == 'bin' and prefix != sys.prefix:
31 sys.prefix = prefix
32 sys.exec_prefix = prefix
33
34 major, minor = sys.version_info[0:2]
35 local_path = [os.path.join(prefix, 'lib', 'python'),
36 os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor)),
37 os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor),
38 'site-packages')]
39 sys.path = local_path + sys.path
40
41from stgit.main import main
42
43start_time = time.time()
44def timer():
45 return time.time() - start_time
46
47prof = profile.Profile(timer)
48try:
49 prof.run('main()')
50except SystemExit:
51 pass
52pstats.Stats(prof).strip_dirs().sort_stats(-1).print_stats().print_callees()