From 29660a67ac80031d38cb3dc35d9ac10b16b7adb0 Mon Sep 17 00:00:00 2001 From: Ilya Shakhat Date: Fri, 19 Feb 2016 18:18:37 +0300 Subject: [PATCH] Multiple lines in charts --- performa/engine/report.py | 27 ++++++++++++++++++--------- performa/scenarios/db/sysbench.rst | 11 +++++++++-- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/performa/engine/report.py b/performa/engine/report.py index 623ed6f..b0d5838 100644 --- a/performa/engine/report.py +++ b/performa/engine/report.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import collections import errno import functools import os @@ -36,6 +37,7 @@ def generate_chart(chart_str, records_collection, doc_folder, tag): chart = yaml.safe_load(chart_str) pipeline = chart.get('pipeline') title = chart.get('title') + fill = chart.get('fill') or False axes = chart.get('axes') or dict(x='x', y='y') if tag: @@ -43,28 +45,35 @@ def generate_chart(chart_str, records_collection, doc_folder, tag): chart_data = records_collection.aggregate(pipeline) - line = [] + lines = collections.defaultdict(list) table = ''' .. list-table:: %(title)s :header-rows: 1 - * - %(x)s - - %(y)s -''' % dict(title=title, x=axes['x'], y=axes['y']) + * +''' % dict(title=title) + + table += ''.join((' - %s\n' % axes[k]) for k in sorted(axes.keys())) + + y_keys = set(axes.keys()) ^ set('x') for chart_rec in chart_data: - line.append((chart_rec['x'], chart_rec['y'])) + for k in y_keys: + lines[k].append((chart_rec['x'], chart_rec[k])) table += (' *\n' + - '\n'.join(' - %d' % chart_rec[v] for v in ('x', 'y')) + + '\n'.join(' - %d' % chart_rec[v] + for v in sorted(axes.keys())) + '\n') xy_chart = pygal.XY(style=style.RedBlueStyle, - fill=True, + fill=fill, legend_at_bottom=True, include_x_axis=True, x_title=axes['x']) - xy_chart.add(axes['y'], line) + + for k in y_keys: + xy_chart.add(axes[k], lines[k]) chart_filename = utils.strict(title) abs_chart_filename = '%s.svg' % os.path.join(doc_folder, chart_filename) @@ -130,7 +139,7 @@ def main(): base_dir = os.path.dirname(scenario_file_path) generate_report(scenario, base_dir, cfg.CONF.mongo_url, cfg.CONF.mongo_db, - cfg.CONF.book) + cfg.CONF.book, cfg.CONF.tag) if __name__ == "__main__": diff --git a/performa/scenarios/db/sysbench.rst b/performa/scenarios/db/sysbench.rst index 61251e2..1606ac7 100644 --- a/performa/scenarios/db/sysbench.rst +++ b/performa/scenarios/db/sysbench.rst @@ -14,11 +14,18 @@ Chart and table: axes: x: threads y: queries per sec + y2: read queries per sec chart: line pipeline: - { $match: { class: sysbench-oltp, status: OK }} - - { $group: { _id: { threads: "$threads" }, queries_total_per_sec: { $avg: { $divide: ["$queries_total", "$duration"] }}}} - - { $project: { x: "$_id.threads", y: "$queries_total_per_sec" }} + - { $group: { _id: { threads: "$threads" }, + queries_total_per_sec: { $avg: { $divide: ["$queries_total", "$duration"] }}, + queries_read_per_sec: { $avg: { $divide: ["$queries_read", "$duration"] }} + }} + - { $project: { x: "$_id.threads", + y: "$queries_total_per_sec", + y2: "$queries_read_per_sec" + }} - { $sort: { x: 1 }} ''' | chart }}