From 7bd69f427e99dcd86bd628bc76865693c5b32500 Mon Sep 17 00:00:00 2001
From: pompolic <pompolic@special-circumstanc.es>
Date: Thu, 26 Jan 2023 17:00:43 +0100
Subject: [PATCH] Separate apply counts by arena

---
 gdb-port/parser.py          | 36 +++++++++++++++++++++---------------
 gdb-port/top-level-parse.py |  6 +++---
 2 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/gdb-port/parser.py b/gdb-port/parser.py
index c7f4043..b1215e4 100644
--- a/gdb-port/parser.py
+++ b/gdb-port/parser.py
@@ -4,9 +4,9 @@ class Parser:
 		self.address = address
 		self.bytes_used = {}
 		self.bytes_used_from_hammer_stats = {} # TODO: once breakpoints vs detailed are exclusive, this should be removed
-		self.apply_count = 0
-		self.successful_parse_count = 0
-		self.failed_parse_count = 0
+		self.apply_count = {} # Per arena
+		self.successful_parse_count = {}
+		self.failed_parse_count = {}
 
 	def name_parser(self, name):
 		self.name = name
@@ -49,23 +49,29 @@ class Parser:
 			res = sum(self.bytes_used.values())
 		return res
 
-	def increment_apply_count(self):
-		self.apply_count += 1
+	def increment_apply_count(self, arena):
+		applycount = self.apply_count.get(arena, 0)
+		applycount += 1
+		self.apply_count.set(arena, applycount)
 
-	def get_apply_count(self):
-		return self.apply_count
+	def get_apply_count(self, arena):
+		return self.apply_count.get(arena, 0)
 
-	def increment_successful_parse_count(self):
-		self.successful_parse_count += 1
+	def increment_successful_parse_count(self, arena):
+		s_count = self.successful_parse_count.get(arena, 0)
+		s_count += 1
+		self.successful_parse_count_count.set(arena, s_count)
 
-	def get_successful_parse_count(self):
-		return self.successful_parse_count
+	def get_successful_parse_count(self, arena):
+		return self.successful_parse_count.get(arena, 0)
 
-	def increment_failed_parse_count(self):
-		self.failed_parse_count += 1
+	def increment_failed_parse_count(self, arena):
+		f_count = self.failed_parse_count.get(arena, 0)
+		f_count += 1
+		self.failed_parse_count_count.set(arena, f_count)
 
-	def get_failed_parse_count(self):
-		return self.failed_parse_count
+	def get_failed_parse_count(self, arena):
+		return self.failed_parse_count.get(arena, 0)
 
 class ParserStack:
 	def __init__(self, parse_state, arena):
diff --git a/gdb-port/top-level-parse.py b/gdb-port/top-level-parse.py
index 077731c..1976dfd 100644
--- a/gdb-port/top-level-parse.py
+++ b/gdb-port/top-level-parse.py
@@ -74,7 +74,7 @@ class TopLevelParse:
 			parser_obj = Parser(None, parser)
 			self.parser_objs[parser] = parser_obj
 		self.h_do_parse_parser = parser_obj # TODO: current_parser_env should be set here instead too
-		parser_obj.increment_apply_count()
+		parser_obj.increment_apply_count(int(arena))
 		if parser_stack.parse_state is None and parser_stack.parse_state != parse_state:
 			self.first_h_do_parse_after_packrat_parse(parse_state, arena)
 
@@ -86,9 +86,9 @@ class TopLevelParse:
 		# If other backends are supported, this might change to pushing/popping the stack in h_do_parse()
 		self.h_do_parse_parser = parser_obj # Restore the "current" parser, otherwise it'll show the parser h_do_parse() was last called with on the GUI and backtrace
 		if ret_val:
-			parser_obj.increment_successful_parse_count()
+			parser_obj.increment_successful_parse_count(int(parse_state['arena']))
 		else:
-			parser_obj.increment_failed_parse_count()
+			parser_obj.increment_failed_parse_count(int(parse_state['arena']))
 
 		if self.memory_stat_method == HammerMemoryStatisticsMethod.DETAILED_ARENA_STATS:
 		#if self.extended_arena_stats_available(): # DEBUG
-- 
GitLab