Package: bootchart2 / 0.14.4-3

0003-pybootchartgui-ensure-a-MemSample-is-valid-before-st.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
From d39566348784eb80672f0d0bd78f0a839424281c Mon Sep 17 00:00:00 2001
From: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
Date: Sun, 17 Jun 2012 14:50:05 +0200
Subject: [PATCH] pybootchartgui: ensure a MemSample is valid before storing
 it

Fix #39
---
 pybootchartgui/parsing.py |    6 +++---
 pybootchartgui/samples.py |   10 +++++++++-
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/pybootchartgui/parsing.py b/pybootchartgui/parsing.py
index 778149b..18eb17c 100644
--- a/pybootchartgui/parsing.py
+++ b/pybootchartgui/parsing.py
@@ -465,10 +465,10 @@ def _parse_proc_meminfo_log(file):
             match = meminfo_re.match(line)
             if not match:
                 raise ParseError("Invalid meminfo line \"%s\"" % match.groups(0))
-            if match.group(1) in used_values:
-                sample.add_value(match.group(1), int(match.group(2)))
+            sample.add_value(match.group(1), int(match.group(2)))
 
-        mem_stats.append(sample)
+        if sample.valid():
+            mem_stats.append(sample)
 
     return mem_stats
 
diff --git a/pybootchartgui/samples.py b/pybootchartgui/samples.py
index ce703b8..a7da2ea 100644
--- a/pybootchartgui/samples.py
+++ b/pybootchartgui/samples.py
@@ -38,12 +38,20 @@ class CPUSample:
                str(self.sys) + "\t" + str(self.io) + "\t" + str (self.swap)
 
 class MemSample:
+    used_values = ('MemTotal', 'MemFree', 'Buffers', 'Cached', 'SwapTotal', 'SwapFree',)
+
     def __init__(self, time):
         self.time = time
         self.records = {}
 
     def add_value(self, name, value):
-        self.records[name] = value
+        if name in MemSample.used_values:
+            self.records[name] = value
+
+    def valid(self):
+        keys = self.records.keys()
+        # discard incomplete samples
+        return [v for v in MemSample.used_values if v not in keys] == []
 
 class ProcessSample:
     def __init__(self, time, state, cpu_sample):
-- 
1.7.10.4