Skip to content

Commit 2dcff52

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1dc4f1e commit 2dcff52

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

midx.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,8 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx)
913913
uint32_t *pack_order;
914914
uint32_t i;
915915

916+
trace2_region_enter("midx", "midx_pack_order", the_repository);
917+
916918
ALLOC_ARRAY(data, ctx->entries_nr);
917919
for (i = 0; i < ctx->entries_nr; i++) {
918920
struct pack_midx_entry *e = &ctx->entries[i];
@@ -930,6 +932,8 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx)
930932
pack_order[i] = data[i].nr;
931933
free(data);
932934

935+
trace2_region_leave("midx", "midx_pack_order", the_repository);
936+
933937
return pack_order;
934938
}
935939

@@ -939,6 +943,8 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,
939943
struct strbuf buf = STRBUF_INIT;
940944
const char *tmp_file;
941945

946+
trace2_region_enter("midx", "write_midx_reverse_index", the_repository);
947+
942948
strbuf_addf(&buf, "%s-%s.rev", midx_name, hash_to_hex(midx_hash));
943949

944950
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,
948954
die(_("cannot store reverse index file"));
949955

950956
strbuf_release(&buf);
957+
958+
trace2_region_leave("midx", "write_midx_reverse_index", the_repository);
951959
}
952960

953961
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,
963971
{
964972
uint32_t i;
965973

974+
trace2_region_enter("midx", "prepare_midx_packing_data", the_repository);
975+
966976
memset(pdata, 0, sizeof(struct packing_data));
967977
prepare_packing_data(the_repository, pdata);
968978

@@ -973,6 +983,8 @@ static void prepare_midx_packing_data(struct packing_data *pdata,
973983
oe_set_in_pack(pdata, to,
974984
ctx->info[ctx->pack_perm[from->pack_int_id]].p);
975985
}
986+
987+
trace2_region_leave("midx", "prepare_midx_packing_data", the_repository);
976988
}
977989

978990
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
10701082
struct rev_info revs;
10711083
struct bitmap_commit_cb cb = {0};
10721084

1085+
trace2_region_enter("midx", "find_commits_for_midx_bitmap",
1086+
the_repository);
1087+
10731088
cb.ctx = ctx;
10741089

10751090
repo_init_revisions(the_repository, &revs, NULL);
@@ -1103,6 +1118,10 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr
11031118
*indexed_commits_nr_p = cb.commits_nr;
11041119

11051120
release_revisions(&revs);
1121+
1122+
trace2_region_leave("midx", "find_commits_for_midx_bitmap",
1123+
the_repository);
1124+
11061125
return cb.commits;
11071126
}
11081127

@@ -1120,6 +1139,8 @@ static int write_midx_bitmap(const char *midx_name,
11201139
char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name,
11211140
hash_to_hex(midx_hash));
11221141

1142+
trace2_region_enter("midx", "write_midx_bitmap", the_repository);
1143+
11231144
if (flags & MIDX_WRITE_BITMAP_HASH_CACHE)
11241145
options |= BITMAP_OPT_HASH_CACHE;
11251146

@@ -1165,6 +1186,9 @@ static int write_midx_bitmap(const char *midx_name,
11651186
cleanup:
11661187
free(index);
11671188
free(bitmap_name);
1189+
1190+
trace2_region_leave("midx", "write_midx_bitmap", the_repository);
1191+
11681192
return ret;
11691193
}
11701194

@@ -1211,6 +1235,8 @@ static int write_midx_internal(const char *object_dir,
12111235
int result = 0;
12121236
struct chunkfile *cf;
12131237

1238+
trace2_region_enter("midx", "write_midx_internal", the_repository);
1239+
12141240
get_midx_filename(&midx_name, object_dir);
12151241
if (safe_create_leading_directories(midx_name.buf))
12161242
die_errno(_("unable to create leading directories of %s"),
@@ -1552,6 +1578,8 @@ static int write_midx_internal(const char *object_dir,
15521578
free(ctx.pack_order);
15531579
strbuf_release(&midx_name);
15541580

1581+
trace2_region_leave("midx", "write_midx_internal", the_repository);
1582+
15551583
return result;
15561584
}
15571585

0 commit comments

Comments
 (0)