|
| 1 | +#!/usr/bin/env python |
| 2 | +import csv |
| 3 | +import matplotlib.pyplot as plt |
| 4 | + |
| 5 | + |
| 6 | +def to_python(s): |
| 7 | + if s.endswith('app'): |
| 8 | + return s |
| 9 | + elif '.' in s: |
| 10 | + return float(s) |
| 11 | + else: |
| 12 | + return int(s) |
| 13 | + |
| 14 | + |
| 15 | +def load(p): |
| 16 | + with open(p, 'r') as f: |
| 17 | + report = csv.reader(f) |
| 18 | + raw_data = [list(map(to_python, l)) for l in report] |
| 19 | + |
| 20 | + data = {} |
| 21 | + for i in raw_data: |
| 22 | + title = i[0] |
| 23 | + if title not in data: |
| 24 | + data[title] = [] |
| 25 | + data[title].append(i[1:]) |
| 26 | + return data |
| 27 | + |
| 28 | + |
| 29 | +def plot(data, ax, y_index, x_index=0): |
| 30 | + for label, rows in data.items(): |
| 31 | + x = [i[x_index] for i in rows] |
| 32 | + y = [i[y_index] for i in rows] |
| 33 | + ax.scatter(x, y, label=label) |
| 34 | + |
| 35 | + |
| 36 | +def plots(plots_desc, data): |
| 37 | + for p in plots_desc: |
| 38 | + title, x_desc, y_desc, prepare, fname = p |
| 39 | + x_label, x_index = x_desc |
| 40 | + y_label, y_index = y_desc |
| 41 | + fig, ax = plt.subplots() |
| 42 | + prepare(ax) |
| 43 | + ax.set_title(title) |
| 44 | + plot(data, ax, y_index, x_index) |
| 45 | + ax.legend() |
| 46 | + ax.set_xlabel(x_label) |
| 47 | + ax.set_ylabel(y_label) |
| 48 | + fig.savefig('plots/' + fname) |
| 49 | + |
| 50 | + |
| 51 | +def main(): |
| 52 | + plots( |
| 53 | + [ |
| 54 | + [ |
| 55 | + "Requests/sec", |
| 56 | + ["delay [ms]", 0], |
| 57 | + ["req/s", 1], |
| 58 | + lambda ax: ax.set_yscale("log", nonposx='clip'), |
| 59 | + "requests_per_sec.png" |
| 60 | + ], |
| 61 | + [ |
| 62 | + "Transfer", |
| 63 | + ["delay [ms]", 0], |
| 64 | + ["KB/s", 2], |
| 65 | + lambda ax: ax.set_yscale("log", nonposx='clip'), |
| 66 | + "transfer.png" |
| 67 | + ], |
| 68 | + [ |
| 69 | + "Latency", |
| 70 | + ["delay [ms]", 0], |
| 71 | + ["KB/s", 3], |
| 72 | + lambda ax: ax, |
| 73 | + "latency.png" |
| 74 | + ], |
| 75 | + [ |
| 76 | + "Timeouts", |
| 77 | + ["delay [ms]", 0], |
| 78 | + ["errors", 5], |
| 79 | + lambda ax: ax, |
| 80 | + "timeouts.png" |
| 81 | + ], |
| 82 | + [ |
| 83 | + "All Errors", |
| 84 | + ["delay [ms]", 0], |
| 85 | + ["errors", 6], |
| 86 | + lambda ax: ax, |
| 87 | + "all_errors.png" |
| 88 | + ] |
| 89 | + ], |
| 90 | + load('./report.csv') |
| 91 | + ) |
| 92 | + |
| 93 | + |
| 94 | +if __name__ == '__main__': |
| 95 | + main() |
0 commit comments