git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] trace2: don't include "fsync" events in all trace2 logs
@ 2022-06-23 15:51 Ævar Arnfjörð Bjarmason
  2022-06-23 18:21 ` [EXTERNAL] " Neeraj Singh (WINDOWS-SFS)
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-06-23 15:51 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Neeraj Singh,
	Ævar Arnfjörð Bjarmason

Fix the overly verbose trace2 logging added in 9a4987677d3 (trace2:
add stats for fsync operations, 2022-03-30) (first released with
v2.36.0).

Since that change every single "git" command invocation has included
these "data" events, even though we'll only make use of these with
core.fsyncMethod=batch, and even then only have non-zero values if
we're writing object data to disk. See c0f4752ed2f (core.fsyncmethod:
batched disk flushes for loose-objects, 2022-04-04) for that feature.

The result was that e.g. "git version" would previously emit a total
of 6 trace2 events with the GIT_TRACE2_EVENT target (version, start,
cmd_ancestry, cmd_name, exit, atexit), but afterwards would emit
8. We'd emit 2 "data" events before the "exit" event.

The reason we didn't catch this was that the trace2 unit tests added
in a15860dca3f (trace2: t/helper/test-trace2, t0210.sh, t0211.sh,
t0212.sh, 2019-02-22) would omit any "data" events that weren't the
ones it cared about. Before this change to the C code 6/7 of our
"t/t0212-trace2-event.sh" tests would fail if this change was applied
to "t/t0212/parse_events.perl".

Let's make the trace2 testing more strict, and further append any new
events types we don't know about in "t/t0212/parse_events.perl". Since
we only invoke the "test-tool trace2" there's no guarantee that we'll
catch other overly verbose events in the future, but we'll at least
notice if we start emitting new events that are issues every time we
log anything with trace2's JSON target.

We exclude the "data_json" event type, we'd otherwise would fail on
both "win test" and "win+VS test" CI due to the logging added in
353d3d77f4f (trace2: collect Windows-specific process information,
2019-02-22). It looks like that logging should really be using
trace2_cmd_ancestry() instead, which was introduced later in
2f732bf15e6 (tr2: log parent process name, 2021-07-21), but let's
leave it for now.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---

This is a fix for a v2.36.0 regression/change, so perhaps it's
categorically out for v2.37.0, but given how isolated the fix is & how
verbose the new trace2 data is perhaps it's worth including anyway.

Passing CI at: https://github.com/avar/git/actions/runs/2548732003

 t/t0212/parse_events.perl | 17 +++++++++++------
 wrapper.c                 |  3 +++
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/t/t0212/parse_events.perl b/t/t0212/parse_events.perl
index b6408560c0c..389cf6f61c4 100644
--- a/t/t0212/parse_events.perl
+++ b/t/t0212/parse_events.perl
@@ -216,12 +216,17 @@
 
     elsif ($event eq 'data') {
 	my $cat = $line->{'category'};
-	if ($cat eq 'test_category') {
-	    
-	    my $key = $line->{'key'};
-	    my $value = $line->{'value'};
-	    $processes->{$sid}->{'data'}->{$cat}->{$key} = $value;
-	}
+	my $key = $line->{'key'};
+	my $value = $line->{'value'};
+	$processes->{$sid}->{'data'}->{$cat}->{$key} = $value;
+    }
+
+    elsif ($event eq 'data_json') {
+	# Ignore due to compat/win32/trace2_win32_process_info.c
+    }
+
+    else {
+	push @{$processes->{$sid}->{$event}} => $line->{value};
     }
 
     # This trace2 target does not emit 'printf' events.
diff --git a/wrapper.c b/wrapper.c
index 1c3c970080b..eebd764131f 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -618,6 +618,9 @@ int git_fsync(int fd, enum fsync_action action)
 
 void trace_git_fsync_stats(void)
 {
+	if (!count_fsync_writeout_only && !count_fsync_hardware_flush)
+		return;
+
 	trace2_data_intmax("fsync", the_repository, "fsync/writeout-only", count_fsync_writeout_only);
 	trace2_data_intmax("fsync", the_repository, "fsync/hardware-flush", count_fsync_hardware_flush);
 }
-- 
2.37.0.rc2.867.gbe8216e3e5c


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

* RE: [EXTERNAL] [PATCH] trace2: don't include "fsync" events in all trace2 logs
  2022-06-23 15:51 [PATCH] trace2: don't include "fsync" events in all trace2 logs Ævar Arnfjörð Bjarmason
@ 2022-06-23 18:21 ` Neeraj Singh (WINDOWS-SFS)
  2022-06-23 19:34 ` Junio C Hamano
  2022-06-30  8:56 ` [PATCH v2] " Ævar Arnfjörð Bjarmason
  2 siblings, 0 replies; 8+ messages in thread
