Skip to content

Commit 940b94f

Browse files
jeffhostetlergitster
authored andcommitted
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>
1 parent 15268d1 commit 940b94f

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

Diff for: fsmonitor.c

+28-1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate)
142142
static int query_fsmonitor(int version, const char *last_update, struct strbuf *query_result)
143143
{
144144
struct child_process cp = CHILD_PROCESS_INIT;
145+
int result;
145146

146147
if (!core_fsmonitor)
147148
return -1;
@@ -152,7 +153,33 @@ static int query_fsmonitor(int version, const char *last_update, struct strbuf *
152153
cp.use_shell = 1;
153154
cp.dir = get_git_work_tree();
154155

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;
156183
}
157184

158185
static void fsmonitor_refresh_callback(struct index_state *istate, const char *name)

Diff for: fsmonitor.h

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ void tweak_fsmonitor(struct index_state *istate);
4444
*/
4545
void refresh_fsmonitor(struct index_state *istate);
4646

47+
/*
48+
* Does the received result contain the "trivial" response?
49+
*/
50+
int fsmonitor_is_trivial_response(const struct strbuf *query_result);
51+
4752
/*
4853
* Set the given cache entries CE_FSMONITOR_VALID bit. This should be
4954
* called any time the cache entry has been updated to reflect the

0 commit comments

Comments
 (0)