From 82249e74402fb4b18aab9086a24948cadfb7fe67 Mon Sep 17 00:00:00 2001 From: Carsten Grohmann Date: Wed, 13 Dec 2017 07:31:39 +0100 Subject: [PATCH] Pep8 --- OOMAnalyser.py | 70 ++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 39 deletions(-) diff --git a/OOMAnalyser.py b/OOMAnalyser.py index fd22cd3..d77ac07 100644 --- a/OOMAnalyser.py +++ b/OOMAnalyser.py @@ -7,12 +7,13 @@ import re -DEBUG=False +DEBUG = False """Show additional information during the development cycle""" -VERSION="0.1.0" +VERSION = "0.1.0" """Version number""" + def hide_element(element_id): """Hide the given HTML element""" document.getElementById(element_id).style.display = 'none' @@ -312,14 +313,14 @@ Killed process 6576 (java) total-vm:33914892kB, anon-rss:20629004kB, file-rss:0k REC_MEMINFO_1 = re.compile( # head line r'^Mem-Info:.*' - + # first line break r'(?:\n)' - + # first line (starting with a space) r'^active_anon:(?P\d+) inactive_anon:(?P\d+) ' r'isolated_anon:(?P\d+)' - + # next line break r'(?:\n)' @@ -341,22 +342,14 @@ Killed process 6576 (java) total-vm:33914892kB, anon-rss:20629004kB, file-rss:0k REC_MEMINFO_2 = re.compile( r'^ slab_reclaimable:(?P\d+) slab_unreclaimable:(?P\d+)' - - # next line break r'(?:\n)' - r'^ mapped:(?P\d+) shmem:(?P\d+) pagetables:(?P\d+) ' r'bounce:(?P\d+)' - - # next line break r'(?:\n)' - - r'^ free:(?P\d+) free_pcp:(?P\d+) free_cma:(?P\d+)' - - , re.MULTILINE + r'^ free:(?P\d+) free_pcp:(?P\d+) free_cma:(?P\d+)', + re.MULTILINE ) - REC_MEM_NODEINFO = re.compile(r'(^Node \d+ (DMA|Normal|hugepages).*(:?\n))+', re.MULTILINE) mem_modinfo_entries = ("active_anon_pages", "inactive_anon_pages", "isolated_anon_pages", @@ -397,8 +390,7 @@ Killed process 6576 (java) total-vm:33914892kB, anon-rss:20629004kB, file-rss:0k r'score (?P\d+) or sacrifice child' r'(?:\n)' r'Killed process \d+ \(.*\) total-vm:(?P\d+)kB, anon-rss:(?P\d+)kB, ' - r'file-rss:(?P\d+)kB, shmem-rss:(?P\d+)kB' - , + r'file-rss:(?P\d+)kB, shmem-rss:(?P\d+)kB', re.MULTILINE) lines = [] @@ -436,7 +428,7 @@ Killed process 6576 (java) total-vm:33914892kB, anon-rss:20629004kB, file-rss:0k print("ERROR: HTML element not found: ", item) return content = self.details.get(item, '') - if type(content) is str: + if isinstance(content, str): content = content.strip() element.textContent = content if DEBUG: @@ -610,7 +602,7 @@ Killed process 6576 (java) total-vm:33914892kB, anon-rss:20629004kB, file-rss:0k # TODO Add to HTML #match = self.REC_PAGEINFO.search(self.oom.text) - #if match: + # if match: # self.details.update(match.groupdict()) match = self.REC_PROCESSES.search(self.oom.text) @@ -635,7 +627,7 @@ Killed process 6576 (java) total-vm:33914892kB, anon-rss:20629004kB, file-rss:0k if item.endswith('_kb') or item.endswith('_pages'): try: self.details[item] = int(self.details[item]) - except: + except BaseException: error('Converting item {}: {} to integer failed'. format(item, self.details[item])) kernel_version = self.details.get('kernel_version', '') @@ -666,7 +658,7 @@ Killed process 6576 (java) total-vm:33914892kB, anon-rss:20629004kB, file-rss:0k # SwapUsed = SwapTotal - SwapFree - SwapCache self.details['swap_used_kb'] = self.details['swap_total_kb'] - self.details['swap_free_kb'] - \ - self.details['swap_cache_kb'] + self.details['swap_cache_kb'] def _show_details(self): """ @@ -682,33 +674,33 @@ Killed process 6576 (java) total-vm:33914892kB, anon-rss:20629004kB, file-rss:0k self._set_single_item(item) svg_swap = self._generate_svg_bar_chart( - ('Swap Used', self.details['swap_used_kb']), - ('Swap Free', self.details['swap_free_kb']), + ('Swap Used', self.details['swap_used_kb']), + ('Swap Free', self.details['swap_free_kb']), ('Swap Cached', self.details['swap_cache_kb']), ) elem_svg_swap = document.getElementById('svg_swap') elem_svg_swap.appendChild(svg_swap) svg_ram = self._generate_svg_bar_chart( - ('Active mem', self.details['active_anon_pages']), + ('Active mem', self.details['active_anon_pages']), ('Inactive mem', self.details['inactive_anon_pages']), ('Isolated mem', self.details['isolated_anon_pages']), - ('Active PC', self.details['active_file_pages']), - ('Inactive PC', self.details['inactive_file_pages']), - ('Isolated PC', self.details['isolated_file_pages']), - ('Unevictable', self.details['unevictable_pages']), - ('Dirty', self.details['dirty_pages']), - ('Writeback', self.details['writeback_pages']), - ('Unstable', self.details['unstable_pages']), - ('Slab reclaimable', self.details['slab_reclaimable_pages']), - ('Slab unreclaimable', self.details['slab_unreclaimable_pages']), - ('Mapped', self.details['mapped_pages']), - ('Shared', self.details['shmem_pages']), + ('Active PC', self.details['active_file_pages']), + ('Inactive PC', self.details['inactive_file_pages']), + ('Isolated PC', self.details['isolated_file_pages']), + ('Unevictable', self.details['unevictable_pages']), + ('Dirty', self.details['dirty_pages']), + ('Writeback', self.details['writeback_pages']), + ('Unstable', self.details['unstable_pages']), + ('Slab reclaimable', self.details['slab_reclaimable_pages']), + ('Slab unreclaimable', self.details['slab_unreclaimable_pages']), + ('Mapped', self.details['mapped_pages']), + ('Shared', self.details['shmem_pages']), ('Pagetable', self.details['pagetables_pages']), - ('Bounce', self.details['bounce_pages']), - ('Free', self.details['free_pages']), - ('Free PCP', self.details['free_pcp_pages']), - ('Free CMA', self.details['free_cma_pages']), + ('Bounce', self.details['bounce_pages']), + ('Free', self.details['free_pages']), + ('Free PCP', self.details['free_pcp_pages']), + ('Free CMA', self.details['free_cma_pages']), ) elem_svg_ram = document.getElementById('svg_ram') elem_svg_ram.appendChild(svg_ram)