Skip to content

Commit c4e8c42

Browse files
derrickstoleegitster
authored andcommitted
sparse-index: count lstat() calls
The clear_skip_worktree.. methods already report some statistics about how many cache entries are checked against path_found() due to having the skip-worktree bit set. However, due to path_found() performing some caching, this isn't the only information that would be helpful to report. Add a new lstat_count member to the path_found_data struct to count the number of times path_found() calls lstat(). This will be helpful to help explain performance problems in this method as well as to demonstrate future changes to the caching algorithm in a more concrete way than end-to-end timings. Signed-off-by: Derrick Stolee <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 23dd6f8 commit c4e8c42

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

sparse-index.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ void ensure_correct_sparsity(struct index_state *istate)
442442
struct path_found_data {
443443
struct strbuf dir;
444444
int dir_found;
445+
size_t lstat_count;
445446
};
446447

447448
#define PATH_FOUND_DATA_INIT { \
@@ -469,6 +470,7 @@ static int path_found(const char *path, struct path_found_data *data)
469470
/*
470471
* If path itself exists, return 1.
471472
*/
473+
data->lstat_count++;
472474
if (!lstat(path, &st))
473475
return 1;
474476

@@ -493,6 +495,7 @@ static int path_found(const char *path, struct path_found_data *data)
493495
strbuf_reset(&data->dir);
494496
strbuf_add(&data->dir, path, newdir - path + 1);
495497

498+
data->lstat_count++;
496499
data->dir_found = !lstat(data->dir.buf, &st);
497500

498501
return 0;
@@ -524,6 +527,8 @@ static int clear_skip_worktree_from_present_files_sparse(struct index_state *ist
524527

525528
trace2_data_intmax("index", istate->repo,
526529
"sparse_path_count", path_count);
530+
trace2_data_intmax("index", istate->repo,
531+
"sparse_lstat_count", data.lstat_count);
527532
trace2_region_leave("index", "clear_skip_worktree_from_present_files_sparse",
528533
istate->repo);
529534
clear_path_found_data(&data);
@@ -553,6 +558,8 @@ static void clear_skip_worktree_from_present_files_full(struct index_state *ista
553558

554559
trace2_data_intmax("index", istate->repo,
555560
"full_path_count", path_count);
561+
trace2_data_intmax("index", istate->repo,
562+
"full_lstat_count", data.lstat_count);
556563
trace2_region_leave("index", "clear_skip_worktree_from_present_files_full",
557564
istate->repo);
558565
clear_path_found_data(&data);

0 commit comments

Comments
 (0)