[gnome-continuous-yocto/gnomeostree-3.28-rocko: 3544/8267] pybootchartgui: simplify drawing of memory usage



commit 820c042b3603b4ab2a1e439c765085797859efe9
Author: Patrick Ohly <patrick ohly intel com>
Date:   Wed Nov 30 10:50:09 2016 +0100

    pybootchartgui: simplify drawing of memory usage
    
    The internal representation after parsing now matches exactly
    what the drawing code needs, thus speeding up drawing a bit.
    However, the main motivation is to store exactly that required
    information in a more compact file.
    
    (From OE-Core rev: ca06e67a0bb5820b38fda4c8dfee20764c1e59ae)
    
    Signed-off-by: Patrick Ohly <patrick ohly intel com>
    Signed-off-by: Ross Burton <ross burton intel com>
    Signed-off-by: Richard Purdie <richard purdie linuxfoundation org>

 scripts/pybootchartgui/pybootchartgui/draw.py    |   12 ++++++------
 scripts/pybootchartgui/pybootchartgui/parsing.py |    2 +-
 scripts/pybootchartgui/pybootchartgui/samples.py |   16 ++++++++++++++++
 3 files changed, 23 insertions(+), 7 deletions(-)
---
diff --git a/scripts/pybootchartgui/pybootchartgui/draw.py b/scripts/pybootchartgui/pybootchartgui/draw.py
index f0143ad..201ce45 100644
--- a/scripts/pybootchartgui/pybootchartgui/draw.py
+++ b/scripts/pybootchartgui/pybootchartgui/draw.py
@@ -463,25 +463,25 @@ def render_charts(ctx, options, clip, trace, curr_y, w, h, sec_w):
        chart_rect = (off_x, curr_y+30, w, meminfo_bar_h)
        mem_stats = trace.mem_stats
        if mem_stats and clip_visible (clip, chart_rect):
-               mem_scale = max(sample.records['MemTotal'] - sample.records['MemFree'] for sample in 
mem_stats)
+               mem_scale = max(sample.buffers for sample in mem_stats)
                draw_legend_box(ctx, "Mem cached (scale: %u MiB)" % (float(mem_scale) / 1024), 
MEM_CACHED_COLOR, off_x, curr_y+20, leg_s)
                draw_legend_box(ctx, "Used", MEM_USED_COLOR, off_x + 240, curr_y+20, leg_s)
                draw_legend_box(ctx, "Buffers", MEM_BUFFERS_COLOR, off_x + 360, curr_y+20, leg_s)
-               draw_legend_line(ctx, "Swap (scale: %u MiB)" % max([(sample.records['SwapTotal'] - 
sample.records['SwapFree'])/1024 for sample in mem_stats]), \
+               draw_legend_line(ctx, "Swap (scale: %u MiB)" % max([(sample.swap)/1024 for sample in 
mem_stats]), \
                                 MEM_SWAP_COLOR, off_x + 480, curr_y+20, leg_s)
                draw_box_ticks(ctx, chart_rect, sec_w)
                draw_annotations(ctx, proc_tree, trace.times, chart_rect)
                draw_chart(ctx, MEM_BUFFERS_COLOR, True, chart_rect, \
-                          [(sample.time, sample.records['MemTotal'] - sample.records['MemFree']) for sample 
in trace.mem_stats], \
+                          [(sample.time, sample.buffers) for sample in trace.mem_stats], \
                           proc_tree, [0, mem_scale])
                draw_chart(ctx, MEM_USED_COLOR, True, chart_rect, \
-                          [(sample.time, sample.records['MemTotal'] - sample.records['MemFree'] - 
sample.records['Buffers']) for sample in mem_stats], \
+                          [(sample.time, sample.used) for sample in mem_stats], \
                           proc_tree, [0, mem_scale])
                draw_chart(ctx, MEM_CACHED_COLOR, True, chart_rect, \
-                          [(sample.time, sample.records['Cached']) for sample in mem_stats], \
+                          [(sample.time, sample.cached) for sample in mem_stats], \
                           proc_tree, [0, mem_scale])
                draw_chart(ctx, MEM_SWAP_COLOR, False, chart_rect, \
-                          [(sample.time, float(sample.records['SwapTotal'] - sample.records['SwapFree'])) 
for sample in mem_stats], \
+                          [(sample.time, float(sample.swap)) for sample in mem_stats], \
                           proc_tree, None)
 
                curr_y = curr_y + meminfo_bar_h
diff --git a/scripts/pybootchartgui/pybootchartgui/parsing.py 
b/scripts/pybootchartgui/pybootchartgui/parsing.py
index 301145a..1c8d8ef 100644
--- a/scripts/pybootchartgui/pybootchartgui/parsing.py
+++ b/scripts/pybootchartgui/pybootchartgui/parsing.py
@@ -503,7 +503,7 @@ def _parse_proc_meminfo_log(file):
             sample.add_value(match.group(1), int(match.group(2)))
 
         if sample.valid():
-            mem_stats.append(sample)
+            mem_stats.append(DrawMemSample(sample))
 
     return mem_stats
 
diff --git a/scripts/pybootchartgui/pybootchartgui/samples.py 
b/scripts/pybootchartgui/pybootchartgui/samples.py
index bedca41..9fc309b 100644
--- a/scripts/pybootchartgui/pybootchartgui/samples.py
+++ b/scripts/pybootchartgui/pybootchartgui/samples.py
@@ -53,6 +53,22 @@ class MemSample:
         # discard incomplete samples
         return [v for v in MemSample.used_values if v not in keys] == []
 
+class DrawMemSample:
+    """
+    Condensed version of a MemSample with exactly the values used by the drawing code.
+    Initialized either from a valid MemSample or
+    a tuple/list of buffer/used/cached/swap values.
+    """
+    def __init__(self, mem_sample):
+        self.time = mem_sample.time
+        if isinstance(mem_sample, MemSample):
+            self.buffers = mem_sample.records['MemTotal'] - mem_sample.records['MemFree']
+            self.used = mem_sample.records['MemTotal'] - mem_sample.records['MemFree'] - 
mem_sample.records['Buffers']
+            self.cached = mem_sample.records['Cached']
+            self.swap = mem_sample.records['SwapTotal'] - mem_sample.records['SwapFree']
+        else:
+            self.buffers, self.used, self.cached, self.swap = mem_sample
+
 class DiskSpaceSample:
     def __init__(self, time):
         self.time = time


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]