Rev 2819: profiling fixes - basename checking and exceptions now caught in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Sep 14 01:42:17 BST 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 2819
revision-id: pqm at pqm.ubuntu.com-20070914004213-xraql0v7q1p63j81
parent: pqm at pqm.ubuntu.com-20070913193317-hi3rhwxhbrviw7hz
parent: ian.clatworthy at internode.on.net-20070913231640-rd98wg24ma9hrma4
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2007-09-14 01:42:13 +0100
message:
  profiling fixes - basename checking and exceptions now caught
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/commands.py             bzr.py-20050309040720-d10f4714595cf8c3
  bzrlib/lsprof.py               lsprof.py-20051208071030-833790916798ceed
  bzrlib/tests/test_lsprof.py    test_lsprof.py-20070606095601-bctdndm8yhc0cqnc-1
    ------------------------------------------------------------
    revno: 2818.1.1
    merged: ian.clatworthy at internode.on.net-20070913231640-rd98wg24ma9hrma4
    parent: pqm at pqm.ubuntu.com-20070913193317-hi3rhwxhbrviw7hz
    parent: ian.clatworthy at internode.on.net-20070910081929-9419oqg1zhva4e7d
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: ianc-integration
    timestamp: Fri 2007-09-14 09:16:40 +1000
    message:
      profiling fixes - basename checking and exceptions now caught
    ------------------------------------------------------------
    revno: 2805.7.6
    merged: ian.clatworthy at internode.on.net-20070910081929-9419oqg1zhva4e7d
    parent: ian.clatworthy at internode.on.net-20070910062740-kkj4776w6snhf0vl
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: bzr.profiling-fixes
    timestamp: Mon 2007-09-10 18:19:29 +1000
    message:
      put back KeyboardInterrupt trapping as needed for Python 2.5
    ------------------------------------------------------------
    revno: 2805.7.5
    merged: ian.clatworthy at internode.on.net-20070910062740-kkj4776w6snhf0vl
    parent: ian.clatworthy at internode.on.net-20070910062331-j985z2fu9amnylcq
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: bzr.profiling-fixes
    timestamp: Mon 2007-09-10 16:27:40 +1000
    message:
      more win32 path friendliness
    ------------------------------------------------------------
    revno: 2805.7.4
    merged: ian.clatworthy at internode.on.net-20070910062331-j985z2fu9amnylcq
    parent: ian.clatworthy at internode.on.net-20070910025614-ftu45ff34xphqr4b
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: bzr.profiling-fixes
    timestamp: Mon 2007-09-10 16:23:31 +1000
    message:
      incorporate feedback from lifeless
    ------------------------------------------------------------
    revno: 2805.7.3
    merged: ian.clatworthy at internode.on.net-20070910025614-ftu45ff34xphqr4b
    parent: ian.clatworthy at internode.on.net-20070910024907-ri37q9rrkuv1rapq
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: bzr.profiling-fixes
    timestamp: Mon 2007-09-10 12:56:14 +1000
    message:
      Update NEWS
    ------------------------------------------------------------
    revno: 2805.7.2
    merged: ian.clatworthy at internode.on.net-20070910024907-ri37q9rrkuv1rapq
    parent: ian.clatworthy at internode.on.net-20070910024007-qeqapxc91bqwhe0q
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: bzr.profiling-fixes
    timestamp: Mon 2007-09-10 12:49:07 +1000
    message:
      use basename, not full path, when checking for callgrind.out file prefix
    ------------------------------------------------------------
    revno: 2805.7.1
    merged: ian.clatworthy at internode.on.net-20070910024007-qeqapxc91bqwhe0q
    parent: pqm at pqm.ubuntu.com-20070907145828-hjh5941jv7y8d9z8
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: bzr.profiling-fixes
    timestamp: Mon 2007-09-10 12:40:07 +1000
    message:
      Dump profiling data even when exceptions are encountered
=== modified file 'NEWS'
--- a/NEWS	2007-09-12 21:27:42 +0000
+++ b/NEWS	2007-09-13 23:16:40 +0000
@@ -17,6 +17,16 @@
 
   BUG FIXES:
 
