Browse Source

Multiple lines in charts

Ilya Shakhat 3 years ago
parent
commit
29660a67ac
2 changed files with 27 additions and 11 deletions
  1. 18
    9
      performa/engine/report.py
  2. 9
    2
      performa/scenarios/db/sysbench.rst

+ 18
- 9
performa/engine/report.py View File

@@ -13,6 +13,7 @@
13 13
 # See the License for the specific language governing permissions and
14 14
 # limitations under the License.
15 15
 
16
+import collections
16 17
 import errno
17 18
 import functools
18 19
 import os
@@ -36,6 +37,7 @@ def generate_chart(chart_str, records_collection, doc_folder, tag):
36 37
     chart = yaml.safe_load(chart_str)
37 38
     pipeline = chart.get('pipeline')
38 39
     title = chart.get('title')
40
+    fill = chart.get('fill') or False
39 41
     axes = chart.get('axes') or dict(x='x', y='y')
40 42
 
41 43
     if tag:
@@ -43,28 +45,35 @@ def generate_chart(chart_str, records_collection, doc_folder, tag):
43 45
 
44 46
     chart_data = records_collection.aggregate(pipeline)
45 47
 
46
-    line = []
48
+    lines = collections.defaultdict(list)
47 49
 
48 50
     table = '''
49 51
 .. list-table:: %(title)s
50 52
    :header-rows: 1
51 53
 
52
-   * - %(x)s
53
-     - %(y)s
54
-''' % dict(title=title, x=axes['x'], y=axes['y'])
54
+   *
55
+''' % dict(title=title)
56
+
57
+    table += ''.join(('     - %s\n' % axes[k]) for k in sorted(axes.keys()))
58
+
59
+    y_keys = set(axes.keys()) ^ set('x')
55 60
 
56 61
     for chart_rec in chart_data:
57
-        line.append((chart_rec['x'], chart_rec['y']))
62
+        for k in y_keys:
63
+            lines[k].append((chart_rec['x'], chart_rec[k]))
58 64
         table += ('   *\n' +
59
-                  '\n'.join('     - %d' % chart_rec[v] for v in ('x', 'y')) +
65
+                  '\n'.join('     - %d' % chart_rec[v]
66
+                            for v in sorted(axes.keys())) +
60 67
                   '\n')
61 68
 
62 69
     xy_chart = pygal.XY(style=style.RedBlueStyle,
63
-                        fill=True,
70
+                        fill=fill,
64 71
                         legend_at_bottom=True,
65 72
                         include_x_axis=True,
66 73
                         x_title=axes['x'])
67
-    xy_chart.add(axes['y'], line)
74
+
75
+    for k in y_keys:
76
+        xy_chart.add(axes[k], lines[k])
68 77
 
69 78
     chart_filename = utils.strict(title)
70 79
     abs_chart_filename = '%s.svg' % os.path.join(doc_folder, chart_filename)
@@ -130,7 +139,7 @@ def main():
130 139
     base_dir = os.path.dirname(scenario_file_path)
131 140
 
132 141
     generate_report(scenario, base_dir, cfg.CONF.mongo_url, cfg.CONF.mongo_db,
133
-                    cfg.CONF.book)
142
+                    cfg.CONF.book, cfg.CONF.tag)
134 143
 
135 144
 
136 145
 if __name__ == "__main__":

+ 9
- 2
performa/scenarios/db/sysbench.rst View File

@@ -14,11 +14,18 @@ Chart and table:
14 14
     axes:
15 15
       x: threads
16 16
       y: queries per sec
17
+      y2: read queries per sec
17 18
     chart: line
18 19
     pipeline:
19 20
     - { $match: { class: sysbench-oltp, status: OK }}
20
-    - { $group: { _id: { threads: "$threads" }, queries_total_per_sec: { $avg: { $divide: ["$queries_total", "$duration"] }}}}
21
-    - { $project: { x: "$_id.threads", y: "$queries_total_per_sec" }}
21
+    - { $group: { _id: { threads: "$threads" },
22
+                  queries_total_per_sec: { $avg: { $divide: ["$queries_total", "$duration"] }},
23
+                  queries_read_per_sec: { $avg: { $divide: ["$queries_read", "$duration"] }}
24
+                }}
25
+    - { $project: { x: "$_id.threads",
26
+                    y: "$queries_total_per_sec",
27
+                    y2: "$queries_read_per_sec"
28
+                  }}
22 29
     - { $sort: { x: 1 }}
23 30
 ''' | chart
24 31
 }}

Loading…
Cancel
Save