[PATCH 2 of 4] profiling: Adding profiling.output config variable

Nicolas Dumazet nicdumz at gmail.com
Thu Apr 2 05:14:03 CDT 2009


Sorry, I used ui.warning, it should be ui.warn

Here is a corrected patch, previously submitted patches apply
correctly on top of this one.

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -378,40 +378,56 @@
         except error.SignatureError:
             raise error.ParseError(cmd, _("invalid arguments"))

-    if options['profile']:
-        import hotshot, hotshot.stats
-        prof = hotshot.Profile("hg.prof")
-        try:
+    if options['profile'] or options['lsprof']:
+        format = ui.config('profiling', 'format')
+
+        if format and not format in ['hotshot', 'lsprof']:
+            ui.warn(_("Unknown profiling format '%s'"
+                        " - Ignored\n") % format)
+            format = None
+
+        if not format:
+            # Fallback
+            if options['profile']:
+                format = 'hotshot'
+            else:
+                # options['lsprof']
+                format = 'lsprof'
+
+        if format == 'hotshot':
+            import hotshot, hotshot.stats
+            prof = hotshot.Profile("hg.prof")
             try:
-                return prof.runcall(checkargs)
-            except:
                 try:
-                    ui.warn(_('exception raised - generating '
-                             'profile anyway\n'))
+                    return prof.runcall(checkargs)
                 except:
-                    pass
-                raise
-        finally:
-            prof.close()
-            stats = hotshot.stats.load("hg.prof")
-            stats.strip_dirs()
-            stats.sort_stats('time', 'calls')
-            stats.print_stats(40)
-    elif options['lsprof']:
-        try:
-            from mercurial import lsprof
-        except ImportError:
-            raise util.Abort(_(
-                'lsprof not available - install from '
-                'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/'))
-        p = lsprof.Profiler()
-        p.enable(subcalls=True)
-        try:
-            return checkargs()
-        finally:
-            p.disable()
-            stats = lsprof.Stats(p.getstats())
-            stats.sort()
-            stats.pprint(top=10, file=sys.stderr, climit=5)
+                    try:
+                        ui.warn(_('exception raised - generating '
+                                 'profile anyway\n'))
+                    except:
+                        pass
+                    raise
+            finally:
+                prof.close()
+                stats = hotshot.stats.load("hg.prof")
+                stats.strip_dirs()
+                stats.sort_stats('time', 'calls')
+                stats.print_stats(40)
+        elif format == 'lsprof':
+            try:
+                from mercurial import lsprof
+            except ImportError:
+                raise util.Abort(_(
+                    'lsprof not available - install from '
+                    'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/'))
+            p = lsprof.Profiler()
+            p.enable(subcalls=True)
+            try:
+                return checkargs()
+            finally:
+                p.disable()
+                stats = lsprof.Stats(p.getstats())
+                stats.sort()
+                stats.pprint(top=10, file=sys.stderr, climit=5)
     else:
         return checkargs()


More information about the Mercurial-devel mailing list