Skip to content

Commit

Permalink
track bucket collision counts, include in table diagnostics dump; fin…
Browse files Browse the repository at this point in the history
…ish moving pdb->raddbg conversion tables over to dynamic & heuristically chosen table sizes
  • Loading branch information
ryanfleury committed Feb 9, 2024
1 parent cdb53eb commit 44d9b57
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 102 deletions.
4 changes: 2 additions & 2 deletions project.4coder
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ commands =
},
.rjf_f4 =
{
.win = "build raddbg_from_pdb release telemetry && pushd build && raddbg_from_pdb.exe --exe:mule_main.exe --pdb:mule_main.pdb --out:mule_main.raddbg --capture && popd",
.win = "build raddbg_from_pdb release telemetry && pushd build && raddbg_from_pdb.exe --exe:raddbg.exe --pdb:raddbg.pdb --out:raddbg.raddbg --capture && popd",
.linux = "",
.out = "*compilation*",
.footer_panel = true,
Expand All @@ -83,7 +83,7 @@ commands =
},
.rjf_f5 =
{
.win = "pushd build && raddbg_from_pdb.exe --exe:mule_main.exe --pdb:mule_main.pdb --out:mule_main.raddbg --capture && popd",
.win = "pushd build && raddbg_from_pdb.exe --exe:raddbg.exe --pdb:raddbg.pdb --out:raddbg.raddbg --capture && popd",
.linux = "",
.out = "*compilation*",
.footer_panel = true,
Expand Down
94 changes: 51 additions & 43 deletions src/raddbg_cons/raddbg_cons.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ cons_root_new(CONS_RootParams *params){
cons__u64toptr_init(arena, &result->scope_map, BKTCOUNT(params->bucket_count_scopes));
cons__u64toptr_init(arena, &result->local_map, BKTCOUNT(params->bucket_count_locals));
cons__u64toptr_init(arena, &result->type_from_id_map, BKTCOUNT(params->bucket_count_types));
cons__str8toptr_init(arena, &result->construct_map, 4096);
cons__str8toptr_init(arena, &result->construct_map, BKTCOUNT(params->bucket_count_type_constructs));

#undef BKTCOUNT
}
Expand Down Expand Up @@ -1753,6 +1753,7 @@ cons__name_map_add_pair(CONS_Root *root, CONS__NameMap *map, String8 string, U32
SLLStackPush_N(map->buckets[bucket_idx], match, bucket_next);
SLLQueuePush_N(map->first, map->last, match, order_next);
map->name_count += 1;
map->bucket_collision_count += (match->bucket_next != 0);
}

// find existing idx
Expand Down Expand Up @@ -1839,6 +1840,7 @@ cons__u64toptr_insert(Arena *arena, CONS__U64ToPtrMap *map, U64 key,
lookup->fill_k = 0;

map->pair_count += 1;
map->bucket_collision_count += (node->next != 0);
}
}

Expand Down Expand Up @@ -1879,6 +1881,7 @@ cons__str8toptr_insert(Arena *arena, CONS__Str8ToPtrMap *map, String8 key, U64 h
node->key = push_str8_copy(arena, key);
node->hash = hash;
node->ptr = ptr;
map->bucket_collision_count += (node->next != 0);
map->pair_count += 1;
ProfEnd();
}
Expand Down Expand Up @@ -1965,6 +1968,7 @@ cons__string(CONS__BakeCtx *bctx, String8 str){
SLLStackPush_N(strs->buckets[bucket_idx], node, bucket_next);

match = node;
strs->bucket_collision_count += (node->bucket_next != 0);
}

// extract idx to return
Expand Down Expand Up @@ -2033,6 +2037,7 @@ cons__idx_run(CONS__BakeCtx *bctx, U32 *idx_run, U32 count){
SLLStackPush_N(idxs->buckets[bucket_idx], node, bucket_next);

match = node;
idxs->bucket_collision_count += (node->bucket_next != 0);
}

