read-cache: log the number of scanned files to trace2

Report the number of files in the working directory that were read and their hashes verified in `refresh_index()`. FSMonitor improves the performance of commands like `git status` by avoiding scanning the disk for changed files. 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 15268d12bef12a40753767882088f4fcfefb3b2b
1 file changed +10 -3
read-cache.c
+10 -3
@@ -1365,7 +1365,8 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
1365 struct cache_entry *ce,
1366 unsigned int options, int *err,
1367 int *changed_ret,
1368 - int *t2_did_lstat)
1368 + int *t2_did_lstat,
1369 + int *t2_did_scan)
1370 {
1371 struct stat st;
1372 struct cache_entry *updated;
@@ -1445,6 +1446,8 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
1446 }
1447 }
1448
1449 + if (t2_did_scan)
1450 + *t2_did_scan = 1;
1451 if (ie_modified(istate, ce, &st, options)) {
1452 if (err)
1453 *err = EINVAL;
@@ -1523,6 +1526,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
1526 const char *unmerged_fmt;
1527 struct progress *progress = NULL;
1528 int t2_sum_lstat = 0;
1529 + int t2_sum_scan = 0;
1530
1531 if (flags & REFRESH_PROGRESS && isatty(2))
1532 progress = start_delayed_progress(_("Refresh index"),
@@ -1547,6 +1551,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
1551 int changed = 0;
1552 int filtered = 0;
1553 int t2_did_lstat = 0;
1554 + int t2_did_scan = 0;
1555
1556 ce = istate->cache[i];
1557 if (ignore_submodules && S_ISGITLINK(ce->ce_mode))
@@ -1574,8 +1579,9 @@ int refresh_index(struct index_state *istate, unsigned int flags,
1579
1580 new_entry = refresh_cache_ent(istate, ce, options,
1581 &cache_errno, &changed,
1577 - &t2_did_lstat);
1582 + &t2_did_lstat, &t2_did_scan);
1583 t2_sum_lstat += t2_did_lstat;
1584 + t2_sum_scan += t2_did_scan;
1585 if (new_entry == ce)
1586 continue;
1587 if (progress)
@@ -1612,6 +1618,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
1618 replace_index_entry(istate, i, new_entry);
1619 }
1620 trace2_data_intmax("index", NULL, "refresh/sum_lstat", t2_sum_lstat);
1621 + trace2_data_intmax("index", NULL, "refresh/sum_scan", t2_sum_scan);
1622 trace2_region_leave("index", "refresh", NULL);
1623 if (progress) {
1624 display_progress(progress, istate->cache_nr);
@@ -1625,7 +1632,7 @@ struct cache_entry *refresh_cache_entry(struct index_state *istate,
1632 struct cache_entry *ce,
1633 unsigned int options)
1634 {
1628 - return refresh_cache_ent(istate, ce, options, NULL, NULL, NULL);
1635 + return refresh_cache_ent(istate, ce, options, NULL, NULL, NULL, NULL);
1636 }
1637
1638