diff mbox series

pybootchartgui: render memory pressure as well

Message ID 20220802191126.697586-1-Martin.Jansa@gmail.com
State Accepted, archived
Commit 42010d0812246a418f30b4f1d9fbd3f374a3bbe9
Headers show
Series pybootchartgui: render memory pressure as well | expand

Commit Message

Martin Jansa Aug. 2, 2022, 7:11 p.m. UTC
* memory pressure is already collected in buildstats, render it as well
  when available
---
 scripts/pybootchartgui/pybootchartgui/draw.py | 44 +++++++++++++++++--
 .../pybootchartgui/pybootchartgui/parsing.py  |  5 +++
 .../pybootchartgui/pybootchartgui/samples.py  |  8 ++++
 3 files changed, 54 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/scripts/pybootchartgui/pybootchartgui/draw.py b/scripts/pybootchartgui/pybootchartgui/draw.py
index a13df3a3fa..3926bdd11e 100644
--- a/scripts/pybootchartgui/pybootchartgui/draw.py
+++ b/scripts/pybootchartgui/pybootchartgui/draw.py
@@ -88,6 +88,10 @@  CPU_PRESSURE_TOTAL_COLOR = CPU_COLOR
 IO_PRESSURE_AVG10_COLOR = (0.0, 0.0, 0.0, 1.0)
 # delta total IO pressure color
 IO_PRESSURE_TOTAL_COLOR = IO_COLOR
+# avg10 memory pressure color
+MEM_PRESSURE_AVG10_COLOR = (0.0, 0.0, 0.0, 1.0)
+# delta total memory pressure color
+MEM_PRESSURE_TOTAL_COLOR = DISK_TPUT_COLOR
 
 
 
@@ -460,12 +464,12 @@  def render_charts(ctx, options, clip, trace, curr_y, w, h, sec_w):
 
         curr_y = curr_y + 30 + bar_h
 
-    # render delta total io
+    # render I/O pressure chart
     if trace.io_pressure:
         draw_legend_line(ctx, "avg10 I/O Pressure", IO_PRESSURE_AVG10_COLOR, off_x, curr_y+20, leg_s)
         draw_legend_box(ctx, "delta total I/O Pressure", IO_PRESSURE_TOTAL_COLOR, off_x + 140, curr_y+20, leg_s)
 
-        # render avg10 io
+        # render delta total io
         chart_rect = (off_x, curr_y+30, w, bar_h)
         if clip_visible (clip, chart_rect):
             draw_box_ticks (ctx, chart_rect, sec_w)
@@ -474,7 +478,7 @@  def render_charts(ctx, options, clip, trace, curr_y, w, h, sec_w):
                     [(sample.time, sample.deltaTotal) for sample in trace.io_pressure], \
                     proc_tree, None)
 
