Skip to content

Commit 7fe1ffd

Browse files
newrengitster
authored andcommitted
dir: report number of visited directories and paths with trace2
Provide more statistics in trace2 output that include the number of directories and total paths visited by the directory traversal logic. Subsequent patches will take advantage of this to ensure we do not unnecessarily traverse into ignored directories. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7f9dd87 commit 7fe1ffd

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

dir.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,6 +2431,7 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
24312431

24322432
if (open_cached_dir(&cdir, dir, untracked, istate, &path, check_only))
24332433
goto out;
2434+
dir->visited_directories++;
24342435

24352436
if (untracked)
24362437
untracked->check_only = !!check_only;
@@ -2439,6 +2440,7 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
24392440
/* check how the file or directory should be treated */
24402441
state = treat_path(dir, untracked, &cdir, istate, &path,
24412442
baselen, pathspec);
2443+
dir->visited_paths++;
24422444

24432445
if (state > dir_state)
24442446
dir_state = state;
@@ -2768,6 +2770,11 @@ static void emit_traversal_statistics(struct dir_struct *dir,
27682770
strbuf_release(&tmp);
27692771
}
27702772

2773+
trace2_data_intmax("read_directory", repo,
2774+
"directories-visited", dir->visited_directories);
2775+
trace2_data_intmax("read_directory", repo,
2776+
"paths-visited", dir->visited_paths);
2777+
27712778
if (!dir->untracked)
27722779
return;
27732780
trace2_data_intmax("read_directory", repo,
@@ -2788,6 +2795,8 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
27882795
struct untracked_cache_dir *untracked;
27892796

27902797
trace2_region_enter("dir", "read_directory", istate->repo);
2798+
dir->visited_paths = 0;
2799+
dir->visited_directories = 0;
27912800

27922801
if (has_symlink_leading_path(path, len)) {
27932802
trace2_region_leave("dir", "read_directory", istate->repo);

dir.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ struct dir_struct {
336336
struct oid_stat ss_info_exclude;
337337
struct oid_stat ss_excludes_file;
338338
unsigned unmanaged_exclude_files;
339+
340+
/* Stats about the traversal */
341+
unsigned visited_paths;
342+
unsigned visited_directories;
339343
};
340344

341345
/*Count the number of slashes for string s*/

t/t7063-status-untracked-cache.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ get_relevant_traces () {
6565
INPUT_FILE=$1
6666
OUTPUT_FILE=$2
6767
grep data.*read_directo $INPUT_FILE |
68-
cut -d "|" -f 9 \
68+
cut -d "|" -f 9 |
69+
grep -v visited \
6970
>"$OUTPUT_FILE"
7071
}
7172

0 commit comments

Comments
 (0)