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 <dstolee@microsoft.com Helped-by: SZEDER Gábor <szeder.dev@gmail.com> Helped-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Garima Singh <garima.singh@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Garima Singh committed
Apr 6, 2020 at 16:59 UTC
42e50e78c6fd8978c2218bbd7b3483ae51d5e3f9
1 file changed
+41
revision.c
+41
@@ -30,6 +30,7 @@
30
#include "hashmap.h"
31
#include "utf8.h"
32
#include "bloom.h"
33
+#include "json-writer.h"
34
35
volatile show_early_output_fn_t show_early_output;
36
@@ -625,6 +626,30 @@ static void file_change(struct diff_options *options,
626
options->flags.has_changes = 1;
627
}
628
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
+
653
static void prepare_to_use_bloom_filter(struct rev_info *revs)
654
{
655
struct pathspec_item *pi;
@@ -661,6 +686,11 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs)
686
revs->bloom_key = xmalloc(sizeof(struct bloom_key));
687
fill_bloom_key(path, len, revs->bloom_key, revs->bloom_filter_settings);
688
689
+ if (trace2_is_enabled() && !bloom_filter_atexit_registered) {
690
+ atexit(trace2_bloom_filter_statistics_atexit);
691
+ bloom_filter_atexit_registered = 1;
692
+ }
693
+
694
free(path_alloc);
695
}
696
@@ -679,10 +709,12 @@ static int check_maybe_different_in_bloom_filter(struct rev_info *revs,
709
filter = get_bloom_filter(revs->repo, commit, 0);
710
711
if (!filter) {
712
+ count_bloom_filter_not_present++;
713
return -1;
714
}
715
716
if (!filter->len) {
717
+ count_bloom_filter_length_zero++;
718
return -1;
719
}
720
@@ -690,6 +722,11 @@ static int check_maybe_different_in_bloom_filter(struct rev_info *revs,
722
revs->bloom_key,
723
revs->bloom_filter_settings);
724
725
+ if (result)
726
+ count_bloom_filter_maybe++;
727
+ else
728
+ count_bloom_filter_definitely_not++;
729
+
730
return result;
731
}
732
@@ -736,6 +773,10 @@ static int rev_compare_tree(struct rev_info *revs,
773
&revs->pruning) < 0)
774
return REV_TREE_DIFFERENT;
775
776
+ if (!nth_parent)
777
+ if (bloom_ret == 1 && tree_difference == REV_TREE_SAME)
778
+ count_bloom_filter_false_positive++;
779
+
780
return tree_difference;
781
}
782