@matheusbsbs / matheus-bagliano / commits / 7734f04873
Fork 0

lstat_cache(): print a warning if doing ping-pong between cache types

This is a debug patch which is only to be used while the lstat_cache() is in the test stage, and should be removed/reverted before the final relase. I think it should be useful to catch these warnings, as I it could be an indication of that the cache would not be very effective if it is doing ping-pong by switching between different cache types too many times. Also, if someone is experimenting with the lstat_cache(), this patch will maybe be useful while debugging. If someone is able to trigger the warning, then send a mail to the GIT mailing list, containing the first 15 lines of the warning, and a short description of the GIT commands to trigger the warnings. I hope someone is willing to use this patch for a while, to be able to catch possible ping-pong's. Signed-off-by: Kjetil Barvik <barvik@broadpark.no> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kjetil Barvik committed Feb 9, 2009 at 21:54 UTC 7734f04873cfaddd0b148074a633f1f824fd961f
1 file changed +23
symlinks.c
+23
@@ -51,6 +51,11 @@ static inline void reset_lstat_cache(void)
51 */
52 }
53
54 +#define SWITCHES_BEFORE_WARNING 10
55 +static unsigned int cache_switches, number_of_warnings;
56 +static unsigned int current_cache_func, last_cache_func;
57 +static unsigned int total_calls;
58 +
59 #define FL_DIR (1 << 0)
60 #define FL_NOENT (1 << 1)
61 #define FL_SYMLINK (1 << 2)
@@ -77,6 +82,7 @@ static int lstat_cache(const char *name, int len,
82 int match_flags, ret_flags, save_flags, max_len, ret;
83 struct stat st;
84
85 + total_calls++;
86 if (cache.track_flags != track_flags ||
87 cache.prefix_len_stat_func != prefix_len_stat_func) {
88 /*
@@ -88,6 +94,17 @@ static int lstat_cache(const char *name, int len,
94 cache.track_flags = track_flags;
95 cache.prefix_len_stat_func = prefix_len_stat_func;
96 match_len = last_slash = 0;
97 + cache_switches++;
98 + if (cache_switches > SWITCHES_BEFORE_WARNING) {
99 + if (number_of_warnings < 10 || number_of_warnings % 1000 == 0)
100 + printf("warning from %s:%d cache_switches:%u > %u "\
101 + "(current:%u last:%u total:%u)\n",
102 + __FILE__, __LINE__,
103 + cache_switches, SWITCHES_BEFORE_WARNING,
104 + current_cache_func, last_cache_func,
105 + total_calls);
106 + number_of_warnings++;
107 + }
108 } else {
109 /*
110 * Check to see if we have a match from the cache for
@@ -216,6 +233,8 @@ void clear_lstat_cache(void)
233 */
234 int has_symlink_leading_path(const char *name, int len)
235 {
236 + last_cache_func = current_cache_func;
237 + current_cache_func = 1;
238 return lstat_cache(name, len,
239 FL_SYMLINK|FL_DIR, USE_ONLY_LSTAT) &
240 FL_SYMLINK;
@@ -227,6 +246,8 @@ int has_symlink_leading_path(const char *name, int len)
246 */
247 int has_symlink_or_noent_leading_path(const char *name, int len)
248 {
249 + last_cache_func = current_cache_func;
250 + current_cache_func = 2;
251 return lstat_cache(name, len,
252 FL_SYMLINK|FL_NOENT|FL_DIR, USE_ONLY_LSTAT) &
253 (FL_SYMLINK|FL_NOENT);
@@ -241,6 +262,8 @@ int has_symlink_or_noent_leading_path(const char *name, int len)
262 */
263 int has_dirs_only_path(const char *name, int len, int prefix_len)
264 {
265 + last_cache_func = current_cache_func;
266 + current_cache_func = 3;
267 return lstat_cache(name, len,
268 FL_DIR|FL_FULLPATH, prefix_len) &
269 FL_DIR;