]> code.ossystems Code Review - openembedded-core.git/commitdiff
pybootchartgui: render disk space usage
authorPatrick Ohly <patrick.ohly@intel.com>
Wed, 30 Nov 2016 09:50:08 +0000 (10:50 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 7 Dec 2016 10:36:11 +0000 (10:36 +0000)
This adds a new, separate chart showing the amount of disk space used
over time for each volume monitored during the build. The hight of the
graph entries represents the delta between current usage and minimal
usage during the build.

That's more useful than showing just the current usage, because then a
graph showing changes in the order of MBs in a volume that is several
GB large would be just flat.

The legend shows the maximum of those deltas, i.e. maximum amount of
space needed for the build. Minor caveat: sampling of disk space usage
starts a bit later than the initial task, so the displayed value may
be slightly lower than the actual amount of space needed because
sampling does not record the actual initial state.

Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
scripts/pybootchartgui/pybootchartgui/draw.py
scripts/pybootchartgui/pybootchartgui/parsing.py
scripts/pybootchartgui/pybootchartgui/samples.py

index ec5dd333a1229be5307075eed041ed349b8a7d06..f0143ad0d6b0af6f2bf4d4e3dafa17f387111453 100644 (file)
@@ -133,6 +133,16 @@ TASK_COLOR_PACKAGE = (0.0, 1.00, 1.00, 1.0)
 # Package Write RPM/DEB/IPK task color
 TASK_COLOR_PACKAGE_WRITE = (0.0, 0.50, 0.50, 1.0)
 
+# Distinct colors used for different disk volumnes.
+# If we have more volumns, colors get re-used.
+VOLUME_COLORS = [
+       (1.0, 1.0, 0.00, 1.0),
+       (0.0, 1.00, 0.00, 1.0),
+       (1.0, 0.00, 1.00, 1.0),
+       (0.0, 0.00, 1.00, 1.0),
+       (0.0, 1.00, 1.00, 1.0),
+]
+
 # Process states
 STATE_UNDEFINED = 0
 STATE_RUNNING   = 1
@@ -397,6 +407,58 @@ def render_charts(ctx, options, clip, trace, curr_y, w, h, sec_w):
 
                curr_y = curr_y + 30 + bar_h
 
+       # render disk space usage
+       #
+       # Draws the amount of disk space used on each volume relative to the
+       # lowest recorded amount. The graphs for each volume are stacked above
+       # each other so that total disk usage is visible.
+       if trace.monitor_disk:
+               ctx.set_font_size(LEGEND_FONT_SIZE)
+               # Determine set of volumes for which we have
+               # information and the minimal amount of used disk
+               # space for each. Currently samples are allowed to
+               # not have a values for all volumes; drawing could be
+               # made more efficient if that wasn't the case.
+               volumes = set()
+               min_used = {}
+               for sample in trace.monitor_disk:
+                       for volume, used in sample.records.items():
+                               volumes.add(volume)
+                               if volume not in min_used or min_used[volume] > used:
+                                       min_used[volume] = used
+               volumes = sorted(list(volumes))
+               disk_scale = 0
+               for i, volume in enumerate(volumes):
+                       volume_scale = max([sample.records[volume] - min_used[volume]
+                                           for sample in trace.monitor_disk
+                                           if volume in sample.records])
+                       # Does not take length of volume name into account, but fixed offset
+                       # works okay in practice.
+                       draw_legend_box(ctx, '%s (max: %u MiB)' % (volume, volume_scale / 1024 / 1024),
+                                       VOLUME_COLORS[i % len(VOLUME_COLORS)],
+                                       off_x + i * 250, curr_y+20, leg_s)
+                       disk_scale += volume_scale
+
+               # render used amount of disk space
+               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)
+                       for i in range(len(volumes), 0, -1):
+                               draw_chart (ctx, VOLUME_COLORS[(i - 1) % len(VOLUME_COLORS)], True, chart_rect, \
+                                           [(sample.time,
+                                             # Sum up used space of all volumes including the current one
+                                             # so that the graphs appear as stacked on top of each other.
+                                             reduce(lambda x,y: x+y,
+                                                    [sample.records[volume] - min_used[volume]
+                                                     for volume in volumes[0:i]
+                                                     if volume in sample.records],
+                                                    0))
+                                            for sample in trace.monitor_disk], \
+                                           proc_tree, [0, disk_scale])
+
+               curr_y = curr_y + 30 + bar_h
+
        # render mem usage
        chart_rect = (off_x, curr_y+30, w, meminfo_bar_h)
        mem_stats = trace.mem_stats
index 48eb048dae1a894e6c2b257e084dfcd07de51231..301145ab6745ba5cd5c49f3247962ab7b5c358f5 100644 (file)
@@ -48,6 +48,7 @@ class Trace:
         self.filename = None
         self.parent_map = None
         self.mem_stats = []
+        self.monitor_disk = None
         self.times = [] # Always empty, but expected by draw.py when drawing system charts.
 
         if len(paths):
@@ -506,6 +507,29 @@ def _parse_proc_meminfo_log(file):
 
     return mem_stats
 
+def _parse_monitor_disk_log(file):
+    """
+    Parse file with information about amount of diskspace used.
+    The format of relevant lines should be: ^volume path: number-of-bytes?
+    """
+    disk_stats = []
+    diskinfo_re = re.compile(r'^(.+):\s*(\d+)$')
+
+    for time, lines in _parse_timed_blocks(file):
+        sample = DiskSpaceSample(time)
+
+        for line in lines:
+            match = diskinfo_re.match(line)
+            if not match:
+                raise ParseError("Invalid monitor_disk line \"%s\"" % line)
+            sample.add_value(match.group(1), int(match.group(2)))
+
+        if sample.valid():
+            disk_stats.append(sample)
+
+    return disk_stats
+
+
 # if we boot the kernel with: initcall_debug printk.time=1 we can
 # get all manner of interesting data from the dmesg output
 # We turn this into a pseudo-process tree: each event is
@@ -684,6 +708,8 @@ def _do_parse(writer, state, filename, file):
         state.mem_stats = _parse_proc_meminfo_log(file)
     elif name == "cmdline2.log":
         state.cmdline = _parse_cmdline_log(writer, file)
+    elif name == "monitor_disk.log":
+        state.monitor_disk = _parse_monitor_disk_log(file)
     elif not filename.endswith('.log'):
         _parse_bitbake_buildstats(writer, state, filename, file)
     t2 = clock()
index 015d743aa0da448c5dcb5604aa896a717c930b6a..bedca4165a293e2cb58db24efb024f64145af373 100644 (file)
@@ -53,6 +53,17 @@ class MemSample:
         # discard incomplete samples
         return [v for v in MemSample.used_values if v not in keys] == []
 
+class DiskSpaceSample:
+    def __init__(self, time):
+        self.time = time
+        self.records = {}
+
+    def add_value(self, name, value):
+        self.records[name] = value
+
+    def valid(self):
+        return bool(self.records)
+
 class ProcessSample:
     def __init__(self, time, state, cpu_sample):
         self.time = time