Skip to content

Commit 42e50e7

Browse files
garimasi514gitster
authored andcommitted
revision.c: add trace2 stats around Bloom filter usage
Add trace2 statistics around Bloom filter usage and behavior for 'git log -- path' commands that are hoping to benefit from the presence of computed changed paths Bloom filters. These statistics are great for performance analysis work and for formal testing, which we will see in the commit following this one. Helped-by: Derrick Stolee <[email protected] Helped-by: SZEDER Gábor <[email protected]> Helped-by: Jonathan Tan <[email protected]> Signed-off-by: Garima Singh <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a56b946 commit 42e50e7

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

revision.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "hashmap.h"
3131
#include "utf8.h"
3232
#include "bloom.h"
33+
#include "json-writer.h"
3334

3435
volatile show_early_output_fn_t show_early_output;
3536

@@ -625,6 +626,30 @@ static void file_change(struct diff_options *options,
625626
options->flags.has_changes = 1;
626627
}
627628

629+
static int bloom_filter_atexit_registered;
630+
static unsigned int count_bloom_filter_maybe;
631+
static unsigned int count_bloom_filter_definitely_not;
632+
static unsigned int count_bloom_filter_false_positive;
633+
static unsigned int count_bloom_filter_not_present;
634+
static unsigned int count_bloom_filter_length_zero;
635+
636+
static void trace2_bloom_filter_statistics_atexit(void)
637+
{
638+
struct json_writer jw = JSON_WRITER_INIT;
639+
640+
jw_object_begin(&jw, 0);
641+
jw_object_intmax(&jw, "filter_not_present", count_bloom_filter_not_present);
642+
jw_object_intmax(&jw, "zero_length_filter", count_bloom_filter_length_zero);
643+
jw_object_intmax(&jw, "maybe", count_bloom_filter_maybe);
644+
jw_object_intmax(&jw, "definitely_not", count_bloom_filter_definitely_not);
645+
jw_object_intmax(&jw, "false_positive", count_bloom_filter_false_positive);
646+
jw_end(&jw);
647+
648+
trace2_data_json("bloom", the_repository, "statistics", &jw);
649+
650+
jw_release(&jw);
651+
}
652+
628653
static void prepare_to_use_bloom_filter(struct rev_info *revs)
629654
{
630655
struct pathspec_item *pi;
@@ -661,6 +686,11 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs)
661686
revs->bloom_key = xmalloc(sizeof(struct bloom_key));
662687
fill_bloom_key(path, len, revs->bloom_key, revs->bloom_filter_settings);
663688

689+
if (trace2_is_enabled() && !bloom_filter_atexit_registered) {
690+
atexit(trace2_bloom_filter_statistics_atexit);
691+
bloom_filter_atexit_registered = 1;
692+
}
693+
664694
free(path_alloc);
665695
}
666696

@@ -679,17 +709,24 @@ static int check_maybe_different_in_bloom_filter(struct rev_info *revs,
679709
filter = get_bloom_filter(revs->repo, commit, 0);
680710

681711
if (!filter) {
712+
count_bloom_filter_not_present++;
682713
return -1;
683714
}
684715

685716
if (!filter->len) {
717+
count_bloom_filter_length_zero++;
686718
return -1;
687719
}
688720

689721
result = bloom_filter_contains(filter,
690722
revs->bloom_key,
691723
revs->bloom_filter_settings);
692724

725+
if (result)
726+
count_bloom_filter_maybe++;
727+
else
728+
count_bloom_filter_definitely_not++;
729+
693730
return result;
694731
}
695732

@@ -736,6 +773,10 @@ static int rev_compare_tree(struct rev_info *revs,
736773
&revs->pruning) < 0)
737774
return REV_TREE_DIFFERENT;
738775

776+
if (!nth_parent)
777+
if (bloom_ret == 1 && tree_difference == REV_TREE_SAME)
778+
count_bloom_filter_false_positive++;
779+
739780
return tree_difference;
740781
}
741782

0 commit comments

Comments
 (0)