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 <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
May 12, 2021 at 17:28 UTC
7fe1ffdafa56b8453a47a40b866d029f24a56d76
3 files changed
+15
-1
dir.c
+9
@@ -2431,6 +2431,7 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
2431
2432
if (open_cached_dir(&cdir, dir, untracked, istate, &path, check_only))
2433
goto out;
2434
+ dir->visited_directories++;
2435
2436
if (untracked)
2437
untracked->check_only = !!check_only;
@@ -2439,6 +2440,7 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
2440
/* check how the file or directory should be treated */
2441
state = treat_path(dir, untracked, &cdir, istate, &path,
2442
baselen, pathspec);
2443
+ dir->visited_paths++;
2444
2445
if (state > dir_state)
2446
dir_state = state;
@@ -2768,6 +2770,11 @@ static void emit_traversal_statistics(struct dir_struct *dir,
2770
strbuf_release(&tmp);
2771
}
2772
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
+
2778
if (!dir->untracked)
2779
return;
2780
trace2_data_intmax("read_directory", repo,
@@ -2788,6 +2795,8 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
2795
struct untracked_cache_dir *untracked;
2796
2797
trace2_region_enter("dir", "read_directory", istate->repo);
2798
+ dir->visited_paths = 0;
2799
+ dir->visited_directories = 0;
2800
2801
if (has_symlink_leading_path(path, len)) {
2802
trace2_region_leave("dir", "read_directory", istate->repo);
dir.h
+4
@@ -336,6 +336,10 @@ struct dir_struct {
336
struct oid_stat ss_info_exclude;
337
struct oid_stat ss_excludes_file;
338
unsigned unmanaged_exclude_files;
339
+
340
+ /* Stats about the traversal */
341
+ unsigned visited_paths;
342
+ unsigned visited_directories;
343
};
344
345
/*Count the number of slashes for string s*/
t/t7063-status-untracked-cache.sh
+2
-1
@@ -65,7 +65,8 @@ get_relevant_traces () {
65
INPUT_FILE=$1
66
OUTPUT_FILE=$2
67
grep data.*read_directo $INPUT_FILE |
68
- cut -d "|" -f 9 \
68
+ cut -d "|" -f 9 |
69
+ grep -v visited \
70
>"$OUTPUT_FILE"
71
}
72