diff mercurial/dispatch.py @ 26191:39a0b11158d8

profiling: allow logging profile to the blackbox This allows specifying '--config profiling.output=blackbox' which will log the profile output to the blackbox (if enabled). This is useful for doing profiling on the server since it allows us to record the command, it's result, any exceptions, and it's profile, all in one spot. And we get log rotation for free.
author Durham Goode <durham@fb.com>
date Tue, 08 Sep 2015 11:39:52 -0700
parents eb2187ebdf8a
children e86d12404d69
line wrap: on
line diff
--- a/mercurial/dispatch.py	Fri Sep 04 11:30:38 2015 -0400
+++ b/mercurial/dispatch.py	Tue Sep 08 11:39:52 2015 -0700
@@ -1023,7 +1023,10 @@
 
         output = ui.config('profiling', 'output')
 
-        if output:
+        if output == 'blackbox':
+            import StringIO
+            fp = StringIO.StringIO()
+        elif output:
             path = ui.expandpath(output)
             fp = open(path, 'wb')
         else:
@@ -1038,6 +1041,12 @@
                 return statprofile(ui, checkargs, fp)
         finally:
             if output:
+                if output == 'blackbox':
+                    val = "Profile:\n%s" % fp.getvalue()
+                    # ui.log treats the input as a format string,
+                    # so we need to escape any % signs.
+                    val = val.replace('%', '%%')
+                    ui.log('profile', val)
                 fp.close()
     else:
         return checkargs()