From: Neeraj Singh (WINDOWS-SFS) @ 2022-06-23 18:21 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason, git@vger.kernel.org
  Cc: Junio C Hamano

This patch looks good to me. 

Thanks,
Neeraj

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

* Re: [PATCH] trace2: don't include "fsync" events in all trace2 logs
  2022-06-23 15:51 [PATCH] trace2: don't include "fsync" events in all trace2 logs Ævar Arnfjörð Bjarmason
  2022-06-23 18:21 ` [EXTERNAL] " Neeraj Singh (WINDOWS-SFS)
@ 2022-06-23 19:34 ` Junio C Hamano
  2022-06-30  8:56 ` [PATCH v2] " Ævar Arnfjörð Bjarmason
  2 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2022-06-23 19:34 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: git, Neeraj Singh

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> Fix the overly verbose trace2 logging added in 9a4987677d3 (trace2:
> add stats for fsync operations, 2022-03-30) (first released with
> v2.36.0).
>
> Since that change every single "git" command invocation has included
> these "data" events, even though we'll only make use of these with
> core.fsyncMethod=batch, and even then only have non-zero values if
> we're writing object data to disk. See c0f4752ed2f (core.fsyncmethod:
> batched disk flushes for loose-objects, 2022-04-04) for that feature.
>
> The result was that e.g. "git version" would previously emit a total
> of 6 trace2 events with the GIT_TRACE2_EVENT target (version, start,
> cmd_ancestry, cmd_name, exit, atexit), but afterwards would emit
> 8. We'd emit 2 "data" events before the "exit" event.
>
> The reason we didn't catch this was that the trace2 unit tests added
> in a15860dca3f (trace2: t/helper/test-trace2, t0210.sh, t0211.sh,
> t0212.sh, 2019-02-22) would omit any "data" events that weren't the
> ones it cared about. Before this change to the C code 6/7 of our
> "t/t0212-trace2-event.sh" tests would fail if this change was applied
> to "t/t0212/parse_events.perl".
>
> Let's make the trace2 testing more strict, and further append any new
> events types we don't know about in "t/t0212/parse_events.perl". Since
> we only invoke the "test-tool trace2" there's no guarantee that we'll
> catch other overly verbose events in the future, but we'll at least
> notice if we start emitting new events that are issues every time we
> log anything with trace2's JSON target.
>
> We exclude the "data_json" event type, we'd otherwise would fail on
> both "win test" and "win+VS test" CI due to the logging added in
> 353d3d77f4f (trace2: collect Windows-specific process information,
> 2019-02-22). It looks like that logging should really be using
> trace2_cmd_ancestry() instead, which was introduced later in
> 2f732bf15e6 (tr2: log parent process name, 2021-07-21), but let's
> leave it for now.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>
> This is a fix for a v2.36.0 regression/change, so perhaps it's
> categorically out for v2.37.0, but given how isolated the fix is & how
> verbose the new trace2 data is perhaps it's worth including anyway.
>
> Passing CI at: https://github.com/avar/git/actions/runs/2548732003
>
>  t/t0212/parse_events.perl | 17 +++++++++++------
>  wrapper.c                 |  3 +++
>  2 files changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/t/t0212/parse_events.perl b/t/t0212/parse_events.perl
> index b6408560c0c..389cf6f61c4 100644
> --- a/t/t0212/parse_events.perl
> +++ b/t/t0212/parse_events.perl
> @@ -216,12 +216,17 @@
>  
>      elsif ($event eq 'data') {
>  	my $cat = $line->{'category'};
> +	my $key = $line->{'key'};
> +	my $value = $line->{'value'};
> +	$processes->{$sid}->{'data'}->{$cat}->{$key} = $value;
> +    }
> +
> +    elsif ($event eq 'data_json') {
> +	# Ignore due to compat/win32/trace2_win32_process_info.c
> +    }
> +
> +    else {
> +	push @{$processes->{$sid}->{$event}} => $line->{value};
>      }

The special casing is unfortunate, but if it is "let's leave it for
now", probably we should leave a NEEDSWORK comment here to remind
us, instead of giving a false impresion that abusing data_json is
OK?

> diff --git a/wrapper.c b/wrapper.c
> index 1c3c970080b..eebd764131f 100644
> --- a/wrapper.c
> +++ b/wrapper.c
> @@ -618,6 +618,9 @@ int git_fsync(int fd, enum fsync_action action)
>  
>  void trace_git_fsync_stats(void)
>  {
> +	if (!count_fsync_writeout_only && !count_fsync_hardware_flush)
> +		return;
> +

OK, both counters are unconditionally incremented whenever the
corresponding action triggers, so this implementation is probably OK
for now, but I suspect that it would become a maintenance burden if
we were to add more fsync actions later.

>  	trace2_data_intmax("fsync", the_repository, "fsync/writeout-only", count_fsync_writeout_only);
>  	trace2_data_intmax("fsync", the_repository, "fsync/hardware-flush", count_fsync_hardware_flush);

If each of these is guarded with "show only when non-zero", that
would become less problematic, though.

A bigger issue is when somebody is debugging the callers of
git_fsync() wondering why they do not trigger.  Getting log entries
that say "no git_fsync() call with these actions have been made"
may be useful (i.e. explicitly negative answer).

I am not sure if it is a good solution in the longer term, but this
implementation may be a good-enough way to squelch the immediate
loudness issue.

Thanks.


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

* [PATCH v2] trace2: don't include "fsync" events in all trace2 logs
  2022-06-23 15:51 [PATCH] trace2: don't include "fsync" events in all trace2 logs Ævar Arnfjörð Bjarmason
  2022-06-23 18:21 ` [EXTERNAL] " Neeraj Singh (WINDOWS-SFS)
  2022-06-23 19:34 ` Junio C Hamano
@ 2022-06-30  8:56 ` Ævar Arnfjörð Bjarmason
  2022-06-30 20:45   ` Junio C Hamano
  2022-07-18 10:31   ` [PATCH v3] trace2: only include "fsync" events if we git_fsync() Ævar Arnfjörð Bjarmason
  2 siblings, 2 replies; 8+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-06-30  8:56 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Neeraj Singh,
	Ævar Arnfjörð Bjarmason

