revision: trace topo-walk statistics

We trace statistics about the effectiveness of changed-path Bloom filters since 42e50e78 (revision.c: add trace2 stats around Bloom filter usage, 2020-04-06). Add similar tracing for the topo-walk algorithm that uses generation numbers to limit the walk size. This information can help investigate and describe benefits to heuristics and other changes. The information that is printed is in JSON format and can be formatted nicely to present as follows: { "count_explort_walked":2603, "count_indegree_walked":2603, "count_topo_walked":473 } Each of these values count the number of commits are visited by each of the three "stages" of the topo-walk as detailed in b4542418 (revision.c: generation-based topo-order algorithm, 2018-11-01). Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Dec 30, 2020 at 04:31 UTC 90b666da601a5ccf9bbc3f2282fb166bf3fdade7
1 file changed +31
revision.c
+31
@@ -3308,6 +3308,26 @@ struct topo_walk_info {
3308 struct author_date_slab author_date;
3309 };
3310
3311 +static int topo_walk_atexit_registered;
3312 +static unsigned int count_explore_walked;
3313 +static unsigned int count_indegree_walked;
3314 +static unsigned int count_topo_walked;
3315 +
3316 +static void trace2_topo_walk_statistics_atexit(void)
3317 +{
3318 + struct json_writer jw = JSON_WRITER_INIT;
3319 +
3320 + jw_object_begin(&jw, 0);
3321 + jw_object_intmax(&jw, "count_explore_walked", count_explore_walked);
3322 + jw_object_intmax(&jw, "count_indegree_walked", count_indegree_walked);
3323 + jw_object_intmax(&jw, "count_topo_walked", count_topo_walked);
3324 + jw_end(&jw);
3325 +
3326 + trace2_data_json("topo_walk", the_repository, "statistics", &jw);
3327 +
3328 + jw_release(&jw);
3329 +}
3330 +
3331 static inline void test_flag_and_insert(struct prio_queue *q, struct commit *c, int flag)
3332 {
3333 if (c->object.flags & flag)
@@ -3329,6 +3349,8 @@ static void explore_walk_step(struct rev_info *revs)
3349 if (repo_parse_commit_gently(revs->repo, c, 1) < 0)
3350 return;
3351
3352 + count_explore_walked++;
3353 +
3354 if (revs->sort_order == REV_SORT_BY_AUTHOR_DATE)
3355 record_author_date(&info->author_date, c);
3356
@@ -3367,6 +3389,8 @@ static void indegree_walk_step(struct rev_info *revs)
3389 if (repo_parse_commit_gently(revs->repo, c, 1) < 0)
3390 return;
3391
3392 + count_indegree_walked++;
3393 +
3394 explore_to_depth(revs, commit_graph_generation(c));
3395
3396 for (p = c->parents; p; p = p->next) {
@@ -3476,6 +3500,11 @@ static void init_topo_walk(struct rev_info *revs)
3500 */
3501 if (revs->sort_order == REV_SORT_IN_GRAPH_ORDER)
3502 prio_queue_reverse(&info->topo_queue);
3503 +
3504 + if (trace2_is_enabled() && !topo_walk_atexit_registered) {
3505 + atexit(trace2_topo_walk_statistics_atexit);
3506 + topo_walk_atexit_registered = 1;
3507 + }
3508 }
3509
3510 static struct commit *next_topo_commit(struct rev_info *revs)
@@ -3502,6 +3531,8 @@ static void expand_topo_walk(struct rev_info *revs, struct commit *commit)
3531 oid_to_hex(&commit->object.oid));
3532 }
3533
3534 + count_topo_walked++;
3535 +
3536 for (p = commit->parents; p; p = p->next) {
3537 struct commit *parent = p->item;
3538 int *pi;