Skip to content

Commit

Permalink
dir: report number of visited directories and paths with trace2
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
newren authored and gitster committed May 12, 2021
1 parent 7f9dd87 commit 7fe1ffd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions dir.c
Expand Up @@ -2431,6 +2431,7 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,

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

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

if (state > dir_state)
dir_state = state;
Expand Down Expand Up @@ -2768,6 +2770,11 @@ static void emit_traversal_statistics(struct dir_struct *dir,
strbuf_release(&tmp);
}

trace2_data_intmax("read_directory", repo,
"directories-visited", dir->visited_directories);
trace2_data_intmax("read_directory", repo,
"paths-visited", dir->visited_paths);

if (!dir->untracked)
return;
trace2_data_intmax("read_directory", repo,
Expand All @@ -2788,6 +2795,8 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
struct untracked_cache_dir *untracked;

trace2_region_enter("dir", "read_directory", istate->repo);
dir->visited_paths = 0;
dir->visited_directories = 0;

if (has_symlink_leading_path(path, len)) {
trace2_region_leave("dir", "read_directory", istate->repo);
Expand Down
4 changes: 4 additions & 0 deletions dir.h
Expand Up @@ -336,6 +336,10 @@ struct dir_struct {
struct oid_stat ss_info_exclude;
struct oid_stat ss_excludes_file;
unsigned unmanaged_exclude_files;

/* Stats about the traversal */
unsigned visited_paths;
unsigned visited_directories;
};

/*Count the number of slashes for string s*/
Expand Down
3 changes: 2 additions & 1 deletion t/t7063-status-untracked-cache.sh
Expand Up @@ -65,7 +65,8 @@ get_relevant_traces () {
INPUT_FILE=$1
OUTPUT_FILE=$2
grep data.*read_directo $INPUT_FILE |
cut -d "|" -f 9 \
cut -d "|" -f 9 |
grep -v visited \
>"$OUTPUT_FILE"
}

Expand Down

0 comments on commit 7fe1ffd

Please sign in to comment.