profiling: allow logging profile to the blackbox
authorDurham Goode <durham@fb.com>
Tue, 08 Sep 2015 11:39:52 -0700
changeset 26191 39a0b11158d8
parent 26190 29d29a82263f
child 26192 67e6e55360d2
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.
mercurial/dispatch.py
tests/test-profile.t
--- 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()
--- a/tests/test-profile.t	Fri Sep 04 11:30:38 2015 -0400
+++ b/tests/test-profile.t	Tue Sep 08 11:39:52 2015 -0700
@@ -14,6 +14,9 @@
   $ hg --profile --config profiling.output=../out st
   $ grep CallCount ../out > /dev/null || cat ../out
 
+  $ hg --profile --config profiling.output=blackbox --config extensions.blackbox= st
+  $ grep CallCount .hg/blackbox.log > /dev/null || cat .hg/blackbox.log
+
   $ hg --profile --config profiling.format=text st 2>../out
   $ grep CallCount ../out > /dev/null || cat ../out