// extract idx to return
Expand Down Expand Up @@ -2430,57 +2435,60 @@ cons__source_combine_lines(Arena *arena, CONS__LineMapFragment *first){
// gather line number map
CONS__SrcLineMapBucket *first_bucket = 0;
CONS__SrcLineMapBucket *last_bucket = 0;

U64 line_count = 0;
U64 voff_count = 0;
U64 max_line_num = 0;
for (CONS__LineMapFragment *map_fragment = first;
map_fragment != 0;
map_fragment = map_fragment->next){
CONS_LineSequence *sequence = &map_fragment->sequence->line_seq;

U64 *seq_voffs = sequence->voffs;
U32 *seq_line_nums = sequence->line_nums;
U64 seq_line_count = sequence->line_count;
for (U64 i = 0; i < seq_line_count; i += 1){
U32 line_num = seq_line_nums[i];
U64 voff = seq_voffs[i];

// update unique voff counter & max line number
voff_count += 1;
max_line_num = Max(max_line_num, line_num);

// find match
CONS__SrcLineMapBucket *match = 0;
for (CONS__SrcLineMapBucket *node = first_bucket;
node != 0;
node = node->next){
if (node->line_num == line_num){
match = node;
break;
ProfScope("gather line number map")
{
for (CONS__LineMapFragment *map_fragment = first;
map_fragment != 0;
map_fragment = map_fragment->next){
CONS_LineSequence *sequence = &map_fragment->sequence->line_seq;

U64 *seq_voffs = sequence->voffs;
U32 *seq_line_nums = sequence->line_nums;
U64 seq_line_count = sequence->line_count;
for (U64 i = 0; i < seq_line_count; i += 1){
U32 line_num = seq_line_nums[i];
U64 voff = seq_voffs[i];

// update unique voff counter & max line number
voff_count += 1;
max_line_num = Max(max_line_num, line_num);

// find match
CONS__SrcLineMapBucket *match = 0;
for (CONS__SrcLineMapBucket *node = first_bucket;
node != 0;
node = node->next){
if (node->line_num == line_num){
match = node;
break;
}
}

// introduce new line if no match
if (match == 0){
match = push_array(scratch.arena, CONS__SrcLineMapBucket, 1);
SLLQueuePush(first_bucket, last_bucket, match);
match->line_num = line_num;
line_count += 1;
}

// insert new voff
{
CONS__SrcLineMapVoffBlock *block = push_array(scratch.arena, CONS__SrcLineMapVoffBlock, 1);
SLLQueuePush(match->first_voff_block, match->last_voff_block, block);
match->voff_count += 1;
block->voff = voff;
}
}

// introduce new line if no match
if (match == 0){
match = push_array(scratch.arena, CONS__SrcLineMapBucket, 1);
SLLQueuePush(first_bucket, last_bucket, match);
match->line_num = line_num;
line_count += 1;
}

// insert new voff
{
CONS__SrcLineMapVoffBlock *block = push_array(scratch.arena, CONS__SrcLineMapVoffBlock, 1);
SLLQueuePush(match->first_voff_block, match->last_voff_block, block);
match->voff_count += 1;
block->voff = voff;
}
}
}

// bake sortable keys array
CONS__SortKey *keys = push_array_no_zero(scratch.arena, CONS__SortKey, line_count);
ProfScope("bake sortable keys array")
{
CONS__SortKey *key_ptr = keys;
for (CONS__SrcLineMapBucket *node = first_bucket;
Expand All @@ -2498,7 +2506,7 @@ cons__source_combine_lines(Arena *arena, CONS__LineMapFragment *first){
U32 *line_nums = push_array_no_zero(arena, U32, line_count);
U32 *line_ranges = push_array_no_zero(arena, U32, line_count + 1);
U64 *voffs = push_array_no_zero(arena, U64, voff_count);

ProfScope("bake result")
{
U64 *voff_ptr = voffs;
for (U32 i = 0; i < line_count; i += 1){
Expand Down
6 changes: 6 additions & 0 deletions src/raddbg_cons/raddbg_cons.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typedef struct CONS_RootParams{
U32 bucket_count_scopes;
U32 bucket_count_locals;
U32 bucket_count_types;
U64 bucket_count_type_constructs;
} CONS_RootParams;

static CONS_Root* cons_root_new(CONS_RootParams *params);
Expand Down Expand Up @@ -485,6 +486,7 @@ typedef struct CONS__NameMapNode{
typedef struct CONS__NameMap{
CONS__NameMapNode **buckets;
U64 buckets_count;
U64 bucket_collision_count;
CONS__NameMapNode *first;
CONS__NameMapNode *last;
U64 name_count;
Expand All @@ -505,6 +507,7 @@ typedef struct CONS__U64ToPtrNode{
typedef struct CONS__U64ToPtrMap{
CONS__U64ToPtrNode **buckets;
U64 buckets_count;
U64 bucket_collision_count;
U64 pair_count;
} CONS__U64ToPtrMap;

Expand Down Expand Up @@ -533,6 +536,7 @@ typedef struct CONS__Str8ToPtrNode{
typedef struct CONS__Str8ToPtrMap{
CONS__Str8ToPtrNode **buckets;
U64 buckets_count;
U64 bucket_collision_count;
U64 pair_count;
} CONS__Str8ToPtrMap;

Expand Down Expand Up @@ -647,6 +651,7 @@ typedef struct CONS__Strings{
CONS__StringNode *order_last;
CONS__StringNode **buckets;
U64 buckets_count;
U64 bucket_collision_count;
U32 count;
} CONS__Strings;

Expand All @@ -665,6 +670,7 @@ typedef struct CONS__IdxRuns{
CONS__IdxRunNode *order_last;
CONS__IdxRunNode **buckets;
U64 buckets_count;
U64 bucket_collision_count;
U32 count;
U32 idx_count;
} CONS__IdxRuns;
Expand Down
Loading

0 comments on commit 44d9b57

Please sign in to comment.