+   * The basename, not the full path, is now used when checking whether
+     the profiling dump file begins with ``callgrind.out`` or not. This
+     fixes a bug reported by Aaron Bentley on IRC. (Ian Clatworthy)
+
+   * Commands reporting exceptions can now be profiled and still have their
+     data correctly dumped to a file. For example, a ``bzr commit`` with
+     no changes still reports the operation as pointless but doing so no
+     longer throws away the profiling data if this command is run with
+     ``--lsprof-file callgrind.out.ci`` say. (Ian Clatworthy)
+
   API BREAKS:
 
    * The ``VersionedFile`` interface now allows content checks to be bypassed

=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2007-09-05 08:18:57 +0000
+++ b/bzrlib/commands.py	2007-09-10 02:40:07 +0000
@@ -796,6 +796,8 @@
 
 
 def run_bzr_catch_errors(argv):
+    # Note: The except clause logic below should be kept in sync with the
+    # profile() routine in lsprof.py.
     try:
         return run_bzr(argv)
     except (KeyboardInterrupt, Exception), e:

=== modified file 'bzrlib/lsprof.py'
--- a/bzrlib/lsprof.py	2007-07-30 01:55:44 +0000
+++ b/bzrlib/lsprof.py	2007-09-10 08:19:29 +0000
@@ -10,6 +10,10 @@
 import threading
 from _lsprof import Profiler, profiler_entry
 
+
+import bzrlib.osutils
+
+
 __all__ = ['profile', 'Stats']
 
 _g_threadmap = {}
@@ -31,8 +35,17 @@
     p = Profiler()
     p.enable(subcalls=True)
     threading.setprofile(_thread_profile)
+    # Note: The except clause is needed below so that profiling data still
+    # gets dumped even when exceptions are encountered. The except clause code
+    # is taken straight from run_bzr_catch_errrors() in commands.py and ought
+    # to be kept in sync with it.
     try:
-        ret = f(*args, **kwds)
+        try:
+            ret = f(*args, **kwds)
+        except (KeyboardInterrupt, Exception), e:
+            import bzrlib.trace
+            bzrlib.trace.report_exception(sys.exc_info(), sys.stderr)
+            ret = 3
     finally:
         p.disable()
         for pp in _g_threadmap.values():
@@ -118,10 +131,11 @@
             otherwise the format is given by the filename extension.
         """
         if format is None:
-            if filename.startswith('callgrind.out'):
+            basename = bzrlib.osutils.basename(filename)
+            if basename.startswith('callgrind.out'):
                 format = "callgrind"
             else:
-                ext = os.path.splitext(filename)[1]
+                ext = bzrlib.osutils.splitext(filename)[1]
                 if len(ext) > 1:
                     format = ext[1:]
         outfile = open(filename, 'wb')

=== modified file 'bzrlib/tests/test_lsprof.py'
--- a/bzrlib/tests/test_lsprof.py	2007-06-18 13:55:14 +0000
+++ b/bzrlib/tests/test_lsprof.py	2007-09-10 06:27:40 +0000
@@ -64,7 +64,7 @@
 
     def _tempfile(self, ext):
         dir = self.test_dir
-        return os.path.join(dir, "tmp_profile_data." + ext)
+        return bzrlib.osutils.pathjoin(dir, "tmp_profile_data." + ext)
 
     def test_stats_save_to_txt(self):
         f = self._tempfile("txt")
@@ -77,6 +77,10 @@
         self.stats.save(f)
         lines = open(f).readlines()
         self.assertEqual(lines[0], "events: Ticks\n")
+        f = bzrlib.osutils.pathjoin(self.test_dir, "callgrind.out.foo")
+        self.stats.save(f)
+        lines = open(f).readlines()
+        self.assertEqual(lines[0], "events: Ticks\n")
         # Test explicit format nommination
         f2 = self._tempfile("txt")
         self.stats.save(f2, format="callgrind")




More information about the bazaar-commits mailing list