Fix the overly verbose trace2 logging added in 9a4987677d3 (trace2:
add stats for fsync operations, 2022-03-30) (first released with
v2.36.0).

Since that change every single "git" command invocation has included
these "data" events, even though we'll only make use of these with
core.fsyncMethod=batch, and even then only have non-zero values if
we're writing object data to disk. See c0f4752ed2f (core.fsyncmethod:
batched disk flushes for loose-objects, 2022-04-04) for that feature.

As we're needing to indent the trace2_data_intmax() lines let's
introduce helper variables to ensure that our resulting lines (which
were already too) don't exceed the recommendations of the
CodingGuidelines. Doing that requires either wrapping them twice, or
introducing short throwaway variable names, let's do the latter.

The result was that e.g. "git version" would previously emit a total
of 6 trace2 events with the GIT_TRACE2_EVENT target (version, start,
cmd_ancestry, cmd_name, exit, atexit), but afterwards would emit
8. We'd emit 2 "data" events before the "exit" event.

The reason we didn't catch this was that the trace2 unit tests added
in a15860dca3f (trace2: t/helper/test-trace2, t0210.sh, t0211.sh,
t0212.sh, 2019-02-22) would omit any "data" events that weren't the
ones it cared about. Before this change to the C code 6/7 of our
"t/t0212-trace2-event.sh" tests would fail if this change was applied
to "t/t0212/parse_events.perl".

Let's make the trace2 testing more strict, and further append any new
events types we don't know about in "t/t0212/parse_events.perl". Since
we only invoke the "test-tool trace2" there's no guarantee that we'll
catch other overly verbose events in the future, but we'll at least
notice if we start emitting new events that are issues every time we
log anything with trace2's JSON target.

We exclude the "data_json" event type, we'd otherwise would fail on
both "win test" and "win+VS test" CI due to the logging added in
353d3d77f4f (trace2: collect Windows-specific process information,
2019-02-22). It looks like that logging should really be using
trace2_cmd_ancestry() instead, which was introduced later in
2f732bf15e6 (tr2: log parent process name, 2021-07-21), but let's
leave it for now.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---

I think this re-roll addresses the concerns Junio brought up in:
https://lore.kernel.org/git/xmqqh74byy19.fsf@gitster.g/; As to the
larger question of:

On Thu, Jun 23 2022, Junio C Hamano wrote:

> I am not sure if it is a good solution in the longer term, but this
> implementation may be a good-enough way to squelch the immediate
> loudness issue.

I think a better long-term solution in this case, per the initial
feedback on the patch would be to have a generic facility to trace2
log how often we call a given syscall:

	https://lore.kernel.org/git/220330.86zgl7o8l8.gmgdl@evledraar.gmail.com/

