示例#1
0
 def update(self):
     mtime = os.path.getmtime(self.fn)
     if self.mtime == mtime:
         return
     self.mtime = mtime
     csvf = csv.reader(open(self.fn, 'r'))
     prevts = None
     val = dict()
     for r in csvf:
         if re.match(r'[CS]\d+.*', r[1]):
             ts, cpu, name, pct, state, helptxt = r[0], r[1], r[2], r[3], r[
                 4], r[5]
         else:
             ts, name, pct, state, helptxt = r[0], r[1], r[2], r[3], r[4]
             cpu = None
         key = (name, cpu)
         ts, pct = float(ts), float(pct.replace("%", ""))
         if name not in self.helptxt or self.helptxt[name] == "":
             self.helptxt[name] = helptxt
         if state == "below" and not self.verbose:
             continue
         if prevts and ts != prevts:
             self.times.append(prevts)
             self.vals.append(val)
             val = dict()
         val[key] = pct
         n = gen_level.level_name(name)
         if cpu:
             self.cpus.add(cpu)
         self.headers.add(name)
         if gen_level.is_metric(name):
             self.metrics.add(n)
         self.levels[n].add(name)
         prevts = ts
示例#2
0
 def update(self):
     mtime = os.path.getmtime(self.fn)
     if self.mtime == mtime:
         return
     self.mtime = mtime
     csvf = csv.reader(open(self.fn, "r"))
     prevts = None
     val = dict()
     for r in csvf:
         if re.match(r"[CS]\d+.*", r[1]):
             ts, cpu, name, pct, state, helptxt = r[0], r[1], r[2], r[3], r[4], r[5]
         else:
             ts, name, pct, state, helptxt = r[0], r[1], r[2], r[3], r[4]
             cpu = "cpu"
         key = (name, cpu)
         ts, pct = float(ts), float(pct.replace("%", ""))
         if name not in self.helptxt or self.helptxt[name] == "":
             self.helptxt[name] = helptxt
         if state == "below" and not self.verbose:
             continue
         if prevts and ts != prevts:
             self.times.append(prevts)
             self.vals.append(val)
             val = dict()
         val[key] = pct
         n = gen_level.level_name(name)
         self.cpus.add(cpu)
         self.headers.add(name)
         if gen_level.is_metric(name):
             self.metrics.add(n)
         self.levels[n].add(name)
         prevts = ts
示例#3
0
xaxis = None
legend_bbox = (0., 0., -0.07, -0.03)
legend_loc = 2

for l in tldata.level_order(data):
    non_null = [x for x in levels[l] if valid_row(ratios[x])]
    if not non_null:
        n += 1
        continue
    all_colors = get_colors(non_null)
    ax = plt.subplot2grid((numplots, 1), (n, 0), sharex=xaxis)
    plt.tight_layout()
    set_title(ax, l)
    r = [[y if y == y else 0.0 for y in ratios[x]] for x in non_null]

    if gen_level.is_metric(non_null[0]):
        for j, name in zip(r, non_null):
            stack = ax.plot(timestamps, j, label=name)
        leg = plt.legend(ncol=6,
                         loc=legend_loc,
                         bbox_to_anchor=legend_bbox,
                         prop={'size':6})
        low = min([min(ratios[x]) for x in non_null])
        high = max([max(ratios[x]) for x in non_null])
        if not math.isnan(low) and not math.isnan(high):
            ax.yaxis.set_ticks([low, math.trunc(((high - low) / 2.0) / 100.) * 100., high])
    else:
        stack = ax.stackplot(timestamps, *r, colors=all_colors)
        ax.set_ylim(0, 100)
        ax.yaxis.set_ticks([0., 50., 100.])
        p = [plt.Rectangle((0, 0), 1, 1, fc=pc.get_facecolor()[0]) for pc in stack]
示例#4
0
legend_bbox = (0., 0., -0.07, -0.03)
legend_loc = 2

for l in tldata.level_order(data):
    non_null = filter(lambda x: valid_row(ratios[x]), levels[l])
    if not non_null:
        print "nothing in level", l
        n += 1
        continue
    all_colors = get_colors(non_null)
    ax = plt.subplot2grid((numplots, 1), (n, 0), sharex=xaxis)
    plt.tight_layout()
    set_title(ax, l)
    r = [ratios[x] for x in non_null]

    if gen_level.is_metric(non_null[0]):
        for j, name in zip(r, non_null):
            stack = ax.plot(timestamps, j, label=name)
        leg = plt.legend(ncol=6,
                         loc=legend_loc,
                         bbox_to_anchor=legend_bbox,
                         prop={'size':6})
        low = min([min(ratios[x]) for x in non_null])
        high = max([max(ratios[x]) for x in non_null])
        if not math.isnan(low) and not math.isnan(high):
            ax.yaxis.set_ticks([low, math.trunc(((high - low)/2.0)/100.)*100., high])
    else:
        stack = ax.stackplot(timestamps, *r, colors=all_colors)
        ax.set_ylim(0, 100)
        ax.yaxis.set_ticks([0., 50., 100.])
        p = [plt.Rectangle((0, 0), 1, 1, fc=pc.get_facecolor()[0]) for pc in stack]
示例#5
0
def gen_chart(source):
    if source not in headers:
        print("source %s for chart not found" % source, file=sys.stderr)
        return

    worksheet = get_worksheet(source + " chart")
    charts = collections.OrderedDict()

    for n, ind in headers[source].items():
        if n == "Timestamp":
            continue
        ns = n.split()
        if len(ns) > 1:
            prefix = ns[0] + " "
            nn = " ".join(ns[1:])
        else:
            prefix = ''
            nn = n

        if gen_level.is_metric(nn):
            chart = workbook.add_chart({'type': 'line'})
            charts[n] = chart
            chart.set_title({'name': n})
        else:
            key = n[:n.rindex('.')] if '.' in n else prefix
            if key not in charts:
                charts[key] = workbook.add_chart({
                    'type': 'column',
                    'subtype': 'percent_stacked'
                })
            chart = charts[key]
            chart.set_title({
                'name':
                '%s Level %d %s' %
                (prefix, n.count('.') + 1,
                 key[key.index(' '):] if ' ' in key else key)
            })
            chart.set_x_axis({'name': 'Timestamp'})
        chart.add_series({
            'name': [source, 0, ind],
            'categories': [source, 1, 0, rows[source], 0],
            'values': [source, 1, ind, rows[source], ind]
        })
        chart.set_size({'width': (rows[source] + MIN_ROWS) * ROW_SCALE})
        chart.set_legend({
            'overlay': True,
            'layout': {
                'x': 0.01,
                'y': 0.01,
                'width': 0.12,
                'height': 0.12
            },
            'fill': {
                'none': True,
                'transparency': True
            }
        })
    row = 1
    for j in charts.keys():
        worksheet.insert_chart('A%d' % row, charts[j])
        row += GRAPH_ROWS