]> git.ipfire.org Git - thirdparty/git.git/commitdiff
trace2: add stats for fsync operations
authorNeeraj Singh <neerajsi@microsoft.com>
Wed, 30 Mar 2022 05:06:40 +0000 (05:06 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 30 Mar 2022 18:15:55 +0000 (11:15 -0700)
Add some global trace2 statistics for the number of fsyncs performed
during the lifetime of a Git process.

These stats are printed as part of trace2_cmd_exit_fl, which is
presumably where we might want to print any other cross-cutting
statistics.

Signed-off-by: Neeraj Singh <neerajsi@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-compat-util.h
t/t0211/scrub_perf.perl
trace2.c
wrapper.c

index 0892e209a2fb23f797030dd04c62cd534e3d1775..4d444dca274a721e3cad8742401ec9788a8336ab 100644 (file)
@@ -1281,6 +1281,11 @@ 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
index d164b750ff702c32e449d6e844f403c657871b2d..299999f0f896e85de175819568e4ff7662a3ef03 100644 (file)
@@ -59,6 +59,10 @@ while (<>) {
            # and highly variable.  Just omit them.
            goto SKIP_LINE;
        }
+       if ($tokens[$col_category] =~ m/fsync/) {
+           # fsync events aren't interesting for the test
+           goto SKIP_LINE;
+       }
     }
 
     # t_abs and t_rel are either blank or a float.  Replace the float
index 179caa72cfee3035fee351bbebcf42097207e635..e01cf77f1a894ea1e890d5979fdf2b829f3e2066 100644 (file)
--- a/trace2.c
+++ b/trace2.c
@@ -214,6 +214,7 @@ int trace2_cmd_exit_fl(const char *file, int line, int code)
        if (!trace2_enabled)
                return code;
 
+       trace_git_fsync_stats();
        trace2_collect_process_info(TRACE2_PROCESS_INFO_EXIT);
 
        tr2main_exit_code = code;
index 354d784c034244e4868372e1cf3b5f9a91f04cac..f512994690b0292587d819c6b042c18e3b9675a4 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
@@ -4,6 +4,9 @@
 #include "cache.h"
 #include "config.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
@@ -564,6 +567,7 @@ int git_fsync(int fd, enum fsync_action action)
 {
        switch (action) {
        case FSYNC_WRITEOUT_ONLY:
+               count_fsync_writeout_only += 1;
 
 #ifdef __APPLE__
                /*
@@ -595,6 +599,8 @@ int git_fsync(int fd, enum fsync_action action)
                return -1;
 
        case FSYNC_HARDWARE_FLUSH:
+               count_fsync_hardware_flush += 1;
+
                /*
                 * On macOS, a special fcntl is required to really flush the
                 * caches within the storage controller. As of this writing,
@@ -610,6 +616,12 @@ 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);
+}
+
 static int warn_if_unremovable(const char *op, const char *file, int rc)
 {
        int err;