From 0ef6699add983199b5e94e9a7d4d95edaff1064b Mon Sep 17 00:00:00 2001 Message-Id: <0ef6699add983199b5e94e9a7d4d95edaff1064b.1717088746.git.mdw@distorted.org.uk> From: Mark Wooding Date: Tue, 4 Oct 2005 20:56:18 +0100 Subject: [PATCH] Add an uninstallable script for profiling Organization: Straylight/Edgeware From: Catalin Marinas The script name is stg-prof and can be used instead stg for printing profiling information. Signed-off-by: Catalin Marinas --- MANIFEST.in | 1 + stg-prof | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100755 stg-prof diff --git a/MANIFEST.in b/MANIFEST.in index 581d0be..4ebca0e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,5 @@ include README MANIFEST.in AUTHORS COPYING INSTALL ChangeLog TODO +include stg-prof include templates/*.tmpl include examples/*.tmpl include examples/stgitrc diff --git a/stg-prof b/stg-prof new file mode 100755 index 0000000..8bbb623 --- /dev/null +++ b/stg-prof @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# -*- python-mode -*- +"""Takes care of starting the Init function +""" + +__copyright__ = """ +Copyright (C) 2005, Catalin Marinas + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License version 2 as +published by the Free Software Foundation. + +This program 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 this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +""" + +import sys, os +import profile, pstats, time + +# Try to detect where it is run from and set prefix and the search path. +# It is assumed that the user installed StGIT using the --prefix= option +prefix, bin = os.path.split(sys.path[0]) + +if bin == 'bin' and prefix != sys.prefix: + sys.prefix = prefix + sys.exec_prefix = prefix + + major, minor = sys.version_info[0:2] + local_path = [os.path.join(prefix, 'lib', 'python'), + os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor)), + os.path.join(prefix, 'lib', 'python%s.%s' % (major, minor), + 'site-packages')] + sys.path = local_path + sys.path + +from stgit.main import main + +start_time = time.time() +def timer(): + return time.time() - start_time + +prof = profile.Profile(timer) +try: + prof.run('main()') +except SystemExit: + pass +pstats.Stats(prof).strip_dirs().sort_stats(-1).print_stats().print_callees() -- [mdw]