aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-08-02 09:37:23 -0700
committerJunio C Hamano <gitster@pobox.com>2023-08-02 09:37:23 -0700
commit52d9dc20e1ddd5ac6b9e9113983b2f8d6977e6b0 (patch)
treee40cb3ecdc5a5620619c411e9b013718b9a300f4
parent99acb0fa54775a383cab70a6e662e45180dee3f0 (diff)
parenta27eecea75b3858b4052b191143f144a7e966869 (diff)
downloadgit-52d9dc20e1ddd5ac6b9e9113983b2f8d6977e6b0.tar.xz
Merge branch 'bb/use-trace2-counters-for-fsync-stats'
Instead of inventing a custom counter variables for debugging, use existing trace2 facility in the fsync customization codepath. * bb/use-trace2-counters-for-fsync-stats: wrapper: use trace2 counters to collect fsync stats
-rwxr-xr-xt/t5351-unpack-large-objects.sh6
-rw-r--r--trace2.c1
-rw-r--r--trace2.h4
-rw-r--r--trace2/tr2_ctr.c10
-rw-r--r--wrapper.c19
-rw-r--r--wrapper.h5
6 files changed, 19 insertions, 26 deletions
diff --git a/t/t5351-unpack-large-objects.sh b/t/t5351-unpack-large-objects.sh
index 8c8af99b84..43cbcd5d49 100755
--- a/t/t5351-unpack-large-objects.sh
+++ b/t/t5351-unpack-large-objects.sh
@@ -55,7 +55,7 @@ check_fsync_events () {
cat >expect &&
sed -n \
- -e '/^{"event":"data",.*"category":"fsync",/ {
+ -e '/^{"event":"counter",.*"category":"fsync",/ {
s/.*"category":"fsync",//;
s/}$//;
p;
@@ -78,8 +78,8 @@ test_expect_success 'unpack big object in stream (core.fsyncmethod=batch)' '
flush_count=1
fi &&
check_fsync_events trace2.txt <<-EOF &&
- "key":"fsync/writeout-only","value":"6"
- "key":"fsync/hardware-flush","value":"$flush_count"
+ "name":"writeout-only","count":6
+ "name":"hardware-flush","count":$flush_count
EOF
test_dir_is_empty dest.git/objects/pack &&
diff --git a/trace2.c b/trace2.c
index 49c23bfd05..6dc74dff4c 100644
--- a/trace2.c
+++ b/trace2.c
@@ -276,7 +276,6 @@ void trace2_cmd_exit_fl(const char *file, int line, int code)
if (!trace2_enabled)
return;
- trace_git_fsync_stats();
trace2_collect_process_info(TRACE2_PROCESS_INFO_EXIT);
tr2main_exit_code = code;
diff --git a/trace2.h b/trace2.h
index d7c3b30538..40d8c2e02a 100644
--- a/trace2.h
+++ b/trace2.h
@@ -554,6 +554,10 @@ enum trace2_counter_id {
TRACE2_COUNTER_ID_PACKED_REFS_JUMPS, /* counts number of jumps */
+ /* counts number of fsyncs */
+ TRACE2_COUNTER_ID_FSYNC_WRITEOUT_ONLY,
+ TRACE2_COUNTER_ID_FSYNC_HARDWARE_FLUSH,
+
/* Add additional counter definitions before here. */
TRACE2_NUMBER_OF_COUNTERS
};
diff --git a/trace2/tr2_ctr.c b/trace2/tr2_ctr.c
index 50570d0165..87cf9034fb 100644
--- a/trace2/tr2_ctr.c
+++ b/trace2/tr2_ctr.c
@@ -32,6 +32,16 @@ static struct tr2_counter_metadata tr2_counter_metadata[TRACE2_NUMBER_OF_COUNTER
.name = "jumps_made",
.want_per_thread_events = 0,
},
+ [TRACE2_COUNTER_ID_FSYNC_WRITEOUT_ONLY] = {
+ .category = "fsync",
+ .name = "writeout-only",
+ .want_per_thread_events = 0,
+ },
+ [TRACE2_COUNTER_ID_FSYNC_HARDWARE_FLUSH] = {
+ .category = "fsync",
+ .name = "hardware-flush",
+ .want_per_thread_events = 0,
+ },
/* Add additional metadata before here. */
};
diff --git a/wrapper.c b/wrapper.c
index fb996f631a..5160c9e28d 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -10,9 +10,6 @@
#include "strbuf.h"
#include "trace2.h"
-static intmax_t count_fsync_writeout_only;
-static intmax_t count_fsync_hardware_flush;
-
#ifdef HAVE_RTLGENRANDOM
/* This is required to get access to RtlGenRandom. */
#define SystemFunction036 NTAPI SystemFunction036
@@ -551,7 +548,7 @@ int git_fsync(int fd, enum fsync_action action)
{
switch (action) {
case FSYNC_WRITEOUT_ONLY:
- count_fsync_writeout_only += 1;
+ trace2_counter_add(TRACE2_COUNTER_ID_FSYNC_WRITEOUT_ONLY, 1);
#ifdef __APPLE__
/*
@@ -583,7 +580,7 @@ int git_fsync(int fd, enum fsync_action action)
return -1;
case FSYNC_HARDWARE_FLUSH:
- count_fsync_hardware_flush += 1;
+ trace2_counter_add(TRACE2_COUNTER_ID_FSYNC_HARDWARE_FLUSH, 1);
/*
* On macOS, a special fcntl is required to really flush the
@@ -600,18 +597,6 @@ 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)
-{
- 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)
{
int err;
diff --git a/wrapper.h b/wrapper.h
index c85b1328d1..79a9c1b507 100644
--- a/wrapper.h
+++ b/wrapper.h
@@ -88,11 +88,6 @@ enum fsync_action {
int git_fsync(int fd, enum fsync_action action);
/*
- * Writes out trace statistics for fsync using the trace2 API.
- */
-void trace_git_fsync_stats(void);
-
-/*
* Preserves errno, prints a message, but gives no warning for ENOENT.
* Returns 0 on success, which includes trying to unlink an object that does
* not exist.