Skip to content
Snippets Groups Projects
Commit 3087d731 authored by pompolic's avatar pompolic
Browse files

Functions to compute the allocations of a single stack frame

parent a6c29ba6
No related branches found
No related tags found
No related merge requests found
......@@ -220,3 +220,19 @@ class ParserStack:
def depth(self):
return len(self.p_stack)
def compute_parserstack_frame_allocs(self):
stack_depth = 0
stack_events = None
for index, ev in enumerate(self.stack_events[::-1]):
# Since this is meant to be called from ParserStack.pop(), the assumption here is that the first element will be a StackEvent.POP
# So we can stop gathering memory allocations at the point stack_depth becomes 0 again: that'll be the point in the list,
# where the parser we just popped from the stack had been pushed on it. Allocations prior to that are not relevant and are not considered
if ev[0] == StackEvent.POP:
stack_depth += 1
elif ev[0] == StackEvent.PUSH:
stack_depth -= 1
if stack_depth == 0:
stack_events = self.stack_events[-index:]
print(stack_events)
break
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment