source: benchmark/plot.py @ 57af3f3

ADTast-experimentalpthread-emulationqualifiedEnum
Last change on this file since 57af3f3 was 57af3f3, checked in by Thierry Delisle <tdelisle@…>, 2 years ago

Changed plotter to show all data + min,max and median.

  • Property mode set to 100755
File size: 4.4 KB
Line 
1#!/usr/bin/python3
2"""
3Python Script to plot values obtained by the rmit.py script
4Runs a R.I.P.L.
5
6./plot.py
7-t trials
8-o option:values
9"""
10
11import argparse
12import itertools
13import json
14import math
15import numpy
16import re
17import statistics
18import sys
19
20import matplotlib.pyplot as plt
21from matplotlib.ticker import EngFormatter
22
23class Field:
24        def __init__(self, unit, _min):
25                self.unit = unit
26                self.min  = _min
27
28field_names = {
29        "ns per ops"           : Field('ns'    , 0),
30        "Number of processors" : Field(''      , 1),
31        "Ops per procs"        : Field('Ops'   , 0),
32        "Ops per threads"      : Field('Ops'   , 0),
33        "ns per ops/procs"     : Field('ns'    , 0),
34        "Number of threads"    : Field('thrd'  , 1),
35        "Total Operations(ops)": Field('Ops'   , 0),
36        "Ops/sec/procs"        : Field('Ops'   , 0),
37        "Total blocks"         : Field('Blocks', 0),
38        "Ops per second"       : Field('Ops'   , 0),
39        "Cycle size (# thrds)" : Field('thrd'  , 1),
40        "Duration (ms)"        : Field('ms'    , 0),
41}
42
43def plot(in_data, x, y, out):
44        fig, ax = plt.subplots()
45        colors = itertools.cycle(['#0095e3','#006cb4','#69df00','#0aa000','#fb0300','#e30002','#fd8f00','#ff7f00','#8f00d6','#4b009a','#ffff00','#b13f00'])
46        series = {} # scatter data for each individual data point
47        groups = {} # data points for x value
48        for entry in in_data:
49                name = entry[0]
50                if not name in series:
51                        series[name] = {'x':[], 'y':[]}
52
53                if not name in groups:
54                        groups[name] = {}
55
56                if x in entry[2] and y in entry[2]:
57                        xval = entry[2][x]
58                        yval = entry[2][y]
59                        series[name]['x'].append(xval)
60                        series[name]['y'].append(yval)
61
62                        if not xval in groups[name]:
63                                groups[name][xval] = []
64
65                        groups[name][xval].append(yval)
66
67        lines = {} # lines from groups with min, max, median, etc.
68        for name, data in groups.items():
69                if not name in lines:
70                        lines[name] = { 'x': [], 'min':[], 'max':[], 'med':[], 'avg':[] }
71
72                for xkey in sorted(data):
73                        ys = data[xkey]
74                        lines[name]['x']  .append(xkey)
75                        lines[name]['min'].append(min(ys))
76                        lines[name]['max'].append(max(ys))
77                        lines[name]['med'].append(statistics.median(ys))
78                        lines[name]['avg'].append(statistics.mean(ys))
79
80                print(lines[name])
81
82        for name, data in series.items():
83                _col = next(colors)
84                plt.scatter(data['x'], data['y'], color=_col, label=name, marker='x')
85                plt.plot(lines[name]['x'], lines[name]['min'], '--', color=_col)
86                plt.plot(lines[name]['x'], lines[name]['max'], '--', color=_col)
87                plt.plot(lines[name]['x'], lines[name]['med'], '-', color=_col)
88
89        mx = max([max(s['x']) for s in series.values()])
90        my = max([max(s['y']) for s in series.values()])
91
92        plt.ylabel(y)
93        plt.xlim(field_names[x].min, mx + 0.25)
94        plt.xticks(range(1, math.ceil(mx) + 1))
95        plt.xlabel(x)
96        plt.ylim(field_names[y].min, my*1.2)
97        plt.grid(b = True)
98        ax.xaxis.set_major_formatter( EngFormatter(unit=field_names[x].unit) )
99        ax.yaxis.set_major_formatter( EngFormatter(unit=field_names[y].unit) )
100        plt.legend(loc='upper left')
101        if out:
102                plt.savefig(out)
103        else:
104                plt.show()
105
106
107if __name__ == "__main__":
108        # ================================================================================
109        # parse command line arguments
110        parser = parser = argparse.ArgumentParser(description='Python Script to draw R.M.I.T. results')
111        parser.add_argument('-f', '--file', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
112        parser.add_argument('-o', '--out', nargs='?', type=str, default=None)
113        parser.add_argument('-y', nargs='?', type=str, default="")
114
115        try:
116                options =  parser.parse_args()
117        except:
118                print('ERROR: invalid arguments', file=sys.stderr)
119                parser.print_help(sys.stderr)
120                sys.exit(1)
121
122        # ================================================================================
123        # load data
124        try :
125                data = json.load(options.file)
126        except :
127                print('ERROR: could not read input', file=sys.stderr)
128                parser.print_help(sys.stderr)
129                sys.exit(1)
130
131        # ================================================================================
132        # identify the keys
133
134        series = set()
135        fields = set()
136
137        for entry in data:
138                series.add(entry[0])
139                for label in entry[2].keys():
140                        fields.add(label)
141
142        if not options.out :
143                print(series)
144                print("fields")
145                for f in fields:
146                        print("{}".format(f))
147
148        if options.y and options.y in field_names.keys():
149                plot(data, "Number of processors", options.y, options.out)
150        else:
151                if options.y:
152                        print("Could not find key '{}', defaulting to 'ns per ops'".format(options.y))
153                plot(data, "Number of processors", "ns per ops", options.out)
Note: See TracBrowser for help on using the repository browser.