Patchwork [2,of,2] profiling: allow logging profile to the blackbox

login
register
mail settings
Submitter Durham Goode
Date Sept. 7, 2015, 7:11 p.m.
Message ID <d72ff051c6c6dee94569.1441653076@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/10413/
State Superseded
Commit 39a0b11158d88e53f43046086ae0eb4de74f469a
Delegated to: Augie Fackler
Headers show

Comments

Durham Goode - Sept. 7, 2015, 7:11 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1441651256 25200
#      Mon Sep 07 11:40:56 2015 -0700
# Node ID d72ff051c6c6dee945690b0e5554a0450820e93e
# Parent  2cd61d6e66c1034c97b7095fdf1d7908dd437b26
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.
Augie Fackler - Sept. 8, 2015, 5:01 p.m.
On Mon, Sep 07, 2015 at 12:11:16PM -0700, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1441651256 25200
> #      Mon Sep 07 11:40:56 2015 -0700
> # Node ID d72ff051c6c6dee945690b0e5554a0450820e93e
> # Parent  2cd61d6e66c1034c97b7095fdf1d7908dd437b26
> profiling: allow logging profile to the blackbox

queued patch 1, I have a question about this one (which I may fix in
flight depending on the answer, though bonus points for just rolling a
v2 and saving me time)

>
> 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.
>
> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -1021,7 +1021,10 @@ def _runcommand(ui, options, cmd, cmdfun
>
>          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:
> @@ -1036,6 +1039,10 @@ def _runcommand(ui, options, cmd, cmdfun
>                  return statprofile(ui, checkargs, fp)
>          finally:
>              if output:
> +                if output == 'blackbox':
> +                    val = "Profile:\n%s" % fp.getvalue()
> +                    val = val.replace('%', '%%')

This looks funny. At least put a comment here why you have to escape
the %s here?

> +                    ui.log('profile', val)
>                  fp.close()
>      else:
>          return checkargs()
> diff --git a/tests/test-profile.t b/tests/test-profile.t
> --- a/tests/test-profile.t
> +++ b/tests/test-profile.t
> @@ -14,6 +14,9 @@ test --profile
>    $ 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
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
Durham Goode - Sept. 8, 2015, 6:42 p.m.
On 9/8/15 10:01 AM, Augie Fackler wrote:
> On Mon, Sep 07, 2015 at 12:11:16PM -0700, Durham Goode wrote:
>> # HG changeset patch
>> # User Durham Goode <durham@fb.com>
>> # Date 1441651256 25200
>> #      Mon Sep 07 11:40:56 2015 -0700
>> # Node ID d72ff051c6c6dee945690b0e5554a0450820e93e
>> # Parent  2cd61d6e66c1034c97b7095fdf1d7908dd437b26
>> profiling: allow logging profile to the blackbox
> queued patch 1, I have a question about this one (which I may fix in
> flight depending on the answer, though bonus points for just rolling a
> v2 and saving me time)
V2 sent
>
>> 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.
>>
>> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
>> --- a/mercurial/dispatch.py
>> +++ b/mercurial/dispatch.py
>> @@ -1021,7 +1021,10 @@ def _runcommand(ui, options, cmd, cmdfun
>>
>>           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:
>> @@ -1036,6 +1039,10 @@ def _runcommand(ui, options, cmd, cmdfun
>>                   return statprofile(ui, checkargs, fp)
>>           finally:
>>               if output:
>> +                if output == 'blackbox':
>> +                    val = "Profile:\n%s" % fp.getvalue()
>> +                    val = val.replace('%', '%%')
> This looks funny. At least put a comment here why you have to escape
> the %s here?
>
>> +                    ui.log('profile', val)
>>                   fp.close()
>>       else:
>>           return checkargs()
>> diff --git a/tests/test-profile.t b/tests/test-profile.t
>> --- a/tests/test-profile.t
>> +++ b/tests/test-profile.t
>> @@ -14,6 +14,9 @@ test --profile
>>     $ 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
>>
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel@selenic.com
>> https://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -1021,7 +1021,10 @@  def _runcommand(ui, options, cmd, cmdfun
 
         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:
@@ -1036,6 +1039,10 @@  def _runcommand(ui, options, cmd, cmdfun
                 return statprofile(ui, checkargs, fp)
         finally:
             if output:
+                if output == 'blackbox':
+                    val = "Profile:\n%s" % fp.getvalue()
+                    val = val.replace('%', '%%')
+                    ui.log('profile', val)
                 fp.close()
     else:
         return checkargs()
diff --git a/tests/test-profile.t b/tests/test-profile.t
--- a/tests/test-profile.t
+++ b/tests/test-profile.t
@@ -14,6 +14,9 @@  test --profile
   $ 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