preload-index: log the number of lstat calls to trace2

Report the total number of calls made to lstat() inside preload_index(). FSMonitor improves the performance of commands like `git status` by avoiding scanning the disk for changed files. This can be seen in `preload_index()`. Let's measure this. 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 8c4b7503d033d8ba20771a1af8e077a79a18ce49
1 file changed +10
preload-index.c
+10
@@ -31,6 +31,7 @@ struct thread_data {
31 struct pathspec pathspec;
32 struct progress_data *progress;
33 int offset, nr;
34 + int t2_nr_lstat;
35 };
36
37 static void *preload_thread(void *_data)
@@ -73,6 +74,7 @@ static void *preload_thread(void *_data)
74 continue;
75 if (threaded_has_symlink_leading_path(&cache, ce->name, ce_namelen(ce)))
76 continue;
77 + p->t2_nr_lstat++;
78 if (lstat(ce->name, &st))
79 continue;
80 if (ie_match_stat(index, ce, &st, CE_MATCH_RACY_IS_DIRTY|CE_MATCH_IGNORE_FSMONITOR))
@@ -98,6 +100,7 @@ void preload_index(struct index_state *index,
100 int threads, i, work, offset;
101 struct thread_data data[MAX_PARALLEL];
102 struct progress_data pd;
103 + int t2_sum_lstat = 0;
104
105 if (!HAVE_THREADS || !core_preload_index)
106 return;
@@ -107,6 +110,9 @@ void preload_index(struct index_state *index,
110 threads = 2;
111 if (threads < 2)
112 return;
113 +
114 + trace2_region_enter("index", "preload", NULL);
115 +
116 trace_performance_enter();
117 if (threads > MAX_PARALLEL)
118 threads = MAX_PARALLEL;
@@ -141,10 +147,14 @@ void preload_index(struct index_state *index,
147 struct thread_data *p = data+i;
148 if (pthread_join(p->pthread, NULL))
149 die("unable to join threaded lstat");
150 + t2_sum_lstat += p->t2_nr_lstat;
151 }
152 stop_progress(&pd.progress);
153
154 trace_performance_leave("preload index");
155 +
156 + trace2_data_intmax("index", NULL, "preload/sum_lstat", t2_sum_lstat);
157 + trace2_region_leave("index", "preload", NULL);
158 }
159
160 int repo_read_index_preload(struct repository *repo,