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>
This commit is contained in:
Garima Singh 2020-04-06 16:59:53 +00:00 committed by Junio C Hamano
parent a56b9464cd
commit 42e50e78c6

View File

@ -30,6 +30,7 @@
#include "hashmap.h"
#include "utf8.h"
#include "bloom.h"
#include "json-writer.h"
volatile show_early_output_fn_t show_early_output;
@ -625,6 +626,30 @@ static void file_change(struct diff_options *options,
options->flags.has_changes = 1;
}
static int bloom_filter_atexit_registered;
static unsigned int count_bloom_filter_maybe;
static unsigned int count_bloom_filter_definitely_not;
static unsigned int count_bloom_filter_false_positive;
static unsigned int count_bloom_filter_not_present;
static unsigned int count_bloom_filter_length_zero;
static void trace2_bloom_filter_statistics_atexit(void)
{
struct json_writer jw = JSON_WRITER_INIT;
jw_object_begin(&jw, 0);
jw_object_intmax(&jw, "filter_not_present", count_bloom_filter_not_present);
jw_object_intmax(&jw, "zero_length_filter", count_bloom_filter_length_zero);
jw_object_intmax(&jw, "maybe", count_bloom_filter_maybe);
jw_object_intmax(&jw, "definitely_not", count_bloom_filter_definitely_not);
jw_object_intmax(&jw, "false_positive", count_bloom_filter_false_positive);
jw_end(&jw);
trace2_data_json("bloom", the_repository, "statistics", &jw);
jw_release(&jw);
}
static void prepare_to_use_bloom_filter(struct rev_info *revs)
{
struct pathspec_item *pi;
@ -661,6 +686,11 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs)
revs->bloom_key = xmalloc(sizeof(struct bloom_key));
fill_bloom_key(path, len, revs->bloom_key, revs->bloom_filter_settings);
if (trace2_is_enabled() && !bloom_filter_atexit_registered) {
atexit(trace2_bloom_filter_statistics_atexit);
bloom_filter_atexit_registered = 1;
}
free(path_alloc);
}
@ -679,10 +709,12 @@ static int check_maybe_different_in_bloom_filter(struct rev_info *revs,
filter = get_bloom_filter(revs->repo, commit, 0);
if (!filter) {
count_bloom_filter_not_present++;
return -1;
}
if (!filter->len) {
count_bloom_filter_length_zero++;
return -1;
}
@ -690,6 +722,11 @@ static int check_maybe_different_in_bloom_filter(struct rev_info *revs,
revs->bloom_key,
revs->bloom_filter_settings);
if (result)
count_bloom_filter_maybe++;
else
count_bloom_filter_definitely_not++;
return result;
}
@ -736,6 +773,10 @@ static int rev_compare_tree(struct rev_info *revs,
&revs->pruning) < 0)
return REV_TREE_DIFFERENT;
if (!nth_parent)
if (bloom_ret == 1 && tree_difference == REV_TREE_SAME)
count_bloom_filter_false_positive++;
return tree_difference;
}