-        # render io pressure
+        # render avg10 io
         max_sample = max (trace.io_pressure, key = lambda s: s.avg10)
         if clip_visible (clip, chart_rect):
             draw_chart (ctx, IO_PRESSURE_AVG10_COLOR, False, chart_rect, \
@@ -487,11 +491,45 @@  def render_charts(ctx, options, clip, trace, curr_y, w, h, sec_w):
         if (pos_x < off_x + 245):
             shift_x, shift_y = 5, 40
 
+
         label = "%d%%" % (max_sample.avg10)
         draw_text (ctx, label, IO_PRESSURE_AVG10_COLOR, pos_x + shift_x, curr_y + shift_y)
 
         curr_y = curr_y + 30 + bar_h
 
+    # render MEM pressure chart
+    if trace.mem_pressure:
+        draw_legend_line(ctx, "avg10 MEM Pressure", MEM_PRESSURE_AVG10_COLOR, off_x, curr_y+20, leg_s)
+        draw_legend_box(ctx, "delta total MEM Pressure", MEM_PRESSURE_TOTAL_COLOR, off_x + 140, curr_y+20, leg_s)
+
+        # render delta total mem
+        chart_rect = (off_x, curr_y+30, w, bar_h)
+        if clip_visible (clip, chart_rect):
+            draw_box_ticks (ctx, chart_rect, sec_w)
+            draw_annotations (ctx, proc_tree, trace.times, chart_rect)
+            draw_chart (ctx, MEM_PRESSURE_TOTAL_COLOR, True, chart_rect, \
+                    [(sample.time, sample.deltaTotal) for sample in trace.mem_pressure], \
+                    proc_tree, None)
+
+        # render avg10 mem
+        max_sample = max (trace.mem_pressure, key = lambda s: s.avg10)
+        if clip_visible (clip, chart_rect):
+            draw_chart (ctx, MEM_PRESSURE_AVG10_COLOR, False, chart_rect, \
+                    [(sample.time, sample.avg10) for sample in trace.mem_pressure], \
+                    proc_tree, None)
+
+        pos_x = off_x + ((max_sample.time - proc_tree.start_time) * w / proc_tree.duration)
+
+        shift_x, shift_y = -20, 20
+        if (pos_x < off_x + 245):
+            shift_x, shift_y = 5, 40
+
+
+        label = "%d%%" % (max_sample.avg10)
+        draw_text (ctx, label, MEM_PRESSURE_AVG10_COLOR, pos_x + shift_x, curr_y + shift_y)
+
+        curr_y = curr_y + 30 + bar_h
+
     # render disk space usage
     #
     # Draws the amount of disk space used on each volume relative to the
diff --git a/scripts/pybootchartgui/pybootchartgui/parsing.py b/scripts/pybootchartgui/pybootchartgui/parsing.py
index 004d6fb953..362d5153e8 100644
--- a/scripts/pybootchartgui/pybootchartgui/parsing.py
+++ b/scripts/pybootchartgui/pybootchartgui/parsing.py
@@ -51,6 +51,7 @@  class Trace:
         self.monitor_disk = None
         self.cpu_pressure = []
         self.io_pressure = []
+        self.mem_pressure = []
         self.times = [] # Always empty, but expected by draw.py when drawing system charts.
 
         if len(paths):
@@ -564,6 +565,8 @@  def _parse_pressure_logs(file, filename):
     pressure_stats = []
     if filename == "cpu.log":
         SamplingClass = CPUPressureSample
+    elif filename == "memory.log":
+        SamplingClass = MemPressureSample
     else:
         SamplingClass = IOPressureSample
     for time, lines in _parse_timed_blocks(file):
@@ -769,6 +772,8 @@  def _do_parse(writer, state, filename, file):
         state.cpu_pressure = _parse_pressure_logs(file, name)
     elif name == "io.log":
         state.io_pressure = _parse_pressure_logs(file, name)
+    elif name == "memory.log":
+        state.mem_pressure = _parse_pressure_logs(file, name)
     elif not filename.endswith('.log'):
         _parse_bitbake_buildstats(writer, state, filename, file)
     t2 = time.process_time()
diff --git a/scripts/pybootchartgui/pybootchartgui/samples.py b/scripts/pybootchartgui/pybootchartgui/samples.py
index 472dc27be0..a70d8a5a28 100644
--- a/scripts/pybootchartgui/pybootchartgui/samples.py
+++ b/scripts/pybootchartgui/pybootchartgui/samples.py
@@ -53,6 +53,14 @@  class IOPressureSample:
         self.avg300 = avg300
         self.deltaTotal = deltaTotal
 
+class MemPressureSample:
+    def __init__(self, time, avg10, avg60, avg300, deltaTotal):
+        self.time = time
+        self.avg10 = avg10
+        self.avg60 = avg60
+        self.avg300 = avg300
+        self.deltaTotal = deltaTotal
+
 
 class MemSample:
     used_values = ('MemTotal', 'MemFree', 'Buffers', 'Cached', 'SwapTotal', 'SwapFree',)