trace2: add stats for fsync operations
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>
Neeraj Singh committed
Mar 30, 2022 at 05:06 UTC
9a4987677d3f65e8cd93b9e77216f0f1026cd9b2
4 files changed
+22
git-compat-util.h
+5
@@ -1281,6 +1281,11 @@ enum fsync_action {
1281
*/
1282
int git_fsync(int fd, enum fsync_action action);
1283
1284
+/*
1285
+ * Writes out trace statistics for fsync using the trace2 API.
1286
+ */
1287
+void trace_git_fsync_stats(void);
1288
+
1289
/*
1290
* Preserves errno, prints a message, but gives no warning for ENOENT.
1291
* Returns 0 on success, which includes trying to unlink an object that does
t/t0211/scrub_perf.perl
+4
@@ -59,6 +59,10 @@ while (<>) {
59
# and highly variable. Just omit them.
60
goto SKIP_LINE;
61
}
62
+ if ($tokens[$col_category] =~ m/fsync/) {
63
+ # fsync events aren't interesting for the test
64
+ goto SKIP_LINE;
65
+ }
66
}
67
68
# t_abs and t_rel are either blank or a float. Replace the float
trace2.c
+1
@@ -214,6 +214,7 @@ int trace2_cmd_exit_fl(const char *file, int line, int code)
214
if (!trace2_enabled)
215
return code;
216
217
+ trace_git_fsync_stats();
218
trace2_collect_process_info(TRACE2_PROCESS_INFO_EXIT);
219
220
tr2main_exit_code = code;
wrapper.c
+12
@@ -4,6 +4,9 @@
4
#include "cache.h"
5
#include "config.h"
6
7
+static intmax_t count_fsync_writeout_only;
8
+static intmax_t count_fsync_hardware_flush;
9
+
10
#ifdef HAVE_RTLGENRANDOM
11
/* This is required to get access to RtlGenRandom. */
12
#define SystemFunction036 NTAPI SystemFunction036
@@ -564,6 +567,7 @@ int git_fsync(int fd, enum fsync_action action)
567
{
568
switch (action) {
569
case FSYNC_WRITEOUT_ONLY:
570
+ count_fsync_writeout_only += 1;
571
572
#ifdef __APPLE__
573
/*
@@ -595,6 +599,8 @@ int git_fsync(int fd, enum fsync_action action)
599
return -1;
600
601
case FSYNC_HARDWARE_FLUSH:
602
+ count_fsync_hardware_flush += 1;
603
+
604
/*
605
* On macOS, a special fcntl is required to really flush the
606
* caches within the storage controller. As of this writing,
@@ -610,6 +616,12 @@ int git_fsync(int fd, enum fsync_action action)
616
}
617
}
618
619
+void trace_git_fsync_stats(void)
620
+{
621
+ trace2_data_intmax("fsync", the_repository, "fsync/writeout-only", count_fsync_writeout_only);
622
+ trace2_data_intmax("fsync", the_repository, "fsync/hardware-flush", count_fsync_hardware_flush);
623
+}
624
+
625
static int warn_if_unremovable(const char *op, const char *file, int rc)
626
{
627
int err;