From 00eab3875145d3116c9dafe37864c3b6f472eb20 Mon Sep 17 00:00:00 2001 From: pompolic <pompolic@special-circumstanc.es> Date: Sat, 13 May 2023 17:47:55 +0200 Subject: [PATCH] WIP commit - convert int(self.arena) calls to use self.arena_int variable --- gdb-port/parser.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/gdb-port/parser.py b/gdb-port/parser.py index 034f782..e6774d0 100644 --- a/gdb-port/parser.py +++ b/gdb-port/parser.py @@ -81,6 +81,8 @@ class ParserStack: self.parse_state = parse_state self.parse_state_gdbval = parse_state self.arena = arena + self.arena_int = int(arena) + # TODO: remove? self.arena_gdbval = arena # self.parse_state and self.arena is expected to be an int by TopLevelParse and is ultimately used to index into the memory usage dict # parse_state is set by top_level_parse.first_h_do_parse_after_h_packrat_parse() to be an int @@ -89,7 +91,7 @@ class ParserStack: self.p_stack = [] self.unclaimed_mem_use = 0 self.stack_events = [] - self.pending_allocs = {} + self.pending_allocs = { self.arena_int : {} } # Represents the index of a "waterline" on the stack_events for the purpose of counting allocations # This is the index of the last event (stack push or pop) where the relevant allocations have been committed to TopLevelParse's memory stats. # Due to the semantics of stack events, this means that if self.committed points to a push event, nothing in that "frame" has been committed yet. if it points to a pop event, everything in that "frame" has been committed @@ -146,8 +148,8 @@ class ParserStack: # TODO: where should commit_at_push() be called? HDoParseBreakpoint determines whether to stop, which ParserStack doesn't know about. could be a bool parameter to push() if should_commit: allocs = self.commit_at_push() - #for addr, alloc in allocs.items(): - # self.pending_allocs[addr] = self.pending_allocs.get(addr, 0) + alloc + for addr, alloc in allocs.items(): + self.pending_allocs[self.arena_int][addr] = self.pending_allocs[self.arena_int].get(addr, 0) + alloc def pop(self): parser_obj = self.peek() @@ -160,8 +162,8 @@ class ParserStack: allocs = self.commit_at_pop() # TODO: where do we commit unclaimed allocs in a parserstack? - #for addr, alloc in allocs.items(): - # self.pending_allocs[addr] = self.pending_allocs.get(addr, 0) + alloc + for addr, alloc in allocs.items(): + self.pending_allocs[self.arena_int][addr] = self.pending_allocs[self.arena_int].get(addr, 0) + alloc #print("adding mem use: parser:", str(parser_obj), "arena:", hex(int(self.arena)), "bytes:", allocated_bytes) # DEBUG #print("adding mem use (alternate): parser:", str(parser_obj), "arena:", hex(int(self.arena)), "bytes:", allocs) # DEBUG #parser_obj.add_mem_use(int(self.arena), allocs) @@ -289,7 +291,7 @@ class ParserStack: # print("commit_at_pop: pop_allocs:", { current_event[2].address: current_frame_alloc }) # DEBUG pop_allocs[current_event[2].address] = pop_allocs.get(current_event[2].address, 0) + current_frame_alloc parser_cache[current_event[2].address] = current_event[2] - current_event[2].add_mem_use(int(self.arena), current_frame_alloc) + current_event[2].add_mem_use(self.arena_int, current_frame_alloc) profiler.disable() # DEBUG return pop_allocs # return { current_event[2].address: current_frame_alloc } @@ -314,7 +316,7 @@ class ParserStack: self.unclaimed_mem_use += pop_allocs.pop(0,0) # Account for allocs and remove with no parser, so it doesn't cause problems in the loop below for parser_addr, alloc in pop_allocs.items(): #top_level_parse.parser_by_address(parser_addr).add_mem_use(int(self.arena), alloc) - parser_cache[parser_addr].add_mem_use(int(self.arena), alloc) + parser_cache[parser_addr].add_mem_use(self.arena_int, alloc) self.committed = len(self.stack_events)-1 return pop_allocs @@ -340,7 +342,7 @@ class ParserStack: differences = map(lambda smaller, bigger: bigger-smaller, bytes_list[:-1], bytes_list[1:]) for index, event in enumerate(ev_list[:-1]): alloc = next(differences) - event[2].add_mem_use(int(self.arena), alloc) + event[2].add_mem_use(self.arena_int, alloc) push_allocs[event[2].address] = push_allocs.get(event[2].address, 0) + alloc #print("commit_at_push: push_allocs:", push_allocs) # DEBUG @@ -357,4 +359,4 @@ class ParserStack: return self.pending_allocs def clear_pending_allocations() - self.pending_allocs = {} + self.pending_allocs = { self.arena_int : {} } -- GitLab