[PATCH] Support cProfile profiler

Jon Foster <[email protected]> Wed, 31 Mar 2010 12:27:17 +0100
Newsgroups gmane.comp.version-control.subversion.cvs2svn.devel
Message-ID <[email protected]>
Hi,

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.

The attached patch makes cvs2svn use cProfile if available, and fall
back to the existing hotshot support if cProfile isn't available.

(Incidentally, profiling shows that the __does_rule_apply_to()
method in SubtreeSymbolTransform is taking over 40% of cvs2svn's
total runtime, on my conversion.  Optimization patches to follow).

Kind regards,

Jon


**********************************************************************
This email and its attachments may be confidential and are intended solely for the use of the individual to whom it is addressed. Any views or opinions expressed are solely those of the author and do not necessarily represent those of Cabot Communications Ltd.

If you are not the intended recipient of this email and its attachments, you must take no action based upon them, nor must you copy or show them to anyone.

Cabot Communications Limited
Verona House, Filwood Road, Bristol BS16 3RY, UK
+44 (0) 1179584232

Co. Registered in England number 02817269

Please contact the sender if you believe you have received this email in error.

**********************************************************************


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

------------------------------------------------------
http://cvs2svn.tigris.org/ds/viewMessage.do?dsForumId=1667&dsMessageId=2467662

To unsubscribe from this discussion, e-mail: [[email protected]].
cvs2svn_cprofile_patch.txt (text/plain, 961 B)
Index: cvs2svn_lib/main.py
===================================================================
--- cvs2svn_lib/main.py	(revision 5093)
+++ cvs2svn_lib/main.py	(working copy)
@@ -77,10 +77,19 @@
 
   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: