summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArmin Kuster <akuster808@gmail.com>2019-05-03 18:26:54 -0700
committerArmin Kuster <akuster808@gmail.com>2019-05-03 18:33:28 -0700
commit775f0e04e31a2a9501b035611281cd31a3aad4b9 (patch)
tree4d48a8d13b4e41a12ec662d5af0c8a7957299d47
parent550f713252a32ecfdc81c9407b1ed6630a5c4fd0 (diff)
downloadopenembedded-core-contrib-775f0e04e31a2a9501b035611281cd31a3aad4b9.tar.gz
pybootchart: fix indentations
used https://raw.githubusercontent.com/python/cpython/master/Tools/scripts/reindent.py Signed-off-by: Armin Kuster <akuster808@gmail.com>
-rwxr-xr-xscripts/pybootchartgui/pybootchartgui.py2
-rw-r--r--scripts/pybootchartgui/pybootchartgui/batch.py1
-rw-r--r--scripts/pybootchartgui/pybootchartgui/draw.py1388
-rw-r--r--scripts/pybootchartgui/pybootchartgui/main.py.in288
-rw-r--r--scripts/pybootchartgui/pybootchartgui/tests/parser_test.py165
5 files changed, 921 insertions, 923 deletions
diff --git a/scripts/pybootchartgui/pybootchartgui.py b/scripts/pybootchartgui/pybootchartgui.py
index 7ce1a5be40..6c5951362e 100755
--- a/scripts/pybootchartgui/pybootchartgui.py
+++ b/scripts/pybootchartgui/pybootchartgui.py
@@ -20,4 +20,4 @@ import sys
from pybootchartgui.main import main
if __name__ == '__main__':
- sys.exit(main())
+ sys.exit(main())
diff --git a/scripts/pybootchartgui/pybootchartgui/batch.py b/scripts/pybootchartgui/pybootchartgui/batch.py
index 05c714e95e..cb52136e9f 100644
--- a/scripts/pybootchartgui/pybootchartgui/batch.py
+++ b/scripts/pybootchartgui/pybootchartgui/batch.py
@@ -43,4 +43,3 @@ def render(writer, trace, app_options, filename):
draw.render (ctx, options, 1.0, trace)
write_surface (surface)
writer.status ("bootchart written to '%s'" % filename)
-
diff --git a/scripts/pybootchartgui/pybootchartgui/draw.py b/scripts/pybootchartgui/pybootchartgui/draw.py
index b21690d61d..4c2e4cf44e 100644
--- a/scripts/pybootchartgui/pybootchartgui/draw.py
+++ b/scripts/pybootchartgui/pybootchartgui/draw.py
@@ -23,18 +23,18 @@ from operator import itemgetter
class RenderOptions:
- def __init__(self, app_options):
- # should we render a cumulative CPU time chart
- self.cumulative = True
- self.charts = True
- self.kernel_only = False
- self.app_options = app_options
-
- def proc_tree (self, trace):
- if self.kernel_only:
- return trace.kernel_tree
- else:
- return trace.proc_tree
+ def __init__(self, app_options):
+ # should we render a cumulative CPU time chart
+ self.cumulative = True
+ self.charts = True
+ self.kernel_only = False
+ self.app_options = app_options
+
+ def proc_tree (self, trace):
+ if self.kernel_only:
+ return trace.kernel_tree
+ else:
+ return trace.proc_tree
# Process tree background color.
BACK_COLOR = (1.0, 1.0, 1.0, 1.0)
@@ -136,11 +136,11 @@ 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),
+ (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
@@ -152,7 +152,7 @@ STATE_STOPPED = 4
STATE_ZOMBIE = 5
STATE_COLORS = [(0, 0, 0, 0), PROC_COLOR_R, PROC_COLOR_S, PROC_COLOR_D, \
- PROC_COLOR_T, PROC_COLOR_Z, PROC_COLOR_X, PROC_COLOR_W]
+ PROC_COLOR_T, PROC_COLOR_Z, PROC_COLOR_X, PROC_COLOR_W]
# CumulativeStats Types
STAT_TYPE_CPU = 0
@@ -160,80 +160,80 @@ STAT_TYPE_IO = 1
# Convert ps process state to an int
def get_proc_state(flag):
- return "RSDTZXW".find(flag) + 1
+ return "RSDTZXW".find(flag) + 1
def draw_text(ctx, text, color, x, y):
- ctx.set_source_rgba(*color)
- ctx.move_to(x, y)
- ctx.show_text(text)
+ ctx.set_source_rgba(*color)
+ ctx.move_to(x, y)
+ ctx.show_text(text)
def draw_fill_rect(ctx, color, rect):
- ctx.set_source_rgba(*color)
- ctx.rectangle(*rect)
- ctx.fill()
+ ctx.set_source_rgba(*color)
+ ctx.rectangle(*rect)
+ ctx.fill()
def draw_rect(ctx, color, rect):
- ctx.set_source_rgba(*color)
- ctx.rectangle(*rect)
- ctx.stroke()
+ ctx.set_source_rgba(*color)
+ ctx.rectangle(*rect)
+ ctx.stroke()
def draw_legend_box(ctx, label, fill_color, x, y, s):
- draw_fill_rect(ctx, fill_color, (x, y - s, s, s))
- draw_rect(ctx, PROC_BORDER_COLOR, (x, y - s, s, s))
- draw_text(ctx, label, TEXT_COLOR, x + s + 5, y)
+ draw_fill_rect(ctx, fill_color, (x, y - s, s, s))
+ draw_rect(ctx, PROC_BORDER_COLOR, (x, y - s, s, s))
+ draw_text(ctx, label, TEXT_COLOR, x + s + 5, y)
def draw_legend_line(ctx, label, fill_color, x, y, s):
- draw_fill_rect(ctx, fill_color, (x, y - s/2, s + 1, 3))
- ctx.arc(x + (s + 1)/2.0, y - (s - 3)/2.0, 2.5, 0, 2.0 * math.pi)
- ctx.fill()
- draw_text(ctx, label, TEXT_COLOR, x + s + 5, y)
+ draw_fill_rect(ctx, fill_color, (x, y - s/2, s + 1, 3))
+ ctx.arc(x + (s + 1)/2.0, y - (s - 3)/2.0, 2.5, 0, 2.0 * math.pi)
+ ctx.fill()
+ draw_text(ctx, label, TEXT_COLOR, x + s + 5, y)
def draw_label_in_box(ctx, color, label, x, y, w, maxx):
- label_w = ctx.text_extents(label)[2]
- label_x = x + w / 2 - label_w / 2
- if label_w + 10 > w:
- label_x = x + w + 5
- if label_x + label_w > maxx:
- label_x = x - label_w - 5
- draw_text(ctx, label, color, label_x, y)
+ label_w = ctx.text_extents(label)[2]
+ label_x = x + w / 2 - label_w / 2
+ if label_w + 10 > w:
+ label_x = x + w + 5
+ if label_x + label_w > maxx:
+ label_x = x - label_w - 5
+ draw_text(ctx, label, color, label_x, y)
def draw_sec_labels(ctx, options, rect, sec_w, nsecs):
- ctx.set_font_size(AXIS_FONT_SIZE)
- prev_x = 0
- for i in range(0, rect[2] + 1, sec_w):
- if ((i / sec_w) % nsecs == 0) :
- if options.app_options.as_minutes :
- label = "%.1f" % (i / sec_w / 60.0)
- else :
- label = "%d" % (i / sec_w)
- label_w = ctx.text_extents(label)[2]
- x = rect[0] + i - label_w/2
- if x >= prev_x:
- draw_text(ctx, label, TEXT_COLOR, x, rect[1] - 2)
- prev_x = x + label_w
+ ctx.set_font_size(AXIS_FONT_SIZE)
+ prev_x = 0
+ for i in range(0, rect[2] + 1, sec_w):
+ if ((i / sec_w) % nsecs == 0) :
+ if options.app_options.as_minutes :
+ label = "%.1f" % (i / sec_w / 60.0)
+ else :
+ label = "%d" % (i / sec_w)
+ label_w = ctx.text_extents(label)[2]
+ x = rect[0] + i - label_w/2
+ if x >= prev_x:
+ draw_text(ctx, label, TEXT_COLOR, x, rect[1] - 2)
+ prev_x = x + label_w
def draw_box_ticks(ctx, rect, sec_w):
- draw_rect(ctx, BORDER_COLOR, tuple(rect))
-
- ctx.set_line_cap(cairo.LINE_CAP_SQUARE)
-
- for i in range(sec_w, rect[2] + 1, sec_w):
- if ((i / sec_w) % 10 == 0) :
- ctx.set_line_width(1.5)
- elif sec_w < 5 :
- continue
- else :
- ctx.set_line_width(1.0)
- if ((i / sec_w) % 30 == 0) :
- ctx.set_source_rgba(*TICK_COLOR_BOLD)
- else :
- ctx.set_source_rgba(*TICK_COLOR)
- ctx.move_to(rect[0] + i, rect[1] + 1)
- ctx.line_to(rect[0] + i, rect[1] + rect[3] - 1)
- ctx.stroke()
- ctx.set_line_width(1.0)
-
- ctx.set_line_cap(cairo.LINE_CAP_BUTT)
+ draw_rect(ctx, BORDER_COLOR, tuple(rect))
+
+ ctx.set_line_cap(cairo.LINE_CAP_SQUARE)
+
+ for i in range(sec_w, rect[2] + 1, sec_w):
+ if ((i / sec_w) % 10 == 0) :
+ ctx.set_line_width(1.5)
+ elif sec_w < 5 :
+ continue
+ else :
+ ctx.set_line_width(1.0)
+ if ((i / sec_w) % 30 == 0) :
+ ctx.set_source_rgba(*TICK_COLOR_BOLD)
+ else :
+ ctx.set_source_rgba(*TICK_COLOR)
+ ctx.move_to(rect[0] + i, rect[1] + 1)
+ ctx.line_to(rect[0] + i, rect[1] + rect[3] - 1)
+ ctx.stroke()
+ ctx.set_line_width(1.0)
+
+ ctx.set_line_cap(cairo.LINE_CAP_BUTT)
def draw_annotations(ctx, proc_tree, times, rect):
ctx.set_line_cap(cairo.LINE_CAP_SQUARE)
@@ -252,51 +252,51 @@ def draw_annotations(ctx, proc_tree, times, rect):
ctx.set_dash([])
def draw_chart(ctx, color, fill, chart_bounds, data, proc_tree, data_range):
- ctx.set_line_width(0.5)
- x_shift = proc_tree.start_time
-
- def transform_point_coords(point, x_base, y_base, \
- xscale, yscale, x_trans, y_trans):
- x = (point[0] - x_base) * xscale + x_trans
- y = (point[1] - y_base) * -yscale + y_trans + chart_bounds[3]
- return x, y
-
- max_x = max (x for (x, y) in data)
- max_y = max (y for (x, y) in data)
- # avoid divide by zero
- if max_y == 0:
- max_y = 1.0
- xscale = float (chart_bounds[2]) / (max_x - x_shift)
- # If data_range is given, scale the chart so that the value range in
- # data_range matches the chart bounds exactly.
- # Otherwise, scale so that the actual data matches the chart bounds.
- if data_range:
- yscale = float(chart_bounds[3]) / (data_range[1] - data_range[0])
- ybase = data_range[0]
- else:
- yscale = float(chart_bounds[3]) / max_y
- ybase = 0
-
- first = transform_point_coords (data[0], x_shift, ybase, xscale, yscale, \
- chart_bounds[0], chart_bounds[1])
- last = transform_point_coords (data[-1], x_shift, ybase, xscale, yscale, \
- chart_bounds[0], chart_bounds[1])
-
- ctx.set_source_rgba(*color)
- ctx.move_to(*first)
- for point in data:
- x, y = transform_point_coords (point, x_shift, ybase, xscale, yscale, \
- chart_bounds[0], chart_bounds[1])
- ctx.line_to(x, y)
- if fill:
- ctx.stroke_preserve()
- ctx.line_to(last[0], chart_bounds[1]+chart_bounds[3])
- ctx.line_to(first[0], chart_bounds[1]+chart_bounds[3])
- ctx.line_to(first[0], first[1])
- ctx.fill()
- else:
- ctx.stroke()
- ctx.set_line_width(1.0)
+ ctx.set_line_width(0.5)
+ x_shift = proc_tree.start_time
+
+ def transform_point_coords(point, x_base, y_base, \
+ xscale, yscale, x_trans, y_trans):
+ x = (point[0] - x_base) * xscale + x_trans
+ y = (point[1] - y_base) * -yscale + y_trans + chart_bounds[3]
+ return x, y
+
+ max_x = max (x for (x, y) in data)
+ max_y = max (y for (x, y) in data)
+ # avoid divide by zero
+ if max_y == 0:
+ max_y = 1.0
+ xscale = float (chart_bounds[2]) / (max_x - x_shift)
+ # If data_range is given, scale the chart so that the value range in
+ # data_range matches the chart bounds exactly.
+ # Otherwise, scale so that the actual data matches the chart bounds.
+ if data_range:
+ yscale = float(chart_bounds[3]) / (data_range[1] - data_range[0])
+ ybase = data_range[0]
+ else:
+ yscale = float(chart_bounds[3]) / max_y
+ ybase = 0
+
+ first = transform_point_coords (data[0], x_shift, ybase, xscale, yscale, \
+ chart_bounds[0], chart_bounds[1])
+ last = transform_point_coords (data[-1], x_shift, ybase, xscale, yscale, \
+ chart_bounds[0], chart_bounds[1])
+
+ ctx.set_source_rgba(*color)
+ ctx.move_to(*first)
+ for point in data:
+ x, y = transform_point_coords (point, x_shift, ybase, xscale, yscale, \
+ chart_bounds[0], chart_bounds[1])
+ ctx.line_to(x, y)
+ if fill:
+ ctx.stroke_preserve()
+ ctx.line_to(last[0], chart_bounds[1]+chart_bounds[3])
+ ctx.line_to(first[0], chart_bounds[1]+chart_bounds[3])
+ ctx.line_to(first[0], first[1])
+ ctx.fill()
+ else:
+ ctx.stroke()
+ ctx.set_line_width(1.0)
bar_h = 55
meminfo_bar_h = 2 * bar_h
@@ -311,338 +311,338 @@ CUML_HEIGHT = 2000 # Increased value to accomodate CPU and I/O Graphs
OPTIONS = None
def extents(options, xscale, trace):
- start = min(trace.start.keys())
- end = start
-
- processes = 0
- for proc in trace.processes:
- if not options.app_options.show_all and \
- trace.processes[proc][1] - trace.processes[proc][0] < options.app_options.mintime:
- continue
-
- if trace.processes[proc][1] > end:
- end = trace.processes[proc][1]
- processes += 1
-
- if trace.min is not None and trace.max is not None:
- start = trace.min
- end = trace.max
-
- w = int ((end - start) * sec_w_base * xscale) + 2 * off_x
- h = proc_h * processes + header_h + 2 * off_y
-
- if options.charts:
- if trace.cpu_stats:
- h += 30 + bar_h
- if trace.disk_stats:
- h += 30 + bar_h
- if trace.monitor_disk:
- h += 30 + bar_h
- if trace.mem_stats:
- h += meminfo_bar_h
-
- return (w, h)
+ start = min(trace.start.keys())
+ end = start
+
+ processes = 0
+ for proc in trace.processes:
+ if not options.app_options.show_all and \
+ trace.processes[proc][1] - trace.processes[proc][0] < options.app_options.mintime:
+ continue
+
+ if trace.processes[proc][1] > end:
+ end = trace.processes[proc][1]
+ processes += 1
+
+ if trace.min is not None and trace.max is not None:
+ start = trace.min
+ end = trace.max
+
+ w = int ((end - start) * sec_w_base * xscale) + 2 * off_x
+ h = proc_h * processes + header_h + 2 * off_y
+
+ if options.charts:
+ if trace.cpu_stats:
+ h += 30 + bar_h
+ if trace.disk_stats:
+ h += 30 + bar_h
+ if trace.monitor_disk:
+ h += 30 + bar_h
+ if trace.mem_stats:
+ h += meminfo_bar_h
+
+ return (w, h)
def clip_visible(clip, rect):
- xmax = max (clip[0], rect[0])
- ymax = max (clip[1], rect[1])
- xmin = min (clip[0] + clip[2], rect[0] + rect[2])
- ymin = min (clip[1] + clip[3], rect[1] + rect[3])
- return (xmin > xmax and ymin > ymax)
+ xmax = max (clip[0], rect[0])
+ ymax = max (clip[1], rect[1])
+ xmin = min (clip[0] + clip[2], rect[0] + rect[2])
+ ymin = min (clip[1] + clip[3], rect[1] + rect[3])
+ return (xmin > xmax and ymin > ymax)
def render_charts(ctx, options, clip, trace, curr_y, w, h, sec_w):
- proc_tree = options.proc_tree(trace)
-
- # render bar legend
- if trace.cpu_stats:
- ctx.set_font_size(LEGEND_FONT_SIZE)
-
- draw_legend_box(ctx, "CPU (user+sys)", CPU_COLOR, off_x, curr_y+20, leg_s)
- draw_legend_box(ctx, "I/O (wait)", IO_COLOR, off_x + 120, curr_y+20, leg_s)
-
- # render I/O wait
- 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, IO_COLOR, True, chart_rect, \
- [(sample.time, sample.user + sample.sys + sample.io) for sample in trace.cpu_stats], \
- proc_tree, None)
- # render CPU load
- draw_chart (ctx, CPU_COLOR, True, chart_rect, \
- [(sample.time, sample.user + sample.sys) for sample in trace.cpu_stats], \
- proc_tree, None)
-
- curr_y = curr_y + 30 + bar_h
-
- # render second chart
- if trace.disk_stats:
- draw_legend_line(ctx, "Disk throughput", DISK_TPUT_COLOR, off_x, curr_y+20, leg_s)
- draw_legend_box(ctx, "Disk utilization", IO_COLOR, off_x + 120, curr_y+20, leg_s)
-
- # render I/O utilization
- 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, IO_COLOR, True, chart_rect, \
- [(sample.time, sample.util) for sample in trace.disk_stats], \
- proc_tree, None)
-
- # render disk throughput
- max_sample = max (trace.disk_stats, key = lambda s: s.tput)
- if clip_visible (clip, chart_rect):
- draw_chart (ctx, DISK_TPUT_COLOR, False, chart_rect, \
- [(sample.time, sample.tput) for sample in trace.disk_stats], \
- 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 = "%dMB/s" % round ((max_sample.tput) / 1024.0)
- draw_text (ctx, label, DISK_TPUT_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
- # 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
- if mem_stats and clip_visible (clip, chart_rect):
- 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.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.buffers) for sample in trace.mem_stats], \
- proc_tree, [0, mem_scale])
- draw_chart(ctx, MEM_USED_COLOR, True, chart_rect, \
- [(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.cached) for sample in mem_stats], \
- proc_tree, [0, mem_scale])
- draw_chart(ctx, MEM_SWAP_COLOR, False, chart_rect, \
- [(sample.time, float(sample.swap)) for sample in mem_stats], \
- proc_tree, None)
-
- curr_y = curr_y + meminfo_bar_h
-
- return curr_y
+ proc_tree = options.proc_tree(trace)
+
+ # render bar legend
+ if trace.cpu_stats:
+ ctx.set_font_size(LEGEND_FONT_SIZE)
+
+ draw_legend_box(ctx, "CPU (user+sys)", CPU_COLOR, off_x, curr_y+20, leg_s)
+ draw_legend_box(ctx, "I/O (wait)", IO_COLOR, off_x + 120, curr_y+20, leg_s)
+
+ # render I/O wait
+ 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, IO_COLOR, True, chart_rect, \
+ [(sample.time, sample.user + sample.sys + sample.io) for sample in trace.cpu_stats], \
+ proc_tree, None)
+ # render CPU load
+ draw_chart (ctx, CPU_COLOR, True, chart_rect, \
+ [(sample.time, sample.user + sample.sys) for sample in trace.cpu_stats], \
+ proc_tree, None)
+
+ curr_y = curr_y + 30 + bar_h
+
+ # render second chart
+ if trace.disk_stats:
+ draw_legend_line(ctx, "Disk throughput", DISK_TPUT_COLOR, off_x, curr_y+20, leg_s)
+ draw_legend_box(ctx, "Disk utilization", IO_COLOR, off_x + 120, curr_y+20, leg_s)
+
+ # render I/O utilization
+ 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, IO_COLOR, True, chart_rect, \
+ [(sample.time, sample.util) for sample in trace.disk_stats], \
+ proc_tree, None)
+
+ # render disk throughput
+ max_sample = max (trace.disk_stats, key = lambda s: s.tput)
+ if clip_visible (clip, chart_rect):
+ draw_chart (ctx, DISK_TPUT_COLOR, False, chart_rect, \
+ [(sample.time, sample.tput) for sample in trace.disk_stats], \
+ 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 = "%dMB/s" % round ((max_sample.tput) / 1024.0)
+ draw_text (ctx, label, DISK_TPUT_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
+ # 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
+ if mem_stats and clip_visible (clip, chart_rect):
+ 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.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.buffers) for sample in trace.mem_stats], \
+ proc_tree, [0, mem_scale])
+ draw_chart(ctx, MEM_USED_COLOR, True, chart_rect, \
+ [(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.cached) for sample in mem_stats], \
+ proc_tree, [0, mem_scale])
+ draw_chart(ctx, MEM_SWAP_COLOR, False, chart_rect, \
+ [(sample.time, float(sample.swap)) for sample in mem_stats], \
+ proc_tree, None)
+
+ curr_y = curr_y + meminfo_bar_h
+
+ return curr_y
def render_processes_chart(ctx, options, trace, curr_y, w, h, sec_w):
- chart_rect = [off_x, curr_y+header_h, w, h - 2 * off_y - header_h - leg_s + proc_h]
-
- draw_legend_box (ctx, "Configure", \
- TASK_COLOR_CONFIGURE, off_x , curr_y + 45, leg_s)
- draw_legend_box (ctx, "Compile", \
- TASK_COLOR_COMPILE, off_x+120, curr_y + 45, leg_s)
- draw_legend_box (ctx, "Install", \
- TASK_COLOR_INSTALL, off_x+240, curr_y + 45, leg_s)
- draw_legend_box (ctx, "Populate Sysroot", \
- TASK_COLOR_SYSROOT, off_x+360, curr_y + 45, leg_s)
- draw_legend_box (ctx, "Package", \
- TASK_COLOR_PACKAGE, off_x+480, curr_y + 45, leg_s)
- draw_legend_box (ctx, "Package Write",
- TASK_COLOR_PACKAGE_WRITE, off_x+600, curr_y + 45, leg_s)
-
- ctx.set_font_size(PROC_TEXT_FONT_SIZE)
-
- draw_box_ticks(ctx, chart_rect, sec_w)
- draw_sec_labels(ctx, options, chart_rect, sec_w, 30)
-
- y = curr_y+header_h
-
- offset = trace.min or min(trace.start.keys())
- for s in sorted(trace.start.keys()):
- for val in sorted(trace.start[s]):
- if not options.app_options.show_all and \
- trace.processes[val][1] - s < options.app_options.mintime:
- continue
- task = val.split(":")[1]
- #print val
- #print trace.processes[val][1]
- #print s
- x = chart_rect[0] + (s - offset) * sec_w
- w = ((trace.processes[val][1] - s) * sec_w)
-
- #print "proc at %s %s %s %s" % (x, y, w, proc_h)
- col = None
- if task == "do_compile":
- col = TASK_COLOR_COMPILE
- elif task == "do_configure":
- col = TASK_COLOR_CONFIGURE
- elif task == "do_install":
- col = TASK_COLOR_INSTALL
- elif task == "do_populate_sysroot":
- col = TASK_COLOR_SYSROOT
- elif task == "do_package":
- col = TASK_COLOR_PACKAGE
- elif task == "do_package_write_rpm" or \
- task == "do_package_write_deb" or \
- task == "do_package_write_ipk":
- col = TASK_COLOR_PACKAGE_WRITE
- else:
- col = WHITE
-
- if col:
- draw_fill_rect(ctx, col, (x, y, w, proc_h))
- draw_rect(ctx, PROC_BORDER_COLOR, (x, y, w, proc_h))
-
- draw_label_in_box(ctx, PROC_TEXT_COLOR, val, x, y + proc_h - 4, w, proc_h)
- y = y + proc_h
-
- return curr_y
+ chart_rect = [off_x, curr_y+header_h, w, h - 2 * off_y - header_h - leg_s + proc_h]
+
+ draw_legend_box (ctx, "Configure", \
+ TASK_COLOR_CONFIGURE, off_x , curr_y + 45, leg_s)
+ draw_legend_box (ctx, "Compile", \
+ TASK_COLOR_COMPILE, off_x+120, curr_y + 45, leg_s)
+ draw_legend_box (ctx, "Install", \
+ TASK_COLOR_INSTALL, off_x+240, curr_y + 45, leg_s)
+ draw_legend_box (ctx, "Populate Sysroot", \
+ TASK_COLOR_SYSROOT, off_x+360, curr_y + 45, leg_s)
+ draw_legend_box (ctx, "Package", \
+ TASK_COLOR_PACKAGE, off_x+480, curr_y + 45, leg_s)
+ draw_legend_box (ctx, "Package Write",
+ TASK_COLOR_PACKAGE_WRITE, off_x+600, curr_y + 45, leg_s)
+
+ ctx.set_font_size(PROC_TEXT_FONT_SIZE)
+
+ draw_box_ticks(ctx, chart_rect, sec_w)
+ draw_sec_labels(ctx, options, chart_rect, sec_w, 30)
+
+ y = curr_y+header_h
+
+ offset = trace.min or min(trace.start.keys())
+ for s in sorted(trace.start.keys()):
+ for val in sorted(trace.start[s]):
+ if not options.app_options.show_all and \
+ trace.processes[val][1] - s < options.app_options.mintime:
+ continue
+ task = val.split(":")[1]
+ #print val
+ #print trace.processes[val][1]
+ #print s
+ x = chart_rect[0] + (s - offset) * sec_w
+ w = ((trace.processes[val][1] - s) * sec_w)
+
+ #print "proc at %s %s %s %s" % (x, y, w, proc_h)
+ col = None
+ if task == "do_compile":
+ col = TASK_COLOR_COMPILE
+ elif task == "do_configure":
+ col = TASK_COLOR_CONFIGURE
+ elif task == "do_install":
+ col = TASK_COLOR_INSTALL
+ elif task == "do_populate_sysroot":
+ col = TASK_COLOR_SYSROOT
+ elif task == "do_package":
+ col = TASK_COLOR_PACKAGE
+ elif task == "do_package_write_rpm" or \
+ task == "do_package_write_deb" or \
+ task == "do_package_write_ipk":
+ col = TASK_COLOR_PACKAGE_WRITE
+ else:
+ col = WHITE
+
+ if col:
+ draw_fill_rect(ctx, col, (x, y, w, proc_h))
+ draw_rect(ctx, PROC_BORDER_COLOR, (x, y, w, proc_h))
+
+ draw_label_in_box(ctx, PROC_TEXT_COLOR, val, x, y + proc_h - 4, w, proc_h)
+ y = y + proc_h
+
+ return curr_y
#
# Render the chart.
#
def render(ctx, options, xscale, trace):
- (w, h) = extents (options, xscale, trace)
- global OPTIONS
- OPTIONS = options.app_options
+ (w, h) = extents (options, xscale, trace)
+ global OPTIONS
+ OPTIONS = options.app_options
- # x, y, w, h
- clip = ctx.clip_extents()
+ # x, y, w, h
+ clip = ctx.clip_extents()
- sec_w = int (xscale * sec_w_base)
- ctx.set_line_width(1.0)
- ctx.select_font_face(FONT_NAME)
- draw_fill_rect(ctx, WHITE, (0, 0, max(w, MIN_IMG_W), h))
- w -= 2*off_x
- curr_y = off_y;
+ sec_w = int (xscale * sec_w_base)
+ ctx.set_line_width(1.0)
+ ctx.select_font_face(FONT_NAME)
+ draw_fill_rect(ctx, WHITE, (0, 0, max(w, MIN_IMG_W), h))
+ w -= 2*off_x
+ curr_y = off_y;
- if options.charts:
- curr_y = render_charts (ctx, options, clip, trace, curr_y, w, h, sec_w)
+ if options.charts:
+ curr_y = render_charts (ctx, options, clip, trace, curr_y, w, h, sec_w)
- curr_y = render_processes_chart (ctx, options, trace, curr_y, w, h, sec_w)
+ curr_y = render_processes_chart (ctx, options, trace, curr_y, w, h, sec_w)
- return
+ return
- proc_tree = options.proc_tree (trace)
+ proc_tree = options.proc_tree (trace)
- # draw the title and headers
- if proc_tree.idle:
- duration = proc_tree.idle
- else:
- duration = proc_tree.duration
+ # draw the title and headers
+ if proc_tree.idle:
+ duration = proc_tree.idle
+ else:
+ duration = proc_tree.duration
- if not options.kernel_only:
- curr_y = draw_header (ctx, trace.headers, duration)
- else:
- curr_y = off_y;
+ if not options.kernel_only:
+ curr_y = draw_header (ctx, trace.headers, duration)
+ else:
+ curr_y = off_y;
- # draw process boxes
- proc_height = h
- if proc_tree.taskstats and options.cumulative:
- proc_height -= CUML_HEIGHT
+ # draw process boxes
+ proc_height = h
+ if proc_tree.taskstats and options.cumulative:
+ proc_height -= CUML_HEIGHT
- draw_process_bar_chart(ctx, clip, options, proc_tree, trace.times,
- curr_y, w, proc_height, sec_w)
+ draw_process_bar_chart(ctx, clip, options, proc_tree, trace.times,
+ curr_y, w, proc_height, sec_w)
- curr_y = proc_height
- ctx.set_font_size(SIG_FONT_SIZE)
- draw_text(ctx, SIGNATURE, SIG_COLOR, off_x + 5, proc_height - 8)
+ curr_y = proc_height
+ ctx.set_font_size(SIG_FONT_SIZE)
+ draw_text(ctx, SIGNATURE, SIG_COLOR, off_x + 5, proc_height - 8)
- # draw a cumulative CPU-time-per-process graph
- if proc_tree.taskstats and options.cumulative:
- cuml_rect = (off_x, curr_y + off_y, w, CUML_HEIGHT/2 - off_y * 2)
- if clip_visible (clip, cuml_rect):
- draw_cuml_graph(ctx, proc_tree, cuml_rect, duration, sec_w, STAT_TYPE_CPU)
+ # draw a cumulative CPU-time-per-process graph
+ if proc_tree.taskstats and options.cumulative:
+ cuml_rect = (off_x, curr_y + off_y, w, CUML_HEIGHT/2 - off_y * 2)
+ if clip_visible (clip, cuml_rect):
+ draw_cuml_graph(ctx, proc_tree, cuml_rect, duration, sec_w, STAT_TYPE_CPU)
- # draw a cumulative I/O-time-per-process graph
- if proc_tree.taskstats and options.cumulative:
- cuml_rect = (off_x, curr_y + off_y * 100, w, CUML_HEIGHT/2 - off_y * 2)
- if clip_visible (clip, cuml_rect):
- draw_cuml_graph(ctx, proc_tree, cuml_rect, duration, sec_w, STAT_TYPE_IO)
+ # draw a cumulative I/O-time-per-process graph
+ if proc_tree.taskstats and options.cumulative:
+ cuml_rect = (off_x, curr_y + off_y * 100, w, CUML_HEIGHT/2 - off_y * 2)
+ if clip_visible (clip, cuml_rect):
+ draw_cuml_graph(ctx, proc_tree, cuml_rect, duration, sec_w, STAT_TYPE_IO)
def draw_process_bar_chart(ctx, clip, options, proc_tree, times, curr_y, w, h, sec_w):
- header_size = 0
- if not options.kernel_only:
- draw_legend_box (ctx, "Running (%cpu)",
- PROC_COLOR_R, off_x , curr_y + 45, leg_s)
- draw_legend_box (ctx, "Unint.sleep (I/O)",
- PROC_COLOR_D, off_x+120, curr_y + 45, leg_s)
- draw_legend_box (ctx, "Sleeping",
- PROC_COLOR_S, off_x+240, curr_y + 45, leg_s)
- draw_legend_box (ctx, "Zombie",
- PROC_COLOR_Z, off_x+360, curr_y + 45, leg_s)
- header_size = 45
-
- chart_rect = [off_x, curr_y + header_size + 15,
- w, h - 2 * off_y - (curr_y + header_size + 15) + proc_h]
- ctx.set_font_size (PROC_TEXT_FONT_SIZE)
-
- draw_box_ticks (ctx, chart_rect, sec_w)
- if sec_w > 100:
- nsec = 1
- else:
- nsec = 5
- draw_sec_labels (ctx, options, chart_rect, sec_w, nsec)
- draw_annotations (ctx, proc_tree, times, chart_rect)
-
- y = curr_y + 60
- for root in proc_tree.process_tree:
- draw_processes_recursively(ctx, root, proc_tree, y, proc_h, chart_rect, clip)
- y = y + proc_h * proc_tree.num_nodes([root])
+ header_size = 0
+ if not options.kernel_only:
+ draw_legend_box (ctx, "Running (%cpu)",
+ PROC_COLOR_R, off_x , curr_y + 45, leg_s)
+ draw_legend_box (ctx, "Unint.sleep (I/O)",
+ PROC_COLOR_D, off_x+120, curr_y + 45, leg_s)
+ draw_legend_box (ctx, "Sleeping",
+ PROC_COLOR_S, off_x+240, curr_y + 45, leg_s)
+ draw_legend_box (ctx, "Zombie",
+ PROC_COLOR_Z, off_x+360, curr_y + 45, leg_s)
+ header_size = 45
+
+ chart_rect = [off_x, curr_y + header_size + 15,
+ w, h - 2 * off_y - (curr_y + header_size + 15) + proc_h]
+ ctx.set_font_size (PROC_TEXT_FONT_SIZE)
+
+ draw_box_ticks (ctx, chart_rect, sec_w)
+ if sec_w > 100:
+ nsec = 1
+ else:
+ nsec = 5
+ draw_sec_labels (ctx, options, chart_rect, sec_w, nsec)
+ draw_annotations (ctx, proc_tree, times, chart_rect)
+
+ y = curr_y + 60
+ for root in proc_tree.process_tree:
+ draw_processes_recursively(ctx, root, proc_tree, y, proc_h, chart_rect, clip)
+ y = y + proc_h * proc_tree.num_nodes([root])
def draw_header (ctx, headers, duration):
@@ -678,291 +678,291 @@ def draw_header (ctx, headers, duration):
return header_y
def draw_processes_recursively(ctx, proc, proc_tree, y, proc_h, rect, clip) :
- x = rect[0] + ((proc.start_time - proc_tree.start_time) * rect[2] / proc_tree.duration)
- w = ((proc.duration) * rect[2] / proc_tree.duration)
-
- draw_process_activity_colors(ctx, proc, proc_tree, x, y, w, proc_h, rect, clip)
- draw_rect(ctx, PROC_BORDER_COLOR, (x, y, w, proc_h))
- ipid = int(proc.pid)
- if not OPTIONS.show_all:
- cmdString = proc.cmd
- else:
- cmdString = ''
- if (OPTIONS.show_pid or OPTIONS.show_all) and ipid is not 0:
- cmdString = cmdString + " [" + str(ipid // 1000) + "]"
- if OPTIONS.show_all:
- if proc.args:
- cmdString = cmdString + " '" + "' '".join(proc.args) + "'"
- else:
- cmdString = cmdString + " " + proc.exe
-
- draw_label_in_box(ctx, PROC_TEXT_COLOR, cmdString, x, y + proc_h - 4, w, rect[0] + rect[2])
-
- next_y = y + proc_h
- for child in proc.child_list:
- if next_y > clip[1] + clip[3]:
- break
- child_x, child_y = draw_processes_recursively(ctx, child, proc_tree, next_y, proc_h, rect, clip)
- draw_process_connecting_lines(ctx, x, y, child_x, child_y, proc_h)
- next_y = next_y + proc_h * proc_tree.num_nodes([child])
-
- return x, y
+ x = rect[0] + ((proc.start_time - proc_tree.start_time) * rect[2] / proc_tree.duration)
+ w = ((proc.duration) * rect[2] / proc_tree.duration)
+
+ draw_process_activity_colors(ctx, proc, proc_tree, x, y, w, proc_h, rect, clip)
+ draw_rect(ctx, PROC_BORDER_COLOR, (x, y, w, proc_h))
+ ipid = int(proc.pid)
+ if not OPTIONS.show_all:
+ cmdString = proc.cmd
+ else:
+ cmdString = ''
+ if (OPTIONS.show_pid or OPTIONS.show_all) and ipid is not 0:
+ cmdString = cmdString + " [" + str(ipid // 1000) + "]"
+ if OPTIONS.show_all:
+ if proc.args:
+ cmdString = cmdString + " '" + "' '".join(proc.args) + "'"
+ else:
+ cmdString = cmdString + " " + proc.exe
+
+ draw_label_in_box(ctx, PROC_TEXT_COLOR, cmdString, x, y + proc_h - 4, w, rect[0] + rect[2])
+
+ next_y = y + proc_h
+ for child in proc.child_list:
+ if next_y > clip[1] + clip[3]:
+ break
+ child_x, child_y = draw_processes_recursively(ctx, child, proc_tree, next_y, proc_h, rect, clip)
+ draw_process_connecting_lines(ctx, x, y, child_x, child_y, proc_h)
+ next_y = next_y + proc_h * proc_tree.num_nodes([child])
+
+ return x, y
def draw_process_activity_colors(ctx, proc, proc_tree, x, y, w, proc_h, rect, clip):
- if y > clip[1] + clip[3] or y + proc_h + 2 < clip[1]:
- return
+ if y > clip[1] + clip[3] or y + proc_h + 2 < clip[1]:
+ return
- draw_fill_rect(ctx, PROC_COLOR_S, (x, y, w, proc_h))
+ draw_fill_rect(ctx, PROC_COLOR_S, (x, y, w, proc_h))
- last_tx = -1
- for sample in proc.samples :
- tx = rect[0] + round(((sample.time - proc_tree.start_time) * rect[2] / proc_tree.duration))
+ last_tx = -1
+ for sample in proc.samples :
+ tx = rect[0] + round(((sample.time - proc_tree.start_time) * rect[2] / proc_tree.duration))
- # samples are sorted chronologically
- if tx < clip[0]:
- continue
- if tx > clip[0] + clip[2]:
- break
+ # samples are sorted chronologically
+ if tx < clip[0]:
+ continue
+ if tx > clip[0] + clip[2]:
+ break
- tw = round(proc_tree.sample_period * rect[2] / float(proc_tree.duration))
- if last_tx != -1 and abs(last_tx - tx) <= tw:
- tw -= last_tx - tx
- tx = last_tx
- tw = max (tw, 1) # nice to see at least something
+ tw = round(proc_tree.sample_period * rect[2] / float(proc_tree.duration))
+ if last_tx != -1 and abs(last_tx - tx) <= tw:
+ tw -= last_tx - tx
+ tx = last_tx
+ tw = max (tw, 1) # nice to see at least something
- last_tx = tx + tw
- state = get_proc_state( sample.state )
+ last_tx = tx + tw
+ state = get_proc_state( sample.state )
- color = STATE_COLORS[state]
- if state == STATE_RUNNING:
- alpha = min (sample.cpu_sample.user + sample.cpu_sample.sys, 1.0)
- color = tuple(list(PROC_COLOR_R[0:3]) + [alpha])
-# print "render time %d [ tx %d tw %d ], sample state %s color %s alpha %g" % (sample.time, tx, tw, state, color, alpha)
- elif state == STATE_SLEEPING:
- continue
+ color = STATE_COLORS[state]
+ if state == STATE_RUNNING:
+ alpha = min (sample.cpu_sample.user + sample.cpu_sample.sys, 1.0)
+ color = tuple(list(PROC_COLOR_R[0:3]) + [alpha])
+# print "render time %d [ tx %d tw %d ], sample state %s color %s alpha %g" % (sample.time, tx, tw, state, color, alpha)
+ elif state == STATE_SLEEPING:
+ continue
- draw_fill_rect(ctx, color, (tx, y, tw, proc_h))
+ draw_fill_rect(ctx, color, (tx, y, tw, proc_h))
def draw_process_connecting_lines(ctx, px, py, x, y, proc_h):
- ctx.set_source_rgba(*DEP_COLOR)
- ctx.set_dash([2, 2])
- if abs(px - x) < 3:
- dep_off_x = 3
- dep_off_y = proc_h / 4
- ctx.move_to(x, y + proc_h / 2)
- ctx.line_to(px - dep_off_x, y + proc_h / 2)
- ctx.line_to(px - dep_off_x, py - dep_off_y)
- ctx.line_to(px, py - dep_off_y)
- else:
- ctx.move_to(x, y + proc_h / 2)
- ctx.line_to(px, y + proc_h / 2)
- ctx.line_to(px, py)
- ctx.stroke()
- ctx.set_dash([])
+ ctx.set_source_rgba(*DEP_COLOR)
+ ctx.set_dash([2, 2])
+ if abs(px - x) < 3:
+ dep_off_x = 3
+ dep_off_y = proc_h / 4
+ ctx.move_to(x, y + proc_h / 2)
+ ctx.line_to(px - dep_off_x, y + proc_h / 2)
+ ctx.line_to(px - dep_off_x, py - dep_off_y)
+ ctx.line_to(px, py - dep_off_y)
+ else:
+ ctx.move_to(x, y + proc_h / 2)
+ ctx.line_to(px, y + proc_h / 2)
+ ctx.line_to(px, py)
+ ctx.stroke()
+ ctx.set_dash([])
# elide the bootchart collector - it is quite distorting
def elide_bootchart(proc):
- return proc.cmd == 'bootchartd' or proc.cmd == 'bootchart-colle'
+ return proc.cmd == 'bootchartd' or proc.cmd == 'bootchart-colle'
class CumlSample:
- def __init__(self, proc):
- self.cmd = proc.cmd
- self.samples = []
- self.merge_samples (proc)
- self.color = None
-
- def merge_samples(self, proc):
- self.samples.extend (proc.samples)
- self.samples.sort (key = lambda p: p.time)
-
- def next(self):
- global palette_idx
- palette_idx += HSV_STEP
- return palette_idx
-
- def get_color(self):
- if self.color is None:
- i = self.next() % HSV_MAX_MOD
- h = 0.0
- if i is not 0:
- h = (1.0 * i) / HSV_MAX_MOD
- s = 0.5
- v = 1.0
- c = colorsys.hsv_to_rgb (h, s, v)
- self.color = (c[0], c[1], c[2], 1.0)
- return self.color
+ def __init__(self, proc):
+ self.cmd = proc.cmd
+ self.samples = []
+ self.merge_samples (proc)
+ self.color = None
+
+ def merge_samples(self, proc):
+ self.samples.extend (proc.samples)
+ self.samples.sort (key = lambda p: p.time)
+
+ def next(self):
+ global palette_idx
+ palette_idx += HSV_STEP
+ return palette_idx
+
+ def get_color(self):
+ if self.color is None:
+ i = self.next() % HSV_MAX_MOD
+ h = 0.0
+ if i is not 0:
+ h = (1.0 * i) / HSV_MAX_MOD
+ s = 0.5
+ v = 1.0
+ c = colorsys.hsv_to_rgb (h, s, v)
+ self.color = (c[0], c[1], c[2], 1.0)
+ return self.color
def draw_cuml_graph(ctx, proc_tree, chart_bounds, duration, sec_w, stat_type):
- global palette_idx
- palette_idx = 0
-
- time_hash = {}
- total_time = 0.0
- m_proc_list = {}
-
- if stat_type is STAT_TYPE_CPU:
- sample_value = 'cpu'
- else:
- sample_value = 'io'
- for proc in proc_tree.process_list:
- if elide_bootchart(proc):
- continue
-
- for sample in proc.samples:
- total_time += getattr(sample.cpu_sample, sample_value)
- if not sample.time in time_hash:
- time_hash[sample.time] = 1
-
- # merge pids with the same cmd
- if not proc.cmd in m_proc_list:
- m_proc_list[proc.cmd] = CumlSample (proc)
- continue
- s = m_proc_list[proc.cmd]
- s.merge_samples (proc)
-
- # all the sample times
- times = sorted(time_hash)
- if len (times) < 2 or total_time == 0:
- print("degenerate boot chart")
- return
-
- pix_per_ns = chart_bounds[3] / total_time
-# print "total time: %g pix-per-ns %g" % (total_time, pix_per_ns)
-
- # FIXME: we have duplicates in the process list too [!] - why !?
-
- # Render bottom up, left to right
- below = {}
- for time in times:
- below[time] = chart_bounds[1] + chart_bounds[3]
-
- # same colors each time we render
- random.seed (0)
-
- ctx.set_line_width(1)
-
- legends = []
- labels = []
-
- # render each pid in order
- for cs in m_proc_list.values():
- row = {}
- cuml = 0.0
-
- # print "pid : %s -> %g samples %d" % (proc.cmd, cuml, len (cs.samples))
- for sample in cs.samples:
- cuml += getattr(sample.cpu_sample, sample_value)
- row[sample.time] = cuml
-
- process_total_time = cuml
-
- # hide really tiny processes
- if cuml * pix_per_ns <= 2:
- continue
-
- last_time = times[0]
- y = last_below = below[last_time]
- last_cuml = cuml = 0.0
-
- ctx.set_source_rgba(*cs.get_color())
- for time in times:
- render_seg = False
-
- # did the underlying trend increase ?
- if below[time] != last_below:
- last_below = below[last_time]
- last_cuml = cuml
- render_seg = True
-
- # did we move up a pixel increase ?
- if time in row:
- nc = round (row[time] * pix_per_ns)
- if nc != cuml:
- last_cuml = cuml
- cuml = nc
- render_seg = True
-
-# if last_cuml > cuml:
-# assert fail ... - un-sorted process samples
-
- # draw the trailing rectangle from the last time to
- # before now, at the height of the last segment.
- if render_seg:
- w = math.ceil ((time - last_time) * chart_bounds[2] / proc_tree.duration) + 1
- x = chart_bounds[0] + round((last_time - proc_tree.start_time) * chart_bounds[2] / proc_tree.duration)
- ctx.rectangle (x, below[last_time] - last_cuml, w, last_cuml)
- ctx.fill()
-# ctx.stroke()
- last_time = time
- y = below [time] - cuml
-
- row[time] = y
-
- # render the last segment
- x = chart_bounds[0] + round((last_time - proc_tree.start_time) * chart_bounds[2] / proc_tree.duration)
- y = below[last_time] - cuml
- ctx.rectangle (x, y, chart_bounds[2] - x, cuml)
- ctx.fill()
-# ctx.stroke()
-
- # render legend if it will fit
- if cuml > 8:
- label = cs.cmd
- extnts = ctx.text_extents(label)
- label_w = extnts[2]
- label_h = extnts[3]
-# print "Text extents %g by %g" % (label_w, label_h)
- labels.append((label,
- chart_bounds[0] + chart_bounds[2] - label_w - off_x * 2,
- y + (cuml + label_h) / 2))
- if cs in legends:
- print("ARGH - duplicate process in list !")
-
- legends.append ((cs, process_total_time))
-
- below = row
-
- # render grid-lines over the top
- draw_box_ticks(ctx, chart_bounds, sec_w)
-
- # render labels
- for l in labels:
- draw_text(ctx, l[0], TEXT_COLOR, l[1], l[2])
-
- # Render legends
- font_height = 20
- label_width = 300
- LEGENDS_PER_COL = 15
- LEGENDS_TOTAL = 45
- ctx.set_font_size (TITLE_FONT_SIZE)
- dur_secs = duration / 100
- cpu_secs = total_time / 1000000000
-
- # misleading - with multiple CPUs ...
-# idle = ((dur_secs - cpu_secs) / dur_secs) * 100.0
- if stat_type is STAT_TYPE_CPU:
- label = "Cumulative CPU usage, by process; total CPU: " \
- " %.5g(s) time: %.3g(s)" % (cpu_secs, dur_secs)
- else:
- label = "Cumulative I/O usage, by process; total I/O: " \
- " %.5g(s) time: %.3g(s)" % (cpu_secs, dur_secs)
-
- draw_text(ctx, label, TEXT_COLOR, chart_bounds[0] + off_x,
- chart_bounds[1] + font_height)
-
- i = 0
- legends = sorted(legends, key=itemgetter(1), reverse=True)
- ctx.set_font_size(TEXT_FONT_SIZE)
- for t in legends:
- cs = t[0]
- time = t[1]
- x = chart_bounds[0] + off_x + int (i/LEGENDS_PER_COL) * label_width
- y = chart_bounds[1] + font_height * ((i % LEGENDS_PER_COL) + 2)
- str = "%s - %.0f(ms) (%2.2f%%)" % (cs.cmd, time/1000000, (time/total_time) * 100.0)
- draw_legend_box(ctx, str, cs.color, x, y, leg_s)
- i = i + 1
- if i >= LEGENDS_TOTAL:
- break
+ global palette_idx
+ palette_idx = 0
+
+ time_hash = {}
+ total_time = 0.0
+ m_proc_list = {}
+
+ if stat_type is STAT_TYPE_CPU:
+ sample_value = 'cpu'
+ else:
+ sample_value = 'io'
+ for proc in proc_tree.process_list:
+ if elide_bootchart(proc):
+ continue
+
+ for sample in proc.samples:
+ total_time += getattr(sample.cpu_sample, sample_value)
+ if not sample.time in time_hash:
+ time_hash[sample.time] = 1
+
+ # merge pids with the same cmd
+ if not proc.cmd in m_proc_list:
+ m_proc_list[proc.cmd] = CumlSample (proc)
+ continue
+ s = m_proc_list[proc.cmd]
+ s.merge_samples (proc)
+
+ # all the sample times
+ times = sorted(time_hash)
+ if len (times) < 2 or total_time == 0:
+ print("degenerate boot chart")
+ return
+
+ pix_per_ns = chart_bounds[3] / total_time
+# print "total time: %g pix-per-ns %g" % (total_time, pix_per_ns)
+
+ # FIXME: we have duplicates in the process list too [!] - why !?
+
+ # Render bottom up, left to right
+ below = {}
+ for time in times:
+ below[time] = chart_bounds[1] + chart_bounds[3]
+
+ # same colors each time we render
+ random.seed (0)
+
+ ctx.set_line_width(1)
+
+ legends = []
+ labels = []
+
+ # render each pid in order
+ for cs in m_proc_list.values():
+ row = {}
+ cuml = 0.0
+
+ # print "pid : %s -> %g samples %d" % (proc.cmd, cuml, len (cs.samples))
+ for sample in cs.samples:
+ cuml += getattr(sample.cpu_sample, sample_value)
+ row[sample.time] = cuml
+
+ process_total_time = cuml
+
+ # hide really tiny processes
+ if cuml * pix_per_ns <= 2:
+ continue
+
+ last_time = times[0]
+ y = last_below = below[last_time]
+ last_cuml = cuml = 0.0
+
+ ctx.set_source_rgba(*cs.get_color())
+ for time in times:
+ render_seg = False
+
+ # did the underlying trend increase ?
+ if below[time] != last_below:
+ last_below = below[last_time]
+ last_cuml = cuml
+ render_seg = True
+
+ # did we move up a pixel increase ?
+ if time in row:
+ nc = round (row[time] * pix_per_ns)
+ if nc != cuml:
+ last_cuml = cuml
+ cuml = nc
+ render_seg = True
+
+# if last_cuml > cuml:
+# assert fail ... - un-sorted process samples
+
+ # draw the trailing rectangle from the last time to
+ # before now, at the height of the last segment.
+ if render_seg:
+ w = math.ceil ((time - last_time) * chart_bounds[2] / proc_tree.duration) + 1
+ x = chart_bounds[0] + round((last_time - proc_tree.start_time) * chart_bounds[2] / proc_tree.duration)
+ ctx.rectangle (x, below[last_time] - last_cuml, w, last_cuml)
+ ctx.fill()
+# ctx.stroke()
+ last_time = time
+ y = below [time] - cuml
+
+ row[time] = y
+
+ # render the last segment
+ x = chart_bounds[0] + round((last_time - proc_tree.start_time) * chart_bounds[2] / proc_tree.duration)
+ y = below[last_time] - cuml
+ ctx.rectangle (x, y, chart_bounds[2] - x, cuml)
+ ctx.fill()
+# ctx.stroke()
+
+ # render legend if it will fit
+ if cuml > 8:
+ label = cs.cmd
+ extnts = ctx.text_extents(label)
+ label_w = extnts[2]
+ label_h = extnts[3]
+# print "Text extents %g by %g" % (label_w, label_h)
+ labels.append((label,
+ chart_bounds[0] + chart_bounds[2] - label_w - off_x * 2,
+ y + (cuml + label_h) / 2))
+ if cs in legends:
+ print("ARGH - duplicate process in list !")
+
+ legends.append ((cs, process_total_time))
+
+ below = row
+
+ # render grid-lines over the top
+ draw_box_ticks(ctx, chart_bounds, sec_w)
+
+ # render labels
+ for l in labels:
+ draw_text(ctx, l[0], TEXT_COLOR, l[1], l[2])
+
+ # Render legends
+ font_height = 20
+ label_width = 300
+ LEGENDS_PER_COL = 15
+ LEGENDS_TOTAL = 45
+ ctx.set_font_size (TITLE_FONT_SIZE)
+ dur_secs = duration / 100
+ cpu_secs = total_time / 1000000000
+
+ # misleading - with multiple CPUs ...
+# idle = ((dur_secs - cpu_secs) / dur_secs) * 100.0
+ if stat_type is STAT_TYPE_CPU:
+ label = "Cumulative CPU usage, by process; total CPU: " \
+ " %.5g(s) time: %.3g(s)" % (cpu_secs, dur_secs)
+ else:
+ label = "Cumulative I/O usage, by process; total I/O: " \
+ " %.5g(s) time: %.3g(s)" % (cpu_secs, dur_secs)
+
+ draw_text(ctx, label, TEXT_COLOR, chart_bounds[0] + off_x,
+ chart_bounds[1] + font_height)
+
+ i = 0
+ legends = sorted(legends, key=itemgetter(1), reverse=True)
+ ctx.set_font_size(TEXT_FONT_SIZE)
+ for t in legends:
+ cs = t[0]
+ time = t[1]
+ x = chart_bounds[0] + off_x + int (i/LEGENDS_PER_COL) * label_width
+ y = chart_bounds[1] + font_height * ((i % LEGENDS_PER_COL) + 2)
+ str = "%s - %.0f(ms) (%2.2f%%)" % (cs.cmd, time/1000000, (time/total_time) * 100.0)
+ draw_legend_box(ctx, str, cs.color, x, y, leg_s)
+ i = i + 1
+ if i >= LEGENDS_TOTAL:
+ break
diff --git a/scripts/pybootchartgui/pybootchartgui/main.py.in b/scripts/pybootchartgui/pybootchartgui/main.py.in
index a954b125da..8fdd18e2cb 100644
--- a/scripts/pybootchartgui/pybootchartgui/main.py.in
+++ b/scripts/pybootchartgui/pybootchartgui/main.py.in
@@ -24,160 +24,160 @@ from . import parsing
from . import batch
def _mk_options_parser():
- """Make an options parser."""
- usage = "%prog [options] /path/to/tmp/buildstats/<recipe-machine>/<BUILDNAME>/"
- version = "%prog v1.0.0"
- parser = optparse.OptionParser(usage, version=version)
- parser.add_option("-i", "--interactive", action="store_true", dest="interactive", default=False,
- help="start in active mode")
- parser.add_option("-f", "--format", dest="format", default="png", choices=["png", "svg", "pdf"],
- help="image format (png, svg, pdf); default format png")
- parser.add_option("-o", "--output", dest="output", metavar="PATH", default=None,
- help="output path (file or directory) where charts are stored")
- parser.add_option("-s", "--split", dest="num", type=int, default=1,
- help="split the output chart into <NUM> charts, only works with \"-o PATH\"")
- parser.add_option("-m", "--mintime", dest="mintime", type=int, default=8,
- help="only tasks longer than this time will be displayed")
- parser.add_option("-M", "--minutes", action="store_true", dest="as_minutes", default=False,
- help="display time in minutes instead of seconds")
-# parser.add_option("-n", "--no-prune", action="store_false", dest="prune", default=True,
-# help="do not prune the process tree")
- parser.add_option("-q", "--quiet", action="store_true", dest="quiet", default=False,
- help="suppress informational messages")
-# parser.add_option("-t", "--boot-time", action="store_true", dest="boottime", default=False,
-# help="only display the boot time of the boot in text format (stdout)")
- parser.add_option("--very-quiet", action="store_true", dest="veryquiet", default=False,
- help="suppress all messages except errors")
- parser.add_option("--verbose", action="store_true", dest="verbose", default=False,
- help="print all messages")
-# parser.add_option("--profile", action="store_true", dest="profile", default=False,
-# help="profile rendering of chart (only useful when in batch mode indicated by -f)")
-# parser.add_option("--show-pid", action="store_true", dest="show_pid", default=False,
-# help="show process ids in the bootchart as 'processname [pid]'")
- parser.add_option("--show-all", action="store_true", dest="show_all", default=False,
- help="show all processes in the chart")
-# parser.add_option("--crop-after", dest="crop_after", metavar="PROCESS", default=None,
-# help="crop chart when idle after PROCESS is started")
-# parser.add_option("--annotate", action="append", dest="annotate", metavar="PROCESS", default=None,
-# help="annotate position where PROCESS is started; can be specified multiple times. " +
-# "To create a single annotation when any one of a set of processes is started, use commas to separate the names")
-# parser.add_option("--annotate-file", dest="annotate_file", metavar="FILENAME", default=None,
-# help="filename to write annotation points to")
- parser.add_option("-T", "--full-time", action="store_true", dest="full_time", default=False,
- help="display the full time regardless of which processes are currently shown")
- return parser
+ """Make an options parser."""
+ usage = "%prog [options] /path/to/tmp/buildstats/<recipe-machine>/<BUILDNAME>/"
+ version = "%prog v1.0.0"
+ parser = optparse.OptionParser(usage, version=version)
+ parser.add_option("-i", "--interactive", action="store_true", dest="interactive", default=False,
+ help="start in active mode")
+ parser.add_option("-f", "--format", dest="format", default="png", choices=["png", "svg", "pdf"],
+ help="image format (png, svg, pdf); default format png")
+ parser.add_option("-o", "--output", dest="output", metavar="PATH", default=None,
+ help="output path (file or directory) where charts are stored")
+ parser.add_option("-s", "--split", dest="num", type=int, default=1,
+ help="split the output chart into <NUM> charts, only works with \"-o PATH\"")
+ parser.add_option("-m", "--mintime", dest="mintime", type=int, default=8,
+ help="only tasks longer than this time will be displayed")
+ parser.add_option("-M", "--minutes", action="store_true", dest="as_minutes", default=False,
+ help="display time in minutes instead of seconds")
+# parser.add_option("-n", "--no-prune", action="store_false", dest="prune", default=True,
+# help="do not prune the process tree")
+ parser.add_option("-q", "--quiet", action="store_true", dest="quiet", default=False,
+ help="suppress informational messages")
+# parser.add_option("-t", "--boot-time", action="store_true", dest="boottime", default=False,
+# help="only display the boot time of the boot in text format (stdout)")
+ parser.add_option("--very-quiet", action="store_true", dest="veryquiet", default=False,
+ help="suppress all messages except errors")
+ parser.add_option("--verbose", action="store_true", dest="verbose", default=False,
+ help="print all messages")
+# parser.add_option("--profile", action="store_true", dest="profile", default=False,
+# help="profile rendering of chart (only useful when in batch mode indicated by -f)")
+# parser.add_option("--show-pid", action="store_true", dest="show_pid", default=False,
+# help="show process ids in the bootchart as 'processname [pid]'")
+ parser.add_option("--show-all", action="store_true", dest="show_all", default=False,
+ help="show all processes in the chart")
+# parser.add_option("--crop-after", dest="crop_after", metavar="PROCESS", default=None,
+# help="crop chart when idle after PROCESS is started")
+# parser.add_option("--annotate", action="append", dest="annotate", metavar="PROCESS", default=None,
+# help="annotate position where PROCESS is started; can be specified multiple times. " +
+# "To create a single annotation when any one of a set of processes is started, use commas to separate the names")
+# parser.add_option("--annotate-file", dest="annotate_file", metavar="FILENAME", default=None,
+# help="filename to write annotation points to")
+ parser.add_option("-T", "--full-time", action="store_true", dest="full_time", default=False,
+ help="display the full time regardless of which processes are currently shown")
+ return parser
class Writer:
- def __init__(self, write, options):
- self.write = write
- self.options = options
-
- def error(self, msg):
- self.write(msg)
+ def __init__(self, write, options):
+ self.write = write
+ self.options = options
- def warn(self, msg):
- if not self.options.quiet:
- self.write(msg)
+ def error(self, msg):
+ self.write(msg)
- def info(self, msg):
- if self.options.verbose:
- self.write(msg)
+ def warn(self, msg):
+ if not self.options.quiet:
+ self.write(msg)
- def status(self, msg):
- if not self.options.quiet:
- self.write(msg)
+ def info(self, msg):
+ if self.options.verbose:
+ self.write(msg)
+
+ def status(self, msg):
+ if not self.options.quiet:
+ self.write(msg)
def _mk_writer(options):
- def write(s):
- print(s)
- return Writer(write, options)
-
+ def write(s):
+ print(s)
+ return Writer(write, options)
+
def _get_filename(path):
- """Construct a usable filename for outputs"""
- dname = "."
- fname = "bootchart"
- if path != None:
- if os.path.isdir(path):
- dname = path
- else:
- fname = path
- return os.path.join(dname, fname)
+ """Construct a usable filename for outputs"""
+ dname = "."
+ fname = "bootchart"
+ if path != None:
+ if os.path.isdir(path):
+ dname = path
+ else:
+ fname = path
+ return os.path.join(dname, fname)
def main(argv=None):
- try:
- if argv is None:
- argv = sys.argv[1:]
-
- parser = _mk_options_parser()
- options, args = parser.parse_args(argv)
-
- # Default values for disabled options
- options.prune = True
- options.boottime = False
- options.profile = False
- options.show_pid = False
- options.crop_after = None
- options.annotate = None
- options.annotate_file = None
-
- writer = _mk_writer(options)
-
- if len(args) == 0:
- print("No path given, trying /var/log/bootchart.tgz")
- args = [ "/var/log/bootchart.tgz" ]
-
- res = parsing.Trace(writer, args, options)
-
- if options.interactive or options.output == None:
- from . import gui
- gui.show(res, options)
- elif options.boottime:
- import math
- proc_tree = res.proc_tree
- if proc_tree.idle:
- duration = proc_tree.idle
- else:
- duration = proc_tree.duration
- dur = duration / 100.0
- print('%02d:%05.2f' % (math.floor(dur/60), dur - 60 * math.floor(dur/60)))
- else:
- if options.annotate_file:
- f = open (options.annotate_file, "w")
- try:
- for time in res[4]:
- if time is not None:
- # output as ms
- f.write(time * 10)
- finally:
- f.close()
- filename = _get_filename(options.output)
- res_list = parsing.split_res(res, options)
- n = 1
- width = len(str(len(res_list)))
- s = "_%%0%dd." % width
- for r in res_list:
- if len(res_list) == 1:
- f = filename + "." + options.format
- else:
- f = filename + s % n + options.format
- n = n + 1
- def render():
- batch.render(writer, r, options, f)
- if options.profile:
- import cProfile
- import pstats
- profile = '%s.prof' % os.path.splitext(filename)[0]
- cProfile.runctx('render()', globals(), locals(), profile)
- p = pstats.Stats(profile)
- p.strip_dirs().sort_stats('time').print_stats(20)
- else:
- render()
-
- return 0
- except parsing.ParseError as ex:
- print(("Parse error: %s" % ex))
- return 2
+ try:
+ if argv is None:
+ argv = sys.argv[1:]
+
+ parser = _mk_options_parser()
+ options, args = parser.parse_args(argv)
+
+ # Default values for disabled options
+ options.prune = True
+ options.boottime = False
+ options.profile = False
+ options.show_pid = False
+ options.crop_after = None
+ options.annotate = None
+ options.annotate_file = None
+
+ writer = _mk_writer(options)
+
+ if len(args) == 0:
+ print("No path given, trying /var/log/bootchart.tgz")
+ args = [ "/var/log/bootchart.tgz" ]
+
+ res = parsing.Trace(writer, args, options)
+
+ if options.interactive or options.output == None:
+ from . import gui
+ gui.show(res, options)
+ elif options.boottime:
+ import math
+ proc_tree = res.proc_tree
+ if proc_tree.idle:
+ duration = proc_tree.idle
+ else:
+ duration = proc_tree.duration
+ dur = duration / 100.0
+ print('%02d:%05.2f' % (math.floor(dur/60), dur - 60 * math.floor(dur/60)))
+ else:
+ if options.annotate_file:
+ f = open (options.annotate_file, "w")
+ try:
+ for time in res[4]:
+ if time is not None:
+ # output as ms
+ f.write(time * 10)
+ finally:
+ f.close()
+ filename = _get_filename(options.output)
+ res_list = parsing.split_res(res, options)
+ n = 1
+ width = len(str(len(res_list)))
+ s = "_%%0%dd." % width
+ for r in res_list:
+ if len(res_list) == 1:
+ f = filename + "." + options.format
+ else:
+ f = filename + s % n + options.format
+ n = n + 1
+ def render():
+ batch.render(writer, r, options, f)
+ if options.profile:
+ import cProfile
+ import pstats
+ profile = '%s.prof' % os.path.splitext(filename)[0]
+ cProfile.runctx('render()', globals(), locals(), profile)
+ p = pstats.Stats(profile)
+ p.strip_dirs().sort_stats('time').print_stats(20)
+ else:
+ render()
+
+ return 0
+ except parsing.ParseError as ex:
+ print(("Parse error: %s" % ex))
+ return 2
if __name__ == '__main__':
- sys.exit(main())
+ sys.exit(main())
diff --git a/scripts/pybootchartgui/pybootchartgui/tests/parser_test.py b/scripts/pybootchartgui/pybootchartgui/tests/parser_test.py
index 00fb3bf797..560406212e 100644
--- a/scripts/pybootchartgui/pybootchartgui/tests/parser_test.py
+++ b/scripts/pybootchartgui/pybootchartgui/tests/parser_test.py
@@ -10,7 +10,7 @@ import pybootchartgui.main as main
debug = False
def floatEq(f1, f2):
- return math.fabs(f1-f2) < 0.00001
+ return math.fabs(f1-f2) < 0.00001
bootchart_dir = os.path.join(os.path.dirname(sys.argv[0]), '../../examples/1/')
parser = main._mk_options_parser()
@@ -18,88 +18,87 @@ options, args = parser.parse_args(['--q', bootchart_dir])
writer = main._mk_writer(options)
class TestBCParser(unittest.TestCase):
-
- def setUp(self):
- self.name = "My first unittest"
- self.rootdir = bootchart_dir
-
- def mk_fname(self,f):
- return os.path.join(self.rootdir, f)
-
- def testParseHeader(self):
- trace = parsing.Trace(writer, args, options)
- state = parsing.parse_file(writer, trace, self.mk_fname('header'))
- self.assertEqual(6, len(state.headers))
- self.assertEqual(2, parsing.get_num_cpus(state.headers))
-
- def test_parseTimedBlocks(self):
- trace = parsing.Trace(writer, args, options)
- state = parsing.parse_file(writer, trace, self.mk_fname('proc_diskstats.log'))
- self.assertEqual(141, len(state.disk_stats))
-
- def testParseProcPsLog(self):
- trace = parsing.Trace(writer, args, options)
- state = parsing.parse_file(writer, trace, self.mk_fname('proc_ps.log'))
- samples = state.ps_stats
- processes = samples.process_map
- sorted_processes = [processes[k] for k in sorted(processes.keys())]
-
- ps_data = open(self.mk_fname('extract2.proc_ps.log'))
- for index, line in enumerate(ps_data):
- tokens = line.split();
- process = sorted_processes[index]
- if debug:
- print(tokens[0:4])
- print(process.pid / 1000, process.cmd, process.ppid, len(process.samples))
- print('-------------------')
-
- self.assertEqual(tokens[0], str(process.pid // 1000))
- self.assertEqual(tokens[1], str(process.cmd))
- self.assertEqual(tokens[2], str(process.ppid // 1000))
- self.assertEqual(tokens[3], str(len(process.samples)))
- ps_data.close()
-
- def testparseProcDiskStatLog(self):
- trace = parsing.Trace(writer, args, options)
- state_with_headers = parsing.parse_file(writer, trace, self.mk_fname('header'))
- state_with_headers.headers['system.cpu'] = 'xxx (2)'
- samples = parsing.parse_file(writer, state_with_headers, self.mk_fname('proc_diskstats.log')).disk_stats
- self.assertEqual(141, len(samples))
-
- diskstats_data = open(self.mk_fname('extract.proc_diskstats.log'))
- for index, line in enumerate(diskstats_data):
- tokens = line.split('\t')
- sample = samples[index]
- if debug:
- print(line.rstrip())
- print(sample)
- print('-------------------')
-
- self.assertEqual(tokens[0], str(sample.time))
- self.assert_(floatEq(float(tokens[1]), sample.read))
- self.assert_(floatEq(float(tokens[2]), sample.write))
- self.assert_(floatEq(float(tokens[3]), sample.util))
- diskstats_data.close()
-
- def testparseProcStatLog(self):
- trace = parsing.Trace(writer, args, options)
- samples = parsing.parse_file(writer, trace, self.mk_fname('proc_stat.log')).cpu_stats
- self.assertEqual(141, len(samples))
-
- stat_data = open(self.mk_fname('extract.proc_stat.log'))
- for index, line in enumerate(stat_data):
- tokens = line.split('\t')
- sample = samples[index]
- if debug:
- print(line.rstrip())
- print(sample)
- print('-------------------')
- self.assert_(floatEq(float(tokens[0]), sample.time))
- self.assert_(floatEq(float(tokens[1]), sample.user))
- self.assert_(floatEq(float(tokens[2]), sample.sys))
- self.assert_(floatEq(float(tokens[3]), sample.io))
- stat_data.close()
+
+ def setUp(self):
+ self.name = "My first unittest"
+ self.rootdir = bootchart_dir
+
+ def mk_fname(self,f):
+ return os.path.join(self.rootdir, f)
+
+ def testParseHeader(self):
+ trace = parsing.Trace(writer, args, options)
+ state = parsing.parse_file(writer, trace, self.mk_fname('header'))
+ self.assertEqual(6, len(state.headers))
+ self.assertEqual(2, parsing.get_num_cpus(state.headers))
+
+ def test_parseTimedBlocks(self):
+ trace = parsing.Trace(writer, args, options)
+ state = parsing.parse_file(writer, trace, self.mk_fname('proc_diskstats.log'))
+ self.assertEqual(141, len(state.disk_stats))
+
+ def testParseProcPsLog(self):
+ trace = parsing.Trace(writer, args, options)
+ state = parsing.parse_file(writer, trace, self.mk_fname('proc_ps.log'))
+ samples = state.ps_stats
+ processes = samples.process_map
+ sorted_processes = [processes[k] for k in sorted(processes.keys())]
+
+ ps_data = open(self.mk_fname('extract2.proc_ps.log'))
+ for index, line in enumerate(ps_data):
+ tokens = line.split();
+ process = sorted_processes[index]
+ if debug:
+ print(tokens[0:4])
+ print(process.pid / 1000, process.cmd, process.ppid, len(process.samples))
+ print('-------------------')
+
+ self.assertEqual(tokens[0], str(process.pid // 1000))
+ self.assertEqual(tokens[1], str(process.cmd))
+ self.assertEqual(tokens[2], str(process.ppid // 1000))
+ self.assertEqual(tokens[3], str(len(process.samples)))
+ ps_data.close()
+
+ def testparseProcDiskStatLog(self):
+ trace = parsing.Trace(writer, args, options)
+ state_with_headers = parsing.parse_file(writer, trace, self.mk_fname('header'))
+ state_with_headers.headers['system.cpu'] = 'xxx (2)'
+ samples = parsing.parse_file(writer, state_with_headers, self.mk_fname('proc_diskstats.log')).disk_stats
+ self.assertEqual(141, len(samples))
+
+ diskstats_data = open(self.mk_fname('extract.proc_diskstats.log'))
+ for index, line in enumerate(diskstats_data):
+ tokens = line.split('\t')
+ sample = samples[index]
+ if debug:
+ print(line.rstrip())
+ print(sample)
+ print('-------------------')
+
+ self.assertEqual(tokens[0], str(sample.time))
+ self.assert_(floatEq(float(tokens[1]), sample.read))
+ self.assert_(floatEq(float(tokens[2]), sample.write))
+ self.assert_(floatEq(float(tokens[3]), sample.util))
+ diskstats_data.close()
+
+ def testparseProcStatLog(self):
+ trace = parsing.Trace(writer, args, options)
+ samples = parsing.parse_file(writer, trace, self.mk_fname('proc_stat.log')).cpu_stats
+ self.assertEqual(141, len(samples))
+
+ stat_data = open(self.mk_fname('extract.proc_stat.log'))
+ for index, line in enumerate(stat_data):
+ tokens = line.split('\t')
+ sample = samples[index]
+ if debug:
+ print(line.rstrip())
+ print(sample)
+ print('-------------------')
+ self.assert_(floatEq(float(tokens[0]), sample.time))
+ self.assert_(floatEq(float(tokens[1]), sample.user))
+ self.assert_(floatEq(float(tokens[2]), sample.sys))
+ self.assert_(floatEq(float(tokens[3]), sample.io))
+ stat_data.close()
if __name__ == '__main__':
unittest.main()
-