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 <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
a98e0f2d317818bfcb7f3c9cf53dfad2334e8ca7
1 file changed
+14
-3
read-cache.c
+14
-3
@@ -1364,7 +1364,8 @@ int add_index_entry(struct index_state *istate, struct cache_entry *ce, int opti
1364
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)
1367
+ int *changed_ret,
1368
+ int *t2_did_lstat)
1369
{
1370
struct stat st;
1371
struct cache_entry *updated;
@@ -1406,6 +1407,8 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
1407
return NULL;
1408
}
1409
1410
+ if (t2_did_lstat)
1411
+ *t2_did_lstat = 1;
1412
if (lstat(ce->name, &st) < 0) {
1413
if (ignore_missing && errno == ENOENT)
1414
return ce;
@@ -1519,6 +1522,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
1522
const char *added_fmt;
1523
const char *unmerged_fmt;
1524
struct progress *progress = NULL;
1525
+ int t2_sum_lstat = 0;
1526
1527
if (flags & REFRESH_PROGRESS && isatty(2))
1528
progress = start_delayed_progress(_("Refresh index"),
@@ -1536,11 +1540,13 @@ int refresh_index(struct index_state *istate, unsigned int flags,
1540
* we only have to do the special cases that are left.
1541
*/
1542
preload_index(istate, pathspec, 0);
1543
+ trace2_region_enter("index", "refresh", NULL);
1544
for (i = 0; i < istate->cache_nr; i++) {
1545
struct cache_entry *ce, *new_entry;
1546
int cache_errno = 0;
1547
int changed = 0;
1548
int filtered = 0;
1549
+ int t2_did_lstat = 0;
1550
1551
ce = istate->cache[i];
1552
if (ignore_submodules && S_ISGITLINK(ce->ce_mode))
@@ -1566,7 +1572,10 @@ int refresh_index(struct index_state *istate, unsigned int flags,
1572
if (filtered)
1573
continue;
1574
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;
1579
if (new_entry == ce)
1580
continue;
1581
if (progress)
@@ -1602,6 +1611,8 @@ int refresh_index(struct index_state *istate, unsigned int flags,
1611
1612
replace_index_entry(istate, i, new_entry);
1613
}
1614
+ trace2_data_intmax("index", NULL, "refresh/sum_lstat", t2_sum_lstat);
1615
+ trace2_region_leave("index", "refresh", NULL);
1616
if (progress) {
1617
display_progress(progress, istate->cache_nr);
1618
stop_progress(&progress);
@@ -1614,7 +1625,7 @@ struct cache_entry *refresh_cache_entry(struct index_state *istate,
1625
struct cache_entry *ce,
1626
unsigned int options)
1627
{
1617
- return refresh_cache_ent(istate, ce, options, NULL, NULL);
1628
+ return refresh_cache_ent(istate, ce, options, NULL, NULL, NULL);
1629
}
1630
1631