git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 1/8] [RFC] dir: convert trace calls to trace2 equivalents

From
Elijah Newren <newren@gmail.com>
Date
May 11, 2021, 17:29 UTC
Message-ID
<CABPp-BEa0hgrTXWAA0hVAZ3uRhsfLY=jEe17+2X5pQpRKiejMg@mail.gmail.com>
In-Reply-To
<96679919-f6ea-adcc-b8fc-9eaa0134c876@jeffhostetler.com>
On Tue, May 11, 2021 at 9:17 AM Jeff Hostetler <git@jeffhostetler.com> wrote:
Show 29 quoted lines
>
> On 5/8/21 3:58 PM, Elijah Newren via GitGitGadget wrote:
> > From: Elijah Newren <newren@gmail.com>
> >
> > Signed-off-by: Elijah Newren <newren@gmail.com>
> > ---
> >   dir.c                             |  34 ++++--
> >   t/t7063-status-untracked-cache.sh | 193 +++++++++++++++++-------------
> >   t/t7519-status-fsmonitor.sh       |   8 +-
> >   3 files changed, 135 insertions(+), 100 deletions(-)
> >
> > diff --git a/dir.c b/dir.c
> > index 3474e67e8f3c..9f7c8debeab3 100644
> > --- a/dir.c
> > +++ b/dir.c
> > @@ -2760,12 +2760,29 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
> >       return root;
> >   }
> >
> > +static void trace2_read_directory_statistics(struct dir_struct *dir,
> > +                                          struct repository *repo)
> > +{
> > +     if (!dir->untracked)
> > +             return;
>
> Is there value to also printing the path?
> The existing `trace_performance_leave()` calls were, but
> I'm familiar enough with this code to say if the output
> wasn't always something like ".".

The path will most likely just be "" (i.e. the empty string) for the toplevel directory, but not always so it may be useful to print it. I'll add it.

Show 30 quoted lines
> > +     trace2_data_intmax("read_directory", repo,
> > +                        "node-creation", dir->untracked->dir_created);
> > +     trace2_data_intmax("read_directory", repo,
> > +                        "gitignore-invalidation",
> > +                        dir->untracked->gitignore_invalidated);
> > +     trace2_data_intmax("read_directory", repo,
> > +                        "directory-invalidation",
> > +                        dir->untracked->dir_invalidated);
> > +     trace2_data_intmax("read_directory", repo,
> > +                        "opendir", dir->untracked->dir_opened);
> > +}
> > +
>
> The existing code was quite tangled and I think this helps
> make things more clear.
>
>
> >   int read_directory(struct dir_struct *dir, struct index_state *istate,
> >                  const char *path, int len, const struct pathspec *pathspec)
> >   {
> >       struct untracked_cache_dir *untracked;
> >
> > -     trace_performance_enter();
> > +     trace2_region_enter("dir", "read_directory", istate->repo);
> >
> >       if (has_symlink_leading_path(path, len)) {
> >               trace_performance_leave("read directory %.*s", len, path);
>
> This `trace_performance_leave()` inside the `if` needs to be
> converted too.
Ooh, good catch.  Will fix.
Show 13 quoted lines
> > @@ -2784,23 +2801,13 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
> >       QSORT(dir->entries, dir->nr, cmp_dir_entry);
> >       QSORT(dir->ignored, dir->ignored_nr, cmp_dir_entry);
> >
> > -     trace_performance_leave("read directory %.*s", len, path);
> > +     trace2_region_leave("dir", "read_directory", istate->repo);
>
> Can we put the call to `trace2_read_directory_statistics()` before
> the above `trace2_region_leave()` call?   Then those stats will
> appear indented between the begin- and end-region events in the output.
>
> That way, the following `if (dir-untracked) {...}` is only
> concerned with the untracked cache and/or freeing that data.
Makes sense, I'll move it.
Show 30 quoted lines
> >       if (dir->untracked) {
> >               static int force_untracked_cache = -1;
> > -             static struct trace_key trace_untracked_stats = TRACE_KEY_INIT(UNTRACKED_STATS);
> >
> >               if (force_untracked_cache < 0)
> >                       force_untracked_cache =
> >                               git_env_bool("GIT_FORCE_UNTRACKED_CACHE", 0);
> > -             trace_printf_key(&trace_untracked_stats,
> > -                              "node creation: %u\n"
> > -                              "gitignore invalidation: %u\n"
> > -                              "directory invalidation: %u\n"
> > -                              "opendir: %u\n",
> > -                              dir->untracked->dir_created,
> > -                              dir->untracked->gitignore_invalidated,
> > -                              dir->untracked->dir_invalidated,
> > -                              dir->untracked->dir_opened);
> >               if (force_untracked_cache &&
> >                       dir->untracked == istate->untracked &&
> >                   (dir->untracked->dir_opened ||
> > @@ -2811,6 +2818,9 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
> >                       FREE_AND_NULL(dir->untracked);
> >               }
> >       }
> > +
> > +     if (trace2_is_enabled())
> > +             trace2_read_directory_statistics(dir, istate->repo);
>
> Also, I think it'd be ok to move the `trace2_is_enabled()` call
> inside the function.  Since we're also testing `!dir->untracked`
> inside the function.

Actually, I can't do that. The path passed to this function is not going to always be (and will often not be) NUL-terminated, but trace2_data_string() expects a NUL-terminated string. So, I'm going to make a temporary strbuf and copy the path into it, but of course I only want to spend time doing that if trace2_is_enabled().

Show 6 quoted lines
> The more that I look at the before and after versions, the
> more I think the `trace2_read_directory_statistics()` call
> should be up before the `trace2_region_leave()`.  Here at the
> bottom of the function, we may have already freed `dir->untracked`.
> I'm not familiar enough with this code to know if that is a
> good or bad thing.

Yeah, the statistics really need to be moved earlier, both for the nesting reasons you point out and because otherwise the statistics won't print whenever dir->untracked != istate->untracked. I'll move them.

Previous: Jeff HostetlerNext: Elijah Newren via GitGitGadget
Message 40 of 90 in “Directory traversal fixes”
  1. 0/5 Directory traversal fixesElijah Newren via GitGitGadget, May 7, 2021
  2. 1/5 t7300: add testcase showing unnecessary traversal into ignored directoryElijah Newren via GitGitGadget, May 7, 2021
  3. Eric SunshineMay 7, 2021
  4. Elijah NewrenMay 7, 2021
  5. Eric SunshineMay 7, 2021
  6. Elijah NewrenMay 7, 2021
  7. Eric SunshineMay 7, 2021
  8. Jeff KingMay 7, 2021
  9. Eric SunshineMay 7, 2021
  10. Elijah NewrenMay 8, 2021
  11. Eric SunshineMay 8, 2021
  12. Elijah NewrenMay 8, 2021
  13. Philip OakleyMay 8, 2021
  14. Elijah NewrenMay 8, 2021
  15. 2/5 t3001, t7300: add testcase showcasing missed directory traversalElijah Newren via GitGitGadget, May 7, 2021
  16. 3/5 dir: avoid unnecessary traversal into ignored directoryElijah Newren via GitGitGadget, May 7, 2021
  17. 4/5 dir: traverse into untracked directories if they may have ignored subfilesElijah Newren via GitGitGadget, May 7, 2021
  18. 5/5 [RFC] ls-files: error out on -i unless -o or -c are specifiedElijah Newren via GitGitGadget, May 7, 2021
  19. 6/5 dir: update stale description of treat_directory()Derrick Stolee, May 7, 2021
  20. Elijah NewrenMay 7, 2021
  21. Derrick StoleeMay 7, 2021
  22. 0/8 Directory traversal fixesElijah Newren via GitGitGadget, May 8, 2021
  23. 1/8 t7300: add testcase showing unnecessary traversal into ignored directoryElijah Newren via GitGitGadget, May 8, 2021
  24. Junio C HamanoMay 8, 2021
  25. Elijah NewrenMay 8, 2021
  26. Junio C HamanoMay 8, 2021
  27. Elijah NewrenMay 8, 2021
  28. 3/8 dir: avoid unnecessary traversal into ignored directoryElijah Newren via GitGitGadget, May 8, 2021
  29. 2/8 t3001, t7300: add testcase showcasing missed directory traversalElijah Newren via GitGitGadget, May 8, 2021
  30. 4/8 dir: traverse into untracked directories if they may have ignored subfilesElijah Newren via GitGitGadget, May 8, 2021
  31. 5/8 [RFC] ls-files: error out on -i unless -o or -c are specifiedElijah Newren via GitGitGadget, May 8, 2021
  32. 6/8 dir: update stale description of treat_directory()Derrick Stolee via GitGitGadget, May 8, 2021
  33. 7/8 [RFC] dir: convert trace calls to trace2 equivalentsElijah Newren via GitGitGadget, May 8, 2021
  34. 8/8 [RFC] dir: reported number of visited directories and paths with trace2Elijah Newren via GitGitGadget, May 8, 2021
  35. 0/8 Directory traversal fixesElijah Newren via GitGitGadget, May 8, 2021
  36. 1/8 [RFC] dir: convert trace calls to trace2 equivalentsElijah Newren via GitGitGadget, May 8, 2021
  37. Junio C HamanoMay 10, 2021
  38. Elijah NewrenMay 11, 2021
  39. Jeff HostetlerMay 11, 2021
  40. Elijah NewrenMay 11, 2021
  41. 2/8 [RFC] dir: report number of visited directories and paths with trace2Elijah Newren via GitGitGadget, May 8, 2021
  42. Junio C HamanoMay 10, 2021
  43. 3/8 [RFC] ls-files: error out on -i unless -o or -c are specifiedElijah Newren via GitGitGadget, May 8, 2021
  44. Junio C HamanoMay 10, 2021
  45. Elijah NewrenMay 11, 2021
  46. Junio C HamanoMay 11, 2021
  47. 4/8 t7300: add testcase showing unnecessary traversal into ignored directoryElijah Newren via GitGitGadget, May 8, 2021
  48. Junio C HamanoMay 10, 2021
  49. Elijah NewrenMay 11, 2021
  50. Junio C HamanoMay 11, 2021
  51. Elijah NewrenMay 12, 2021
  52. Junio C HamanoMay 12, 2021
  53. 5/8 t3001, t7300: add testcase showcasing missed directory traversalElijah Newren via GitGitGadget, May 8, 2021
  54. 6/8 dir: avoid unnecessary traversal into ignored directoryElijah Newren via GitGitGadget, May 8, 2021
  55. Junio C HamanoMay 10, 2021
  56. Elijah NewrenMay 11, 2021
  57. 7/8 dir: traverse into untracked directories if they may have ignored subfilesElijah Newren via GitGitGadget, May 8, 2021
  58. 8/8 dir: update stale description of treat_directory()Derrick Stolee via GitGitGadget, May 8, 2021
  59. 0/8 Directory traversal fixesElijah Newren via GitGitGadget, May 11, 2021
  60. 1/8 dir: convert trace calls to trace2 equivalentsElijah Newren via GitGitGadget, May 11, 2021
  61. Jeff HostetlerMay 11, 2021
  62. Elijah NewrenMay 11, 2021
  63. Jeff HostetlerMay 11, 2021
  64. Elijah NewrenMay 12, 2021
  65. Jeff HostetlerMay 12, 2021
  66. Elijah NewrenMay 12, 2021
  67. 3/8 ls-files: error out on -i unless -o or -c are specifiedElijah Newren via GitGitGadget, May 11, 2021
  68. 2/8 dir: report number of visited directories and paths with trace2Elijah Newren via GitGitGadget, May 11, 2021
  69. 4/8 t7300: add testcase showing unnecessary traversal into ignored directoryElijah Newren via GitGitGadget, May 11, 2021
  70. 5/8 t3001, t7300: add testcase showcasing missed directory traversalElijah Newren via GitGitGadget, May 11, 2021
  71. 7/8 dir: traverse into untracked directories if they may have ignored subfilesElijah Newren via GitGitGadget, May 11, 2021
  72. 6/8 dir: avoid unnecessary traversal into ignored directoryElijah Newren via GitGitGadget, May 11, 2021
  73. 8/8 dir: update stale description of treat_directory()Derrick Stolee via GitGitGadget, May 11, 2021
  74. 0/9 Directory traversal fixesElijah Newren via GitGitGadget, May 12, 2021
  75. 1/9 dir: convert trace calls to trace2 equivalentsElijah Newren via GitGitGadget, May 12, 2021
  76. 2/9 dir: report number of visited directories and paths with trace2Elijah Newren via GitGitGadget, May 12, 2021
  77. 4/9 t7300: add testcase showing unnecessary traversal into ignored directoryElijah Newren via GitGitGadget, May 12, 2021
  78. 6/9 dir: avoid unnecessary traversal into ignored directoryElijah Newren via GitGitGadget, May 12, 2021
  79. 8/9 dir: update stale description of treat_directory()Derrick Stolee via GitGitGadget, May 12, 2021
  80. Derrick StoleeMay 17, 2021
  81. Junio C HamanoMay 17, 2021
  82. Elijah NewrenMay 18, 2021
  83. Junio C HamanoMay 19, 2021
  84. 7/9 dir: traverse into untracked directories if they may have ignored subfilesElijah Newren via GitGitGadget, May 12, 2021
  85. 3/9 ls-files: error out on -i unless -o or -c are specifiedElijah Newren via GitGitGadget, May 12, 2021
  86. 5/9 t3001, t7300: add testcase showcasing missed directory traversalElijah Newren via GitGitGadget, May 12, 2021
  87. 9/9 dir: introduce readdir_skip_dot_and_dotdot() helperElijah Newren via GitGitGadget, May 12, 2021
  88. Derrick StoleeMay 17, 2021
  89. Elijah NewrenMay 18, 2021
  90. Derrick StoleeMay 17, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.