From 3f19a50f1771f43c29f7db4035640faff11e2ae6 Mon Sep 17 00:00:00 2001 From: Carsten Grohmann Date: Sat, 25 Mar 2023 20:50:09 +0100 Subject: [PATCH] Move regexs from OOMAnalyser to BaseKernelConfig --- OOMAnalyser.py | 80 +++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/OOMAnalyser.py b/OOMAnalyser.py index fea0835..56842b4 100644 --- a/OOMAnalyser.py +++ b/OOMAnalyser.py @@ -554,18 +554,36 @@ class BaseKernelConfig: @type: (int, int, str) """ + REC_FREE_MEMORY_CHUNKS = re.compile( + "Node (?P\d+) (?PDMA|DMA32|Normal): (?P.*) = (?P\d+)kB" + ) + """RE to extract free memory chunks of a memory zone""" + REC_OOM_BEGIN = re.compile(r"invoked oom-killer:", re.MULTILINE) """RE to match the first line of an OOM block""" REC_OOM_END = re.compile(r"^Killed process \d+", re.MULTILINE) """RE to match the last line of an OOM block""" + REC_PAGE_SIZE = re.compile("Node 0 DMA: \d+\*(?P\d+)kB") + """RE to extract the page size from buddyinfo DMA zone""" + REC_PROCESS_LINE = re.compile( r"^\[(?P[ \d]+)\]\s+(?P\d+)\s+(?P\d+)\s+(?P\d+)\s+(?P\d+)\s+" r"(?P\d+)\s+(?P\d+)\s+(?P-?\d+)\s+(?P.+)\s*" ) """Match content of process table""" + REC_WATERMARK = re.compile( + "Node (?P\d+) (?PDMA|DMA32|Normal) " + "free:(?P\d+)kB " + "min:(?P\d+)kB " + "low:(?P\d+)kB " + "high:(?P\d+)kB " + ".*" + ) + """RE to extract watermark information in a memory zone""" + watermark_start = "Node 0 DMA free:" """ Pattern to find the start of the memory watermark information @@ -2804,42 +2822,7 @@ class OOMAnalyser: ) """RE to match the OOM line with kernel version""" - REC_FREE_MEMORY_CHUNKS = re.compile( - "Node (?P\d+) (?PDMA|DMA32|Normal): (?P.*) = (?P\d+)kB" - ) - """RE to extract free memory chunks of a memor zone""" - - REC_PAGE_SIZE = re.compile("Node 0 DMA: \d+\*(?P\d+)kB") - """RE to extract the page size from buddyinfo DMA zone""" - - REC_WATERMARK = re.compile( - "Node (?P\d+) (?PDMA|DMA32|Normal) " - "free:(?P\d+)kB " - "min:(?P\d+)kB " - "low:(?P\d+)kB " - "high:(?P\d+)kB " - ".*" - ) - """RE to extract watermark information in a memory zone""" - - def __init__(self, oom): - self.oom_entity = oom - self.oom_result = OOMResult() - - def _identify_kernel_version(self): - """ - Identify the used kernel version and - - @rtype: bool - """ - match = self.REC_KERNEL_VERSION.search(self.oom_entity.text) - if not match: - self.oom_result.error_msg = "Failed to extract kernel version from OOM text" - return False - self.oom_result.kversion = match.group("kernel_version") - return True - - rec_split_kversion = re.compile( + REC_SPLIT_KVERSION = re.compile( r"(?P" r"(?P\d+)\.(?P\d+)" # major . minor r"(\.\d+)?" # optional: patch level @@ -2858,6 +2841,23 @@ class OOMAnalyser: - 3.10.0-514.6.1.el7.x86_64 #1 """ + def __init__(self, oom): + self.oom_entity = oom + self.oom_result = OOMResult() + + def _identify_kernel_version(self): + """ + Identify the used kernel version and + + @rtype: bool + """ + match = self.REC_KERNEL_VERSION.search(self.oom_entity.text) + if not match: + self.oom_result.error_msg = "Failed to extract kernel version from OOM text" + return False + self.oom_result.kversion = match.group("kernel_version") + return True + def _check_kversion_greater_equal(self, kversion, min_version): """ Returns True if the kernel version is greater or equal to the minimum version @@ -2866,7 +2866,7 @@ class OOMAnalyser: @param (int, int, str) min_version: Minimum version @rtype: bool """ - match = self.rec_split_kversion.match(kversion) + match = self.REC_SPLIT_KVERSION.match(kversion) if not match: self.oom_result.error_msg = ( @@ -3039,7 +3039,7 @@ class OOMAnalyser: def _extract_page_size(self): """Extract page size from buddyinfo DMZ zone""" - match = self.REC_PAGE_SIZE.search(self.oom_entity.text) + match = self.oom_result.kconfig.REC_PAGE_SIZE.search(self.oom_entity.text) if match: self.oom_result.details["page_size_kb"] = int(match.group("page_size")) self.oom_result.details["_page_size_guessed"] = False @@ -3081,7 +3081,7 @@ class OOMAnalyser: self.oom_entity.goto_previous_line() for line in self.oom_entity: - match = self.REC_FREE_MEMORY_CHUNKS.match(line) + match = self.oom_result.kconfig.REC_FREE_MEMORY_CHUNKS.match(line) if not match: continue node = int(match.group("node")) @@ -3140,7 +3140,7 @@ class OOMAnalyser: zone = None self.oom_entity.goto_previous_line() for line in self.oom_entity: - match = self.REC_WATERMARK.match(line) + match = self.oom_result.kconfig.REC_WATERMARK.match(line) if not match: if line.startswith("lowmem_reserve[]:"): # zone and node are defined in the previous round