diff --git a/gdb-port/top-level-parse.py b/gdb-port/top-level-parse.py index da6a1e0aa79408157d68cfdba461bf4b77730724..ee40a1c887639784f19e745d386b89d0df934a30 100644 --- a/gdb-port/top-level-parse.py +++ b/gdb-port/top-level-parse.py @@ -66,6 +66,11 @@ class TopLevelParse: self.parser_objs[parser] = parser_obj parser_stack = self.peek_parserstack() parser_stack.push(parser_obj, arena, stopping_at_bp) + if stopping_at_bp: + profiler.enable() + self.gather_all_allocations_in_parserstacks() + self.commit_pending_allocations(self.pending_allocations) + profiler.disable() parser_obj.increment_apply_count(int(arena)) if parser_stack.parse_state is None and parser_stack.parse_state != parse_state_int: self.first_h_do_parse_after_packrat_parse(parse_state_int, arena_int) @@ -277,8 +282,14 @@ class TopLevelParse: self.pending_allocs[ps.arena_int] = pending_allocs - # TODO: allocations are grouped by arena, then parser address. we get the arena address from the parser stack, which may be shared between parser stacks - # Therefore, it can't just be blindly assigned to a key with the arena's address. the two dicts need to be merged, with the values of duplicate entries added together - # However, the problem is that doing this naively would require two nested for loops minimum + # TODO: allocations are grouped by arena, then parser address. we get the arena address from the parser stack, which may be shared between parser stacks + # Therefore, it can't just be blindly assigned to a key with the arena's address. the two dicts need to be merged, with the values of duplicate entries added together + # However, the problem is that doing this naively would require two nested for loops minimum + # TODO: check if grouping { parser : { arena : alloc } } would work better + def commit_pending_allocations(self): + for arena, allocs in self.pending_allocs.items(): + for addr, alloc in allocs.items(): + parser_objs[addr].add_mem_use(arena, alloc) + self.pending_allocs = {} top_level_parse = TopLevelParse()