Skip to content

Commit a98e0f2

Browse files
jeffhostetlergitster
authored andcommitted
read-cache: log the number of lstat calls to trace2
Report the total number of calls made to lstat() inside of refresh_index(). FSMonitor improves the performance of commands like `git status` by avoiding scanning the disk for changed files. This can be seen in `refresh_index()`. Let's measure this. Signed-off-by: Jeff Hostetler <[email protected]> Reviewed-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8c4b750 commit a98e0f2

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

read-cache.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,8 @@ int add_index_entry(struct index_state *istate, struct cache_entry *ce, int opti
13641364
static struct cache_entry *refresh_cache_ent(struct index_state *istate,
13651365
struct cache_entry *ce,
13661366
unsigned int options, int *err,
1367-
int *changed_ret)
1367+
int *changed_ret,
1368+
int *t2_did_lstat)
13681369
{
13691370
struct stat st;
13701371
struct cache_entry *updated;
@@ -1406,6 +1407,8 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
14061407
return NULL;
14071408
}
14081409

1410+
if (t2_did_lstat)
1411+
*t2_did_lstat = 1;
14091412
if (lstat(ce->name, &st) < 0) {
14101413
if (ignore_missing && errno == ENOENT)
14111414
return ce;
@@ -1519,6 +1522,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
15191522
const char *added_fmt;
15201523
const char *unmerged_fmt;
15211524
struct progress *progress = NULL;
1525+
int t2_sum_lstat = 0;
15221526

15231527
if (flags & REFRESH_PROGRESS && isatty(2))
15241528
progress = start_delayed_progress(_("Refresh index"),
@@ -1536,11 +1540,13 @@ int refresh_index(struct index_state *istate, unsigned int flags,
15361540
* we only have to do the special cases that are left.
15371541
*/
15381542
preload_index(istate, pathspec, 0);
1543+
trace2_region_enter("index", "refresh", NULL);
15391544
for (i = 0; i < istate->cache_nr; i++) {
15401545
struct cache_entry *ce, *new_entry;
15411546
int cache_errno = 0;
15421547
int changed = 0;
15431548
int filtered = 0;
1549+
int t2_did_lstat = 0;
15441550

15451551
ce = istate->cache[i];
15461552
if (ignore_submodules && S_ISGITLINK(ce->ce_mode))
@@ -1566,7 +1572,10 @@ int refresh_index(struct index_state *istate, unsigned int flags,
15661572
if (filtered)
15671573
continue;
15681574

1569-
new_entry = refresh_cache_ent(istate, ce, options, &cache_errno, &changed);
1575+
new_entry = refresh_cache_ent(istate, ce, options,
1576+
&cache_errno, &changed,
1577+
&t2_did_lstat);
1578+
t2_sum_lstat += t2_did_lstat;
15701579
if (new_entry == ce)
15711580
continue;
15721581
if (progress)
@@ -1602,6 +1611,8 @@ int refresh_index(struct index_state *istate, unsigned int flags,
16021611

16031612
replace_index_entry(istate, i, new_entry);
16041613
}
1614+
trace2_data_intmax("index", NULL, "refresh/sum_lstat", t2_sum_lstat);
1615+
trace2_region_leave("index", "refresh", NULL);
16051616
if (progress) {
16061617
display_progress(progress, istate->cache_nr);
16071618
stop_progress(&progress);
@@ -1614,7 +1625,7 @@ struct cache_entry *refresh_cache_entry(struct index_state *istate,
16141625
struct cache_entry *ce,
16151626
unsigned int options)
16161627
{
1617-
return refresh_cache_ent(istate, ce, options, NULL, NULL);
1628+
return refresh_cache_ent(istate, ce, options, NULL, NULL, NULL);
16181629
}
16191630

16201631

0 commit comments

Comments
 (0)