source: benchmark/plot.py @ 2ebde76

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

Forgot to remove debug print.

  • Property mode set to 100755
File size: 4.3 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        for name, data in series.items():
81                _col = next(colors)
82                plt.scatter(data['x'], data['y'], color=_col, label=name, marker='x')
83                plt.plot(lines[name]['x'], lines[name]['min'], '--', color=_col)
84                plt.plot(lines[name]['x'], lines[name]['max'], '--', color=_col)
85                plt.plot(lines[name]['x'], lines[name]['med'], '-', color=_col)
86
87        mx = max([max(s['x']) for s in series.values()])
88        my = max([max(s['y']) for s in series.values()])
89
90        plt.ylabel(y)
91        plt.xlim(field_names[x].min, mx + 0.25)
92        plt.xticks(range(1, math.ceil(mx) + 1))
93        plt.xlabel(x)
94        plt.ylim(field_names[y].min, my*1.2)
95        plt.grid(b = True)
96        ax.xaxis.set_major_formatter( EngFormatter(unit=field_names[x].unit) )
97        ax.yaxis.set_major_formatter( EngFormatter(unit=field_names[y].unit) )
98        plt.legend(loc='upper left')
99        if out:
100                plt.savefig(out)
101        else:
102                plt.show()
103
104
105if __name__ == "__main__":
106        # ================================================================================
107        # parse command line arguments
108        parser = parser = argparse.ArgumentParser(description='Python Script to draw R.M.I.T. results')
109        parser.add_argument('-f', '--file', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
110        parser.add_argument('-o', '--out', nargs='?', type=str, default=None)
111        parser.add_argument('-y', nargs='?', type=str, default="")
112
113        try:
114                options =  parser.parse_args()
115        except:
116                print('ERROR: invalid arguments', file=sys.stderr)
117                parser.print_help(sys.stderr)
118                sys.exit(1)
119
120        # ================================================================================
121        # load data
122        try :
123                data = json.load(options.file)
124        except :
125                print('ERROR: could not read input', file=sys.stderr)
126                parser.print_help(sys.stderr)
127                sys.exit(1)
128
129        # ================================================================================
130        # identify the keys
131
132        series = set()
133        fields = set()
134
135        for entry in data:
136                series.add(entry[0])
137                for label in entry[2].keys():
138                        fields.add(label)
139
140        if not options.out :
141                print(series)
142                print("fields")
143                for f in fields:
144                        print("{}".format(f))
145
146        if options.y and options.y in field_names.keys():
147                plot(data, "Number of processors", options.y, options.out)
148        else:
149                if options.y:
150                        print("Could not find key '{}', defaulting to 'ns per ops'".format(options.y))
151                plot(data, "Number of processors", "ns per ops", options.out)
Note: See TracBrowser for help on using the repository browser.