fsmonitor: log invocation of FSMonitor hook to trace2

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>

Jeff Hostetler committed Feb 3, 2021 at 15:34 UTC 940b94f35cf1858adf23fe939bcbbe73147ca1f3
2 files changed +33 -1
fsmonitor.c
+28 -1
@@ -142,6 +142,7 @@ void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate)
142 static int query_fsmonitor(int version, const char *last_update, struct strbuf *query_result)
143 {
144 struct child_process cp = CHILD_PROCESS_INIT;
145 + int result;
146
147 if (!core_fsmonitor)
148 return -1;
@@ -152,7 +153,33 @@ static int query_fsmonitor(int version, const char *last_update, struct strbuf *
153 cp.use_shell = 1;
154 cp.dir = get_git_work_tree();
155
155 - return capture_command(&cp, query_result, 1024);
156 + trace2_region_enter("fsm_hook", "query", NULL);
157 +
158 + result = capture_command(&cp, query_result, 1024);
159 +
160 + if (result)
161 + trace2_data_intmax("fsm_hook", NULL, "query/failed", result);
162 + else {
163 + trace2_data_intmax("fsm_hook", NULL, "query/response-length",
164 + query_result->len);
165 +
166 + if (fsmonitor_is_trivial_response(query_result))
167 + trace2_data_intmax("fsm_hook", NULL,
168 + "query/trivial-response", 1);
169 + }
170 +
171 + trace2_region_leave("fsm_hook", "query", NULL);
172 +
173 + return result;
174 +}
175 +
176 +int fsmonitor_is_trivial_response(const struct strbuf *query_result)
177 +{
178 + static char trivial_response[3] = { '\0', '/', '\0' };
179 + int is_trivial = !memcmp(trivial_response,
180 + &query_result->buf[query_result->len - 3], 3);
181 +
182 + return is_trivial;
183 }
184
185 static void fsmonitor_refresh_callback(struct index_state *istate, const char *name)
fsmonitor.h
+5
@@ -44,6 +44,11 @@ void tweak_fsmonitor(struct index_state *istate);
44 */
45 void refresh_fsmonitor(struct index_state *istate);
46
47 +/*
48 + * Does the received result contain the "trivial" response?
49 + */
50 +int fsmonitor_is_trivial_response(const struct strbuf *query_result);
51 +
52 /*
53 * Set the given cache entries CE_FSMONITOR_VALID bit. This should be
54 * called any time the cache entry has been updated to reflect the