I.e. in most (all?) other cases our trace2 logging is logging git's
"business logic", but in this case the logging is functionally the
same as a more dumb interception of an arbitrary system call, and then
having some generic "syscall stats" trace2 event.

In this case such a generic logger would need to be a bit smarter than
just a dumb wrapper, i.e. we'd need:

    fsync() != EINTR /* due to fsync_loop() */
    sync_file_range()

That still wouldn't be the same as the current logging if implemented
correctly, but I think in a good way. E.g. now we'll log a failed
fsync() the same as a successful one, as we increment the counter
before seeing what the return value was.

But anyway, as noted in the original thread Neeraj didn't have time to
look into that, neither do I, and the patch is now a part of git. So
let's solve the immediate issue of verbose logging, and leave any
other improvements for the future.

Range-diff against v1:
1:  df87e515efd ! 1:  a1fc37de947 trace2: don't include "fsync" events in all trace2 logs
    @@ Commit message
         we're writing object data to disk. See c0f4752ed2f (core.fsyncmethod:
         batched disk flushes for loose-objects, 2022-04-04) for that feature.
     
    +    As we're needing to indent the trace2_data_intmax() lines let's
    +    introduce helper variables to ensure that our resulting lines (which
    +    were already too) don't exceed the recommendations of the
    +    CodingGuidelines. Doing that requires either wrapping them twice, or
    +    introducing short throwaway variable names, let's do the latter.
    +
         The result was that e.g. "git version" would previously emit a total
         of 6 trace2 events with the GIT_TRACE2_EVENT target (version, start,
         cmd_ancestry, cmd_name, exit, atexit), but afterwards would emit
    @@ t/t0212/parse_events.perl
     +    }
     +
     +    elsif ($event eq 'data_json') {
    -+	# Ignore due to compat/win32/trace2_win32_process_info.c
    ++	# NEEDSWORK: Ignore due to
    ++	# compat/win32/trace2_win32_process_info.c, which should log a
    ++	# "cmd_ancestry" event instead.
     +    }
     +
     +    else {
    @@ wrapper.c: int git_fsync(int fd, enum fsync_action action)
      
      void trace_git_fsync_stats(void)
      {
    -+	if (!count_fsync_writeout_only && !count_fsync_hardware_flush)
    -+		return;
    +-	trace2_data_intmax("fsync", the_repository, "fsync/writeout-only", count_fsync_writeout_only);
    +-	trace2_data_intmax("fsync", the_repository, "fsync/hardware-flush", count_fsync_hardware_flush);
    ++	const struct repository *r = the_repository;
    ++	const intmax_t cfwo = count_fsync_writeout_only;
    ++	const intmax_t cfhf = count_fsync_hardware_flush;
     +
    - 	trace2_data_intmax("fsync", the_repository, "fsync/writeout-only", count_fsync_writeout_only);
    - 	trace2_data_intmax("fsync", the_repository, "fsync/hardware-flush", count_fsync_hardware_flush);
    ++	if (cfwo)
    ++		trace2_data_intmax("fsync", r, "fsync/writeout-only", cfwo);
    ++	if (cfhf)
    ++		trace2_data_intmax("fsync", r, "fsync/hardware-flush", cfhf);
      }
    + 
    + static int warn_if_unremovable(const char *op, const char *file, int rc)

 t/t0212/parse_events.perl | 19 +++++++++++++------
 wrapper.c                 | 10 ++++++++--
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/t/t0212/parse_events.perl b/t/t0212/parse_events.perl
index b6408560c0c..30a9f51e9f1 100644
--- a/t/t0212/parse_events.perl
+++ b/t/t0212/parse_events.perl
@@ -216,12 +216,19 @@
 
     elsif ($event eq 'data') {
 	my $cat = $line->{'category'};
-	if ($cat eq 'test_category') {
-	    
-	    my $key = $line->{'key'};
-	    my $value = $line->{'value'};
-	    $processes->{$sid}->{'data'}->{$cat}->{$key} = $value;
-	}
+	my $key = $line->{'key'};
+	my $value = $line->{'value'};
+	$processes->{$sid}->{'data'}->{$cat}->{$key} = $value;
+    }
+
+    elsif ($event eq 'data_json') {
+	# NEEDSWORK: Ignore due to
+	# compat/win32/trace2_win32_process_info.c, which should log a
+	# "cmd_ancestry" event instead.
+    }
+
+    else {
+	push @{$processes->{$sid}->{$event}} => $line->{value};
     }
 
     # This trace2 target does not emit 'printf' events.
diff --git a/wrapper.c b/wrapper.c
index 1c3c970080b..67727f95411 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -618,8 +618,14 @@ int git_fsync(int fd, enum fsync_action action)
 
 void trace_git_fsync_stats(void)
 {
-	trace2_data_intmax("fsync", the_repository, "fsync/writeout-only", count_fsync_writeout_only);
-	trace2_data_intmax("fsync", the_repository, "fsync/hardware-flush", count_fsync_hardware_flush);
+	const struct repository *r = the_repository;
+	const intmax_t cfwo = count_fsync_writeout_only;
+	const intmax_t cfhf = count_fsync_hardware_flush;
+
+	if (cfwo)
+		trace2_data_intmax("fsync", r, "fsync/writeout-only", cfwo);
+	if (cfhf)
+		trace2_data_intmax("fsync", r, "fsync/hardware-flush", cfhf);
 }
 
 static int warn_if_unremovable(const char *op, const char *file, int rc)
-- 
2.37.0.880.gf07d56b18ba


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

* Re: [PATCH v2] trace2: don't include "fsync" events in all trace2 logs
  2022-06-30  8:56 ` [PATCH v2] " Ævar Arnfjörð Bjarmason
@ 2022-06-30 20:45   ` Junio C Hamano
  2022-07-18 10:31   ` [PATCH v3] trace2: only include "fsync" events if we git_fsync() Ævar Arnfjörð Bjarmason
  1 sibling, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2022-06-30 20:45 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: git, Neeraj Singh

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> As we're needing to indent the trace2_data_intmax() lines let's
> introduce helper variables to ensure that our resulting lines (which
> were already too) don't exceed the recommendations of the

too -> too something

> +    elsif ($event eq 'data_json') {
> +	# NEEDSWORK: Ignore due to
> +	# compat/win32/trace2_win32_process_info.c, which should log a
> +	# "cmd_ancestry" event instead.
> +    }

This does read better.

>  void trace_git_fsync_stats(void)
>  {
> -	trace2_data_intmax("fsync", the_repository, "fsync/writeout-only", count_fsync_writeout_only);
> -	trace2_data_intmax("fsync", the_repository, "fsync/hardware-flush", count_fsync_hardware_flush);
> +	const struct repository *r = the_repository;
> +	const intmax_t cfwo = count_fsync_writeout_only;
> +	const intmax_t cfhf = count_fsync_hardware_flush;
> +
> +	if (cfwo)
> +		trace2_data_intmax("fsync", r, "fsync/writeout-only", cfwo);
> +	if (cfhf)
> +		trace2_data_intmax("fsync", r, "fsync/hardware-flush", cfhf);

I would have wrapped the lines instead of introducing these extra
variables; the key observation is that it would make a much easier
pattern to follow for a future developer who needs to add the third
kind of "fsync" on top of the existing wo and hf.

But we can address that when somebody actually adds the third one,
so let's take the patch as-is.

Thanks.

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

* [PATCH v3] trace2: only include "fsync" events if we git_fsync()
  2022-06-30  8:56 ` [PATCH v2] " Ævar Arnfjörð Bjarmason
  2022-06-30 20:45   ` Junio C Hamano
@ 2022-07-18 10:31   ` Ævar Arnfjörð Bjarmason
  2022-07-18 16:50     ` Junio C Hamano
  1 sibling, 1 reply; 8+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-07-18 10:31 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Neeraj Singh, Han Xin,
	Ævar Arnfjörð Bjarmason

Fix the overly verbose trace2 logging added in 9a4987677d3 (trace2:
add stats for fsync operations, 2022-03-30) (first released with
v2.36.0).

Since that change every single "git" command invocation has included
these "data" events, even though we'll only make use of these with
core.fsyncMethod=batch, and even then only have non-zero values if
we're writing object data to disk. See c0f4752ed2f (core.fsyncmethod:
batched disk flushes for loose-objects, 2022-04-04) for that feature.

As we're needing to indent the trace2_data_intmax() lines let's
introduce helper variables to ensure that our resulting lines (which
were already too) don't exceed the recommendations of the
CodingGuidelines. Doing that requires either wrapping them twice, or
introducing short throwaway variable names, let's do the latter.

The result was that e.g. "git version" would previously emit a total
of 6 trace2 events with the GIT_TRACE2_EVENT target (version, start,
cmd_ancestry, cmd_name, exit, atexit), but afterwards would emit
8. We'd emit 2 "data" events before the "exit" event.

The reason we didn't catch this was that the trace2 unit tests added
in a15860dca3f (trace2: t/helper/test-trace2, t0210.sh, t0211.sh,
t0212.sh, 2019-02-22) would omit any "data" events that weren't the
ones it cared about. Before this change to the C code 6/7 of our
"t/t0212-trace2-event.sh" tests would fail if this change was applied
to "t/t0212/parse_events.perl".

Let's make the trace2 testing more strict, and further append any new
events types we don't know about in "t/t0212/parse_events.perl". Since
we only invoke the "test-tool trace2" there's no guarantee that we'll
catch other overly verbose events in the future, but we'll at least
notice if we start emitting new events that are issues every time we
log anything with trace2's JSON target.

We exclude the "data_json" event type, we'd otherwise would fail on
both "win test" and "win+VS test" CI due to the logging added in
353d3d77f4f (trace2: collect Windows-specific process information,
2019-02-22). It looks like that logging should really be using
trace2_cmd_ancestry() instead, which was introduced later in
2f732bf15e6 (tr2: log parent process name, 2021-07-21), but let's
leave it for now.

The fix-up to aaf81223f48 (unpack-objects: use stream_loose_object()
to unpack large objects, 2022-06-11) is needed because we're changing
the behavior of these events as discussed above. Since we'd always
emit a "hardware-flush" event the test added in aaf81223f48 wasn't
testing anything except that this trace2 data was unconditionally
logged. Even if "core.fsyncMethod" wasn't set to "batch" we'd pass the
test.

Now we'll check the expected number of "writeout" v.s. "flush" calls
under "core.fsyncMethod=batch", but note that this doesn't actually
test if we carried out the sync using that method, on a platform where
we'd have to fall back to fsync() each of those "writeout" would
really be a "flush" (i.e. a full fsync()).

But in this case what we're testing is that the logic in
"unpack-objects" behaves as expected, not the OS-specific question of
whether we actually were able to use the "bulk" method.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---

This v3:

 * Fixes the failing tests, due to a merge with
   hx/unpack-streaming. See details at:
   https://lore.kernel.org/git/220715.86bktqzdb8.gmgdl@evledraar.gmail.com/

   We now test how many "writeout" and "flush" sync events we emit,
   rather than the (meaningless) previous behavior (see above)>

 * Creates a log_trace_fsync_if() helper in wrapper.c, to avoid both
   the duplication and line-wrapping issues previous rounds tried to
   address more verbosely.

Range-diff against v2:
1:  a1fc37de947 ! 1:  979dea5956a trace2: don't include "fsync" events in all trace2 logs
    @@ Metadata
     Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## Commit message ##
    -    trace2: don't include "fsync" events in all trace2 logs
    +    trace2: only include "fsync" events if we git_fsync()
     
         Fix the overly verbose trace2 logging added in 9a4987677d3 (trace2:
         add stats for fsync operations, 2022-03-30) (first released with
    @@ Commit message
         2f732bf15e6 (tr2: log parent process name, 2021-07-21), but let's
         leave it for now.
     
    +    The fix-up to aaf81223f48 (unpack-objects: use stream_loose_object()
    +    to unpack large objects, 2022-06-11) is needed because we're changing
    +    the behavior of these events as discussed above. Since we'd always
    +    emit a "hardware-flush" event the test added in aaf81223f48 wasn't
    +    testing anything except that this trace2 data was unconditionally
    +    logged. Even if "core.fsyncMethod" wasn't set to "batch" we'd pass the
    +    test.
    +
    +    Now we'll check the expected number of "writeout" v.s. "flush" calls
    +    under "core.fsyncMethod=batch", but note that this doesn't actually
    +    test if we carried out the sync using that method, on a platform where
    +    we'd have to fall back to fsync() each of those "writeout" would
    +    really be a "flush" (i.e. a full fsync()).
    +
    +    But in this case what we're testing is that the logic in
    +    "unpack-objects" behaves as expected, not the OS-specific question of
    +    whether we actually were able to use the "bulk" method.
    +
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## t/t0212/parse_events.perl ##
    @@ t/t0212/parse_events.perl
      
          # This trace2 target does not emit 'printf' events.
     
    + ## t/t5351-unpack-large-objects.sh ##
    +@@ t/t5351-unpack-large-objects.sh: test_expect_success 'unpack big object in stream' '
    + 	test_dir_is_empty dest.git/objects/pack
    + '
    + 
    ++check_fsync_events () {
    ++	local trace="$1" &&
    ++	shift &&
    ++
    ++	cat >expect &&
    ++	sed -n \
    ++		-e '/^{"event":"data",.*"category":"fsync",/ {
    ++			s/.*"category":"fsync",//;
    ++			s/}$//;
    ++			p;
    ++		}' \
    ++		<"$trace" >actual &&
    ++	test_cmp expect actual
    ++}
    ++
    + BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch'
    + 
    + test_expect_success 'unpack big object in stream (core.fsyncmethod=batch)' '
    + 	prepare_dest 1m &&
    + 	GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
    ++	GIT_TEST_FSYNC=true \
    + 		git -C dest.git $BATCH_CONFIGURATION unpack-objects <pack-$PACK.pack &&
    +-	grep fsync/hardware-flush trace2.txt &&
    ++	check_fsync_events trace2.txt <<-\EOF &&
    ++	"key":"fsync/writeout-only","value":"6"
    ++	"key":"fsync/hardware-flush","value":"1"
    ++	EOF
    ++
    + 	test_dir_is_empty dest.git/objects/pack &&
    + 	git -C dest.git cat-file --batch-check="%(objectname)" <obj-list >current &&
    + 	cmp obj-list current
    +
      ## wrapper.c ##
     @@ wrapper.c: int git_fsync(int fd, enum fsync_action action)
    + 	}
    + }
      
    ++static void log_trace_fsync_if(const char *key, intmax_t value)
    ++{
    ++	if (value)
    ++		trace2_data_intmax("fsync", the_repository, key, value);
    ++}
    ++
      void trace_git_fsync_stats(void)
      {
     -	trace2_data_intmax("fsync", the_repository, "fsync/writeout-only", count_fsync_writeout_only);
     -	trace2_data_intmax("fsync", the_repository, "fsync/hardware-flush", count_fsync_hardware_flush);
    -+	const struct repository *r = the_repository;
    -+	const intmax_t cfwo = count_fsync_writeout_only;
    -+	const intmax_t cfhf = count_fsync_hardware_flush;
    -+
    -+	if (cfwo)
    -+		trace2_data_intmax("fsync", r, "fsync/writeout-only", cfwo);
    -+	if (cfhf)
    -+		trace2_data_intmax("fsync", r, "fsync/hardware-flush", cfhf);
    ++	log_trace_fsync_if("fsync/writeout-only", count_fsync_writeout_only);
    ++	log_trace_fsync_if("fsync/hardware-flush", count_fsync_hardware_flush);
      }
      
      static int warn_if_unremovable(const char *op, const char *file, int rc)

 t/t0212/parse_events.perl       | 19 +++++++++++++------
 t/t5351-unpack-large-objects.sh | 22 +++++++++++++++++++++-
 wrapper.c                       | 10 ++++++++--
 3 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/t/t0212/parse_events.perl b/t/t0212/parse_events.perl
index b6408560c0c..30a9f51e9f1 100644
--- a/t/t0212/parse_events.perl
+++ b/t/t0212/parse_events.perl
@@ -216,12 +216,19 @@
 
     elsif ($event eq 'data') {
 	my $cat = $line->{'category'};
-	if ($cat eq 'test_category') {
-	    
-	    my $key = $line->{'key'};
-	    my $value = $line->{'value'};
-	    $processes->{$sid}->{'data'}->{$cat}->{$key} = $value;
-	}
+	my $key = $line->{'key'};
+	my $value = $line->{'value'};
+	$processes->{$sid}->{'data'}->{$cat}->{$key} = $value;
+    }
+
+    elsif ($event eq 'data_json') {
+	# NEEDSWORK: Ignore due to
+	# compat/win32/trace2_win32_process_info.c, which should log a
+	# "cmd_ancestry" event instead.
+    }
+
+    else {
+	push @{$processes->{$sid}->{$event}} => $line->{value};
     }
 
     # This trace2 target does not emit 'printf' events.
diff --git a/t/t5351-unpack-large-objects.sh b/t/t5351-unpack-large-objects.sh
index 8ce8aa3b147..f785cb06173 100755
--- a/t/t5351-unpack-large-objects.sh
+++ b/t/t5351-unpack-large-objects.sh
@@ -48,13 +48,33 @@ test_expect_success 'unpack big object in stream' '
 	test_dir_is_empty dest.git/objects/pack
 '
 
+check_fsync_events () {
+	local trace="$1" &&
+	shift &&
+
+	cat >expect &&
+	sed -n \
+		-e '/^{"event":"data",.*"category":"fsync",/ {
+			s/.*"category":"fsync",//;
+			s/}$//;
+			p;
+		}' \
+		<"$trace" >actual &&
+	test_cmp expect actual
+}
+
 BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch'
 
 test_expect_success 'unpack big object in stream (core.fsyncmethod=batch)' '
 	prepare_dest 1m &&
 	GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
+	GIT_TEST_FSYNC=true \
 		git -C dest.git $BATCH_CONFIGURATION unpack-objects <pack-$PACK.pack &&
-	grep fsync/hardware-flush trace2.txt &&
+	check_fsync_events trace2.txt <<-\EOF &&
+	"key":"fsync/writeout-only","value":"6"
+	"key":"fsync/hardware-flush","value":"1"
+	EOF
+
 	test_dir_is_empty dest.git/objects/pack &&
 	git -C dest.git cat-file --batch-check="%(objectname)" <obj-list >current &&
 	cmp obj-list current
diff --git a/wrapper.c b/wrapper.c
index 1c3c970080b..cfe79bd081f 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -616,10 +616,16 @@ int git_fsync(int fd, enum fsync_action action)
 	}
 }
 
+static void log_trace_fsync_if(const char *key, intmax_t value)
+{
+	if (value)
+		trace2_data_intmax("fsync", the_repository, key, value);
+}
+
 void trace_git_fsync_stats(void)
 {
-	trace2_data_intmax("fsync", the_repository, "fsync/writeout-only", count_fsync_writeout_only);
-	trace2_data_intmax("fsync", the_repository, "fsync/hardware-flush", count_fsync_hardware_flush);
+	log_trace_fsync_if("fsync/writeout-only", count_fsync_writeout_only);
+	log_trace_fsync_if("fsync/hardware-flush", count_fsync_hardware_flush);
 }
 
 static int warn_if_unremovable(const char *op, const char *file, int rc)
-- 
2.37.1.1032.gb00b5447790


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

* Re: [PATCH v3] trace2: only include "fsync" events if we git_fsync()
  2022-07-18 10:31   ` [PATCH v3] trace2: only include "fsync" events if we git_fsync() Ævar Arnfjörð Bjarmason
@ 2022-07-18 16:50     ` Junio C Hamano
  2022-07-18 19:01       ` [EXTERNAL] " Neeraj Singh (WINDOWS-SFS)
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2022-07-18 16:50 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: git, Neeraj Singh, Han Xin

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> As we're needing to indent the trace2_data_intmax() lines let's
> introduce helper variables to ensure that our resulting lines (which
> were already too) don't exceed the recommendations of the
> CodingGuidelines. Doing that requires either wrapping them twice, or
> introducing short throwaway variable names, let's do the latter.

Or a macro that can be used like

	log_trace_fsync_nonzero(writeout_only);
	log_trace_fsync_nonzero(hardware_flush);

something along the lines of

#define log_trace_fsync_nonzero(var) \
	if (count_fsync_ #var) \
		trace2_data_intmax("fsync", the_repository, \
			"fsync/" ##var, count_fsync_ #var)

using token pasting and token stringification ;-)

The macro itself I am not serious at all.  s/_if/_nonzero/ may be
worth pondering, though.

>    We now test how many "writeout" and "flush" sync events we emit,
>    rather than the (meaningless) previous behavior (see above)>

Makes sense.

Neeraj, Ack, as the author of 9a498767 (trace2: add stats for fsync
operations, 2022-03-30)?

Thanks all.

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

* RE: [EXTERNAL] Re: [PATCH v3] trace2: only include "fsync" events if we git_fsync()
  2022-07-18 16:50     ` Junio C Hamano
@ 2022-07-18 19:01       ` Neeraj Singh (WINDOWS-SFS)
  0 siblings, 0 replies; 8+ messages in thread
From: Neeraj Singh (WINDOWS-SFS) @ 2022-07-18 19:01 UTC (permalink / raw)
  To: Junio C Hamano, Ævar Arnfjörð Bjarmason
  Cc: git@vger.kernel.org, Han Xin

Yes, ACK.  Looks fine to me.  This is still enough info to diagnose if the configuration is being parsed properly and if we're going down the right codepaths.

Thanks,
Neeraj

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

end of thread, other threads:[~2022-07-18 19:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-23 15:51 [PATCH] trace2: don't include "fsync" events in all trace2 logs Ævar Arnfjörð Bjarmason
2022-06-23 18:21 ` [EXTERNAL] " Neeraj Singh (WINDOWS-SFS)
2022-06-23 19:34 ` Junio C Hamano
2022-06-30  8:56 ` [PATCH v2] " Ævar Arnfjörð Bjarmason
2022-06-30 20:45   ` Junio C Hamano
2022-07-18 10:31   ` [PATCH v3] trace2: only include "fsync" events if we git_fsync() Ævar Arnfjörð Bjarmason
2022-07-18 16:50     ` Junio C Hamano
2022-07-18 19:01       ` [EXTERNAL] " Neeraj Singh (WINDOWS-SFS)

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).