From 436d0b3298e154b970ed83c4c7e5ba5584974553 Mon Sep 17 00:00:00 2001 From: Carsten Grohmann Date: Wed, 22 Mar 2023 23:00:30 +0100 Subject: [PATCH] Show and hide elements reworked Elements should be hidden by default and shown if necessary. This is a constant behaviour with this change. It also prevents flickering when the page is loaded and the JS set all defaults. --- OOMAnalyser.html | 54 ++++++++++++++++++++++++++++++++---------------- OOMAnalyser.py | 27 +++++++----------------- 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/OOMAnalyser.html b/OOMAnalyser.html index a3cb1eb..03c1325 100644 --- a/OOMAnalyser.html +++ b/OOMAnalyser.html @@ -24,13 +24,31 @@ THIS PROGRAM COMES WITH NO WARRANTY font-size: 0.83em; } .js-text--default-hide { - /* empty just used to hide elements in the default view */ - + /* empty - used with JS to hide elements in the default view + * + * OOMDisplay.set_html_defaults() hides all elements by + * adding "js-text--display-none" to classList. + */ } .js-text--default-show { - /* empty just used to show elements in the default view */ + /* empty - used with JS to show elements in the default view + * + * OOMDisplay.set_html_defaults() shows all elements by + * removing "js-text--display-none" from classList. + */ } .js-text--display-none { + /* hide elements + * + * The visibility of elements will be toggled with JS. + * OOMAnalyser.show_elements(), OOMAnalyser.hide_elements() and + * OOMAnalyser.toggle_elements() are used to control the + * visibility. + * + * Set js-text--display-none to prevent flickering between loading + * the page and setting default values with + * OOMDisplay.set_html_defaults(). + */ display: none; } @@ -387,7 +405,7 @@ window.onerror = function (msg, url, lineNo, columnNo, errorObj) {

Summary

-
+

The OOM killer was automatically triggered to free memory, because the system couldn't satisfy the memory request. @@ -395,7 +413,7 @@ window.onerror = function (msg, url, lineNo, columnNo, errorObj) { to satisfy the original memory request.

-
+

The OOM killer was manually triggered (e.g. with "echo f > /proc/sysrq-trigger") by a user with root privileges. There is no demand to free memory but the OOM killer started @@ -403,7 +421,7 @@ window.onerror = function (msg, url, lineNo, columnNo, errorObj) { highest score.

-
+

The system has physical memory and swap space. That's @@ -413,7 +431,7 @@ window.onerror = function (msg, url, lineNo, columnNo, errorObj) { ( out of ) swap space are in use.

-
+

The system has physical memory and no swap space. @@ -421,7 +439,7 @@ window.onerror = function (msg, url, lineNo, columnNo, errorObj) { physical memory are in use.

-
+

The process "" (PID ) requested a memory chunk of order from the @@ -434,17 +452,17 @@ window.onerror = function (msg, url, lineNo, columnNo, errorObj) { memory.

-
+

- + The request failed because after its fulfillment the free memory would be below the memory low watermark. - + If this requirement were met, the free memory would still be above the low memory watermark. The request failed because there is no free chunk in the current or higher order. - + The request failed, but the reason is unknown. The memory shortage triggers the OOM process. @@ -453,22 +471,22 @@ window.onerror = function (msg, url, lineNo, columnNo, errorObj) {

The process "" (PID ) - + with an OOM score of has been terminated. It uses () of the resident memory.

-
+

Dynamic memory allocation is used by both the kernel and all applications. This leads to memory fragmentation and is a common behavior. - + The system memory is heavily fragmented, because all chunks with an order ≥ are in use. Allocation of larger contiguous memory areas will fail. - + The system memory is not heavily fragmented, because chunks with an order ≥ are freely available. @@ -879,10 +897,10 @@ window.onerror = function (msg, url, lineNo, columnNo, errorObj) { Page size - + Extracted from DMA zone buddyinfo - + Guessed diff --git a/OOMAnalyser.py b/OOMAnalyser.py index 588f439..11e853c 100644 --- a/OOMAnalyser.py +++ b/OOMAnalyser.py @@ -4154,7 +4154,7 @@ Out of memory: Killed process 651 (unattended-upgr) total-vm:108020kB, anon-rss: def __init__(self): self.oom = None - self.set_HTML_defaults() + self.set_html_defaults() self.update_toc() element = document.getElementById("version") @@ -4308,17 +4308,18 @@ Out of memory: Killed process 651 (unattended-upgr) total-vm:108020kB, anon-rss: else: element.innerHTML = self.svg_array_updown - def set_HTML_defaults(self): + def set_html_defaults(self): """Reset the HTML document but don't clean elements""" + + # show all hidden elements in the result table + show_elements("table .js-text--display-none") + # hide all elements marked to be hidden by default hide_elements(".js-text--default-hide") # show all elements marked to be shown by default show_elements(".js-text--default-show") - # show hidden rows - show_elements("table .js-text--display-none") - # clear notification box element = document.getElementById("notify_box") while element.firstChild: @@ -4362,7 +4363,7 @@ Out of memory: Killed process 651 (unattended-upgr) total-vm:108020kB, anon-rss: def reset_form(self): document.getElementById("textarea_oom").value = "" - self.set_HTML_defaults() + self.set_html_defaults() self.update_toc() def toggle_oom(self, show=False): @@ -4383,7 +4384,7 @@ Out of memory: Killed process 651 (unattended-upgr) total-vm:108020kB, anon-rss: self.oom = OOMEntity(self.load_from_form()) # set defaults and clear notifications - self.set_HTML_defaults() + self.set_html_defaults() analyser = OOMAnalyser(self.oom) success = analyser.analyse() @@ -4441,8 +4442,6 @@ Out of memory: Killed process 651 (unattended-upgr) total-vm:108020kB, anon-rss: ): show_elements(".js-alloc-failure--show") show_elements(".js-alloc-failure-unknown-reason-show") - else: - hide_elements(".js-alloc-failure--show") def _show_memory_fragmentation(self): """Show details about memory fragmentation""" @@ -4451,19 +4450,15 @@ Out of memory: Killed process 651 (unattended-upgr) total-vm:108020kB, anon-rss: show_elements(".js-memory-fragmentation--show") if self.oom_result.mem_fragmented: show_elements(".js-memory-heavy-fragmentation--show") - hide_elements(".js-memory-no-heavy-fragmentation--show") else: - hide_elements(".js-memory-heavy-fragmentation--show") show_elements(".js-memory-no-heavy-fragmentation--show") def _show_page_size(self): """Show page size""" if self.oom_result.details.get("_page_size_guessed", True): - hide_elements(".js-pagesize-determined--show") show_elements(".js-pagesize-guessed--show") else: show_elements(".js-pagesize-determined--show") - hide_elements(".js-pagesize-guessed--show") def _show_ram_usage(self): """Generate RAM usage diagram""" @@ -4512,9 +4507,7 @@ Out of memory: Killed process 651 (unattended-upgr) total-vm:108020kB, anon-rss: elem_svg_swap = document.getElementById("svg_swap") elem_svg_swap.appendChild(svg_swap) show_elements(".js-swap-active--show") - hide_elements(".js-swap-inactive--show") else: - hide_elements(".js-swap-active--show") show_elements(".js-swap-inactive--show") def _show_items(self): @@ -4522,11 +4515,9 @@ Out of memory: Killed process 651 (unattended-upgr) total-vm:108020kB, anon-rss: hide_element("input") show_element("analysis") if self.oom_result.oom_type == OOMEntityType.manual: - hide_elements(".js-oom-automatic--show") show_elements(".js-oom-manual--show") else: show_elements(".js-oom-automatic--show") - hide_elements(".js-oom-manual--show") for item in self.oom_result.details.keys(): # ignore internal items @@ -4538,8 +4529,6 @@ Out of memory: Killed process 651 (unattended-upgr) total-vm:108020kB, anon-rss: # since KernelConfig_5_0.EXTRACT_PATTERN_OVERLAY_50['Process killed by OOM'] if "killed_proc_score" in self.oom_result.details: show_elements(".js-killed-proc-score--show") - else: - hide_elements(".js-killed-proc-score--show") def sort_pstable(self, column_number): """