]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fsmonitor: log invocation of FSMonitor hook to trace2
authorJeff Hostetler <jeffhost@microsoft.com>
Wed, 3 Feb 2021 15:34:47 +0000 (15:34 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 17 Feb 2021 01:14:34 +0000 (17:14 -0800)
Let's measure the time taken to request and receive FSMonitor data
via the hook API and the size of the response.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Reviewed-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
fsmonitor.c
fsmonitor.h

index ca031c3abb8bf5a4c392039615c7ed88a991aa5e..7a2be24cd433130408f9e5d9acdf5aacc920d2f6 100644 (file)
@@ -142,6 +142,7 @@ void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate)
 static int query_fsmonitor(int version, const char *last_update, struct strbuf *query_result)
 {
        struct child_process cp = CHILD_PROCESS_INIT;
+       int result;
 
        if (!core_fsmonitor)
                return -1;
@@ -152,7 +153,33 @@ static int query_fsmonitor(int version, const char *last_update, struct strbuf *
        cp.use_shell = 1;
        cp.dir = get_git_work_tree();
 
-       return capture_command(&cp, query_result, 1024);
+       trace2_region_enter("fsm_hook", "query", NULL);
+
+       result = capture_command(&cp, query_result, 1024);
+
+       if (result)
+               trace2_data_intmax("fsm_hook", NULL, "query/failed", result);
+       else {
+               trace2_data_intmax("fsm_hook", NULL, "query/response-length",
+                                  query_result->len);
+
+               if (fsmonitor_is_trivial_response(query_result))
+                       trace2_data_intmax("fsm_hook", NULL,
+                                          "query/trivial-response", 1);
+       }
+
+       trace2_region_leave("fsm_hook", "query", NULL);
+
+       return result;
+}
+
+int fsmonitor_is_trivial_response(const struct strbuf *query_result)
+{
+       static char trivial_response[3] = { '\0', '/', '\0' };
+       int is_trivial = !memcmp(trivial_response,
+                                &query_result->buf[query_result->len - 3], 3);
+
+       return is_trivial;
 }
 
 static void fsmonitor_refresh_callback(struct index_state *istate, const char *name)
index 739318ab6d1060e3f5ef9eba0ab93aa560c1d246..7f1794b90b001cbc07991fd12e8cd7aaebe6cdfd 100644 (file)
@@ -44,6 +44,11 @@ void tweak_fsmonitor(struct index_state *istate);
  */
 void refresh_fsmonitor(struct index_state *istate);
 
+/*
+ * Does the received result contain the "trivial" response?
+ */
+int fsmonitor_is_trivial_response(const struct strbuf *query_result);
+
 /*
  * Set the given cache entries CE_FSMONITOR_VALID bit. This should be
  * called any time the cache entry has been updated to reflect the