All of lore.kernel.org
 help / color / mirror / Atom feed
* GIT_TRACE_PERFORMANCE and pager
@ 2016-02-29 11:25 Christian Couder
  2016-02-29 11:39 ` Jeff King
  0 siblings, 1 reply; 5+ messages in thread
From: Christian Couder @ 2016-02-29 11:25 UTC (permalink / raw)
  To: git; +Cc: Karsten Blees, Junio C Hamano

Hi,

It looks like setting GIT_TRACE_PERFORMANCE to 1 or 2 (for stdout or
stderr) does not always work well with commands that use a pager, for
example:

-------------
> GIT_TRACE_PERFORMANCE=2 git log -1
commit f02fbc4f9433937ee0463d0342d6d7d97e1f6f1e
Author: Junio C Hamano <gitster@pobox.com>
Date:   Fri Feb 26 13:45:26 2016 -0800

    Git 2.8-rc0

    Signed-off-by: Junio C Hamano <gitster@pobox.com>
-------------

In the above the GIT_TRACE_PERFORMANCE output is missing.

When I use "--no-pager", I get the GIT_TRACE_PERFORMANCE output:

-------------
> GIT_TRACE_PERFORMANCE=2 git --no-pager log -1
commit f02fbc4f9433937ee0463d0342d6d7d97e1f6f1e
Author: Junio C Hamano <gitster@pobox.com>
Date:   Fri Feb 26 13:45:26 2016 -0800

    Git 2.8-rc0

    Signed-off-by: Junio C Hamano <gitster@pobox.com>
12:16:31.258462 trace.c:420             performance: 0.001415428 s:
git command: 'git' '--no-pager' 'log' '-1'
-------------

Setting GIT_TRACE to 1 or 2 seems to work, but maybe it is because it
outputs stuff at the beginning of the process and not at the end.

Cheers,
Christian.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GIT_TRACE_PERFORMANCE and pager
  2016-02-29 11:25 GIT_TRACE_PERFORMANCE and pager Christian Couder
@ 2016-02-29 11:39 ` Jeff King
  2016-02-29 13:46   ` Christian Couder
  2016-02-29 16:47   ` Junio C Hamano
  0 siblings, 2 replies; 5+ messages in thread
From: Jeff King @ 2016-02-29 11:39 UTC (permalink / raw)
  To: Christian Couder; +Cc: git, Karsten Blees, Junio C Hamano

On Mon, Feb 29, 2016 at 12:25:49PM +0100, Christian Couder wrote:

> Setting GIT_TRACE to 1 or 2 seems to work, but maybe it is because it
> outputs stuff at the beginning of the process and not at the end.

Yeah, I think so. Try this (on Linux):

  $ GIT_PAGER='sed s/^/paged:/' \
    GIT_TRACE_PERFORMANCE=1 \
    strace -f -e write -e 'signal=!sigchld' git -p rev-parse
  strace: Process 31155 attached
  strace: Process 31156 attached
  [pid 31156] +++ exited with 0 +++
  [pid 31155] +++ exited with 0 +++
  write(2, "06:32:30.486995 [pid=31154] trac"..., 114) = -1 EBADF (Bad file descriptor)
  write(2, "Could not trace into fd given by"..., 99) = -1 EBADF (Bad file descriptor)
  +++ exited with 0 +++

We redirect stderr to the pager (note that GIT_TRACE=1 still goes to
stderr; it never goes to stdout). We wait() on the pager process before
we exit the main git process, and we don't print the performance stats
until atexit(). So by the time we get there, the pager must be dead, and
the pipe descriptor is closed (I'm actually kind of surprised we don't
get EPIPE, but it looks like we close the descriptors in
wait_for_pager()).

One workaround is something like:

  GIT_TRACE_PERFORMANCE=3 3>&2 git ...

though I guess I'd question whether trace-performance is interesting at
all for a paged command, since it is also counting the length of time
you spend looking at the pager waiting to hit "q".

-Peff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GIT_TRACE_PERFORMANCE and pager
  2016-02-29 11:39 ` Jeff King
@ 2016-02-29 13:46   ` Christian Couder
  2016-02-29 21:30     ` Jeff King
  2016-02-29 16:47   ` Junio C Hamano
  1 sibling, 1 reply; 5+ messages in thread
