As a library boundary, wrapper.c should not directly log trace2 statistics, but instead provide those statistics upon request. Therefore, move the trace2 logging code to trace2.[ch.]. This also allows wrapper.c to not be dependent on trace2.h and repository.h. Signed-off-by: Calvin Wan <calvinwan@xxxxxxxxxx> --- trace2.c | 13 +++++++++++++ trace2.h | 5 +++++ wrapper.c | 17 ++++++----------- wrapper.h | 4 ++-- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/trace2.c b/trace2.c index 0efc4e7b95..f367a1ce31 100644 --- a/trace2.c +++ b/trace2.c @@ -915,3 +915,16 @@ const char *trace2_session_id(void) { return tr2_sid_get(); } + +static void log_trace_fsync_if(const char *key) +{ + intmax_t value = get_trace_git_fsync_stats(key); + if (value) + trace2_data_intmax("fsync", the_repository, key, value); +} + +void trace_git_fsync_stats(void) +{ + log_trace_fsync_if("fsync/writeout-only"); + log_trace_fsync_if("fsync/hardware-flush"); +} diff --git a/trace2.h b/trace2.h index 4ced30c0db..689e9a4027 100644 --- a/trace2.h +++ b/trace2.h @@ -581,4 +581,9 @@ void trace2_collect_process_info(enum trace2_process_info_reason reason); const char *trace2_session_id(void); +/* + * Writes out trace statistics for fsync + */ +void trace_git_fsync_stats(void); + #endif /* TRACE2_H */ diff --git a/wrapper.c b/wrapper.c index 22be9812a7..bd7f0a9752 100644 --- a/wrapper.c +++ b/wrapper.c @@ -6,9 +6,7 @@ #include "config.h" #include "gettext.h" #include "object.h" -#include "repository.h" #include "strbuf.h" -#include "trace2.h" static intmax_t count_fsync_writeout_only; static intmax_t count_fsync_hardware_flush; @@ -600,16 +598,13 @@ int git_fsync(int fd, enum fsync_action action) } } -static void log_trace_fsync_if(const char *key, intmax_t value) +intmax_t get_trace_git_fsync_stats(const char *key) { - 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); + if (!strcmp(key, "fsync/writeout-only")) + return count_fsync_writeout_only; + if (!strcmp(key, "fsync/hardware-flush")) + return count_fsync_hardware_flush; + return 0; } static int warn_if_unremovable(const char *op, const char *file, int rc) diff --git a/wrapper.h b/wrapper.h index c85b1328d1..db1bc109ed 100644 --- a/wrapper.h +++ b/wrapper.h @@ -88,9 +88,9 @@ enum fsync_action { int git_fsync(int fd, enum fsync_action action); /* - * Writes out trace statistics for fsync using the trace2 API. + * Returns trace statistics for fsync using the trace2 API. */ -void trace_git_fsync_stats(void); +intmax_t get_trace_git_fsync_stats(const char *key); /* * Preserves errno, prints a message, but gives no warning for ENOENT. -- 2.41.0.162.gfafddb0af9-goog