From 56fc056ba598f9040b36978861810973422c4325 Mon Sep 17 00:00:00 2001 From: mhagger Date: Thu, 8 Apr 2010 19:29:18 +0000 Subject: [PATCH] Support cProfile profiler. Patch by: Jon Foster According to the Python 2.5 docs, the "hotshot" profiler is deprecated and may be removed in a future release of Python. Those docs recommend the "cProfile" profiler, which is new in Python 2.5. This patch makes cvs2svn use cProfile if available, and fall back to the existing hotshot support if cProfile isn't available. git-svn-id: http://cvs2svn.tigris.org/svn/cvs2svn/trunk@5111 be7e6eca-30d4-0310-a8e5-ac0d63af7087 --- cvs2svn_lib/main.py | 17 +++++++++++++---- cvs2svn_lib/run_options.py | 9 +++++++-- www/cvs2svn.html | 5 ++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/cvs2svn_lib/main.py b/cvs2svn_lib/main.py index 626dd8aa..981ad4ee 100644 --- a/cvs2svn_lib/main.py +++ b/cvs2svn_lib/main.py @@ -77,10 +77,19 @@ def main(progname, run_options, pass_manager): try: if run_options.profiling: - import hotshot - prof = hotshot.Profile('cvs2svn.hotshot') - prof.runcall(pass_manager.run, run_options) - prof.close() + try: + import cProfile + except ImportError: + # Old version of Python without cProfile. Use hotshot instead. + import hotshot + prof = hotshot.Profile('cvs2svn.hotshot') + prof.runcall(pass_manager.run, run_options) + prof.close() + else: + # Recent version of Python (2.5+) with cProfile. + def run_with_profiling(): + pass_manager.run(run_options) + cProfile.runctx('run_with_profiling()', globals(), locals(), 'cvs2svn.cProfile') else: pass_manager.run(run_options) finally: diff --git a/cvs2svn_lib/run_options.py b/cvs2svn_lib/run_options.py index ed30ff57..c1c83b82 100644 --- a/cvs2svn_lib/run_options.py +++ b/cvs2svn_lib/run_options.py @@ -837,12 +837,17 @@ class RunOptions(object): help='prevent the deletion of intermediate files', man_help='Prevent the deletion of temporary files.', )) + prof = 'cProfile' + try: + import cProfile + except ImportError, e: + prof = 'hotshot' group.add_option(ManOption( '--profile', action='callback', callback=self.callback_profile, - help='profile with \'hotshot\' (into file cvs2svn.hotshot)', + help='profile with \'' + prof + '\' (into file cvs2svn.' + prof + ')', man_help=( - 'Profile with \'hotshot\' (into file \\fIcvs2svn.hotshot\\fR).' + 'Profile with \'' + prof + '\' (into file \\fIcvs2svn.' + prof + '\\fR).' ), )) diff --git a/www/cvs2svn.html b/www/cvs2svn.html index 491cfa59..1410f552 100644 --- a/www/cvs2svn.html +++ b/www/cvs2svn.html @@ -1203,7 +1203,10 @@ project-id symbol conversion svn-path parent-lod-name --profile - Dump Python Dump Python cProfile profiling data to the file cvs2svn.cProfile. + In Python 2.4 and earlier, if cProfile is not installed, it will + instead dump Hotshot profiling data to the file cvs2svn.hotshot. -- 2.11.4.GIT