midx.c: instrument MIDX and bitmap generation with trace2 regions

When debugging MIDX and MIDX-bitmap related issues, it is useful to figure out where Git is spending its time. GitHub has been using the below trace2 regions to instrument various components of generating a MIDX itself, as well time spent preparing to build a MIDX bitmap. These are limited to instrumenting the following functions: - midx.c::find_commits_for_midx_bitmap() - midx.c::midx_pack_order() - midx.c::prepare_midx_packing_data() - midx.c::write_midx_bitmap() - midx.c::write_midx_internal() - midx.c::write_midx_reverse_index() to start and end with a trace2_region_enter() and trace2_region_leave(), respectively. The category for all of these is "midx", which matches the existing convention. The region description matches the name of the function. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Oct 12, 2022 at 18:01 UTC 2dcff52524e611413cb0cb49015f0d105f5f8dfa
1 file changed +28
midx.c
+28
@@ -913,6 +913,8 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx)
913 uint32_t *pack_order;
914 uint32_t i;
915
916 + trace2_region_enter("midx", "midx_pack_order", the_repository);
917 +
918 ALLOC_ARRAY(data, ctx->entries_nr);
919 for (i = 0; i < ctx->entries_nr; i++) {
920 struct pack_midx_entry *e = &ctx->entries[i];
@@ -930,6 +932,8 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx)
932 pack_order[i] = data[i].nr;
933 free(data);
934
935 + trace2_region_leave("midx", "midx_pack_order", the_repository);
936 +
937 return pack_order;
938 }
939
@@ -939,6 +943,8 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,
943 struct strbuf buf = STRBUF_INIT;
944 const char *tmp_file;
945
946 + trace2_region_enter("midx", "write_midx_reverse_index", the_repository);
947 +
948 strbuf_addf(&buf, "%s-%s.rev", midx_name, hash_to_hex(midx_hash));
949
950 tmp_file = write_rev_file_order(NULL, ctx->pack_order, ctx->entries_nr,
@@ -948,6 +954,8 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,
954 die(_("cannot store reverse index file"));
955
956 strbuf_release(&buf);
957 +
958 + trace2_region_leave("midx", "write_midx_reverse_index", the_repository);
959 }
960
961 static void clear_midx_files_ext(const char *object_dir, const char *ext,
@@ -963,6 +971,8 @@ static void prepare_midx_packing_data(struct packing_data *pdata,
971 {
972 uint32_t i;
973
974 + trace2_region_enter("midx", "prepare_midx_packing_data", the_repository);
975 +
976 memset(pdata, 0, sizeof(struct packing_data));
977 prepare_packing_data(the_repository, pdata);
978
@@ -973,6 +983,8 @@ static void prepare_midx_packing_data(struct packing_data *pdata,
983 oe_set_in_pack(pdata, to,
984 ctx->info[ctx->pack_perm[from->pack_int_id]].p);
985 }
986 +
987 + trace2_region_leave("midx", "prepare_midx_packing_data", the_repository);
988 }
989
990 static int add_ref_to_pending(const char *refname,
@@ -1070,6 +1082,9 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr
1082 struct rev_info revs;
1083 struct bitmap_commit_cb cb = {0};
1084
1085 + trace2_region_enter("midx", "find_commits_for_midx_bitmap",
1086 + the_repository);
1087 +
1088 cb.ctx = ctx;
1089
1090 repo_init_revisions(the_repository, &revs, NULL);
@@ -1103,6 +1118,10 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr
1118 *indexed_commits_nr_p = cb.commits_nr;
1119
1120 release_revisions(&revs);
1121 +
1122 + trace2_region_leave("midx", "find_commits_for_midx_bitmap",
1123 + the_repository);
1124 +
1125 return cb.commits;
1126 }
1127
@@ -1120,6 +1139,8 @@ static int write_midx_bitmap(const char *midx_name,
1139 char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name,
1140 hash_to_hex(midx_hash));
1141
1142 + trace2_region_enter("midx", "write_midx_bitmap", the_repository);
1143 +
1144 if (flags & MIDX_WRITE_BITMAP_HASH_CACHE)
1145 options |= BITMAP_OPT_HASH_CACHE;
1146
@@ -1165,6 +1186,9 @@ static int write_midx_bitmap(const char *midx_name,
1186 cleanup:
1187 free(index);
1188 free(bitmap_name);
1189 +
1190 + trace2_region_leave("midx", "write_midx_bitmap", the_repository);
1191 +
1192 return ret;
1193 }
1194
@@ -1211,6 +1235,8 @@ static int write_midx_internal(const char *object_dir,
1235 int result = 0;
1236 struct chunkfile *cf;
1237
1238 + trace2_region_enter("midx", "write_midx_internal", the_repository);
1239 +
1240 get_midx_filename(&midx_name, object_dir);
1241 if (safe_create_leading_directories(midx_name.buf))
1242 die_errno(_("unable to create leading directories of %s"),
@@ -1552,6 +1578,8 @@ cleanup:
1578 free(ctx.pack_order);
1579 strbuf_release(&midx_name);
1580
1581 + trace2_region_leave("midx", "write_midx_internal", the_repository);
1582 +
1583 return result;
1584 }
1585