From: Christian Couder @ 2016-02-29 13:46 UTC (permalink / raw)
  To: Jeff King; +Cc: git, Karsten Blees, Junio C Hamano

On Mon, Feb 29, 2016 at 12:39 PM, Jeff King <peff@peff.net> wrote:
> On Mon, Feb 29, 2016 at 12:25:49PM +0100, Christian Couder wrote:
>
>> Setting GIT_TRACE to 1 or 2 seems to work, but maybe it is because it
>> outputs stuff at the beginning of the process and not at the end.
>
> Yeah, I think so. Try this (on Linux):
>
>   $ GIT_PAGER='sed s/^/paged:/' \
>     GIT_TRACE_PERFORMANCE=1 \
>     strace -f -e write -e 'signal=!sigchld' git -p rev-parse
>   strace: Process 31155 attached
>   strace: Process 31156 attached
>   [pid 31156] +++ exited with 0 +++
>   [pid 31155] +++ exited with 0 +++
>   write(2, "06:32:30.486995 [pid=31154] trac"..., 114) = -1 EBADF (Bad file descriptor)
>   write(2, "Could not trace into fd given by"..., 99) = -1 EBADF (Bad file descriptor)
>   +++ exited with 0 +++

Yeah, I get the same thing.

> We redirect stderr to the pager (note that GIT_TRACE=1 still goes to
> stderr; it never goes to stdout). We wait() on the pager process before
> we exit the main git process, and we don't print the performance stats
> until atexit(). So by the time we get there, the pager must be dead, and
> the pipe descriptor is closed (I'm actually kind of surprised we don't
> get EPIPE, but it looks like we close the descriptors in
> wait_for_pager()).
>
> One workaround is something like:
>
>   GIT_TRACE_PERFORMANCE=3 3>&2 git ...

Yeah, that works.

> though I guess I'd question whether trace-performance is interesting at
> all for a paged command, since it is also counting the length of time
> you spend looking at the pager waiting to hit "q".

In case of "GIT_TRACE_PERFORMANCE=2 git log -1", it doesn't count the
time spent looking at the pager because the output is small, so 'less'
exits immediately, and it could give the impression that
GIT_TRACE_PERFORMANCE is not working.

I am preparing a patch to Documentation/technical/api-trace.txt to
warn about that.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GIT_TRACE_PERFORMANCE and pager
  2016-02-29 11:39 ` Jeff King
  2016-02-29 13:46   ` Christian Couder
@ 2016-02-29 16:47   ` Junio C Hamano
  1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2016-02-29 16:47 UTC (permalink / raw)
  To: Jeff King; +Cc: Christian Couder, git, Karsten Blees

On Mon, Feb 29, 2016 at 3:39 AM, Jeff King <peff@peff.net> wrote:
> One workaround is something like:
>
>   GIT_TRACE_PERFORMANCE=3 3>&2 git ...
>
> though I guess I'd question whether trace-performance is interesting at
> all for a paged command, since it is also counting the length of time
> you spend looking at the pager waiting to hit "q".

Yup, exactly. I see Christian tried to add something to the documentation,
but I think it is sufficient to suggest running commands with --no-pager.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GIT_TRACE_PERFORMANCE and pager
  2016-02-29 13:46   ` Christian Couder
@ 2016-02-29 21:30     ` Jeff King
  0 siblings, 0 replies; 5+ messages in thread
From: Jeff King @ 2016-02-29 21:30 UTC (permalink / raw)
  To: Christian Couder; +Cc: git, Karsten Blees, Junio C Hamano

On Mon, Feb 29, 2016 at 02:46:12PM +0100, Christian Couder wrote:

> > though I guess I'd question whether trace-performance is interesting at
> > all for a paged command, since it is also counting the length of time
> > you spend looking at the pager waiting to hit "q".
> 
> In case of "GIT_TRACE_PERFORMANCE=2 git log -1", it doesn't count the
> time spent looking at the pager because the output is small, so 'less'
> exits immediately, and it could give the impression that
> GIT_TRACE_PERFORMANCE is not working.

Ah, right. I don't use "-F" with less, so mine hangs around until I
quit.

-Peff

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-02-29 21:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-29 11:25 GIT_TRACE_PERFORMANCE and pager Christian Couder
2016-02-29 11:39 ` Jeff King
2016-02-29 13:46   ` Christian Couder
2016-02-29 21:30     ` Jeff King
2016-02-29 16:47   ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.