source: benchmark/plot.py @ 13888c0

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since 13888c0 was f34f95c, checked in by Thierry Delisle <tdelisle@…>, 2 years ago

Updated plot script to support non-interactive mode

  • Property mode set to 100755
File size: 3.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 sys
18
19import matplotlib.pyplot as plt
20from matplotlib.ticker import EngFormatter
21
22class Field:
23        def __init__(self, unit, _min):
24                self.unit = unit
25                self.min  = _min
26
27field_names = {
28        "ns per ops"           : Field('ns'    , 0),
29        "Number of processors" : Field(''      , 1),
30        "Ops per procs"        : Field('Ops'   , 0),
31        "Ops per threads"      : Field('Ops'   , 0),
32        "ns per ops/procs"     : Field('ns'    , 0),
33        "Number of threads"    : Field('thrd'  , 1),
34        "Total Operations(ops)": Field('Ops'   , 0),
35        "Ops/sec/procs"        : Field('Ops'   , 0),
36        "Total blocks"         : Field('Blocks', 0),
37        "Ops per second"       : Field('Ops'   , 0),
38        "Cycle size (# thrds)" : Field('thrd'  , 1),
39        "Duration (ms)"        : Field('ms'    , 0),
40}
41
42def plot(data, x, y, out):
43        fig, ax = plt.subplots()
44        colors = itertools.cycle(['#0095e3','#006cb4','#69df00','#0aa000','#fb0300','#e30002','#fd8f00','#ff7f00','#8f00d6','#4b009a','#ffff00','#b13f00'])
45        series = {}
46        for entry in data:
47                if not entry[0] in series:
48                        series[entry[0]] = {'x':[], 'y':[]}
49
50                if x in entry[2] and y in entry[2]:
51                        series[entry[0]]['x'].append(entry[2][x])
52                        series[entry[0]]['y'].append(entry[2][y])
53
54        for name, data in series.items():
55                plt.scatter(data['x'], data['y'], color=next(colors), label=name, marker='x')
56
57        mx = max([max(s['x']) for s in series.values()])
58        my = max([max(s['y']) for s in series.values()])
59
60        plt.ylabel(y)
61        plt.xlim(field_names[x].min, mx + 0.25)
62        plt.xticks(range(1, math.ceil(mx) + 1))
63        plt.xlabel(x)
64        plt.ylim(field_names[y].min, my*1.2)
65        plt.grid(b = True)
66        ax.xaxis.set_major_formatter( EngFormatter(unit=field_names[x].unit) )
67        ax.yaxis.set_major_formatter( EngFormatter(unit=field_names[y].unit) )
68        plt.legend(loc='upper left')
69        if out:
70                plt.savefig(out)
71        else:
72                plt.show()
73
74
75if __name__ == "__main__":
76        # ================================================================================
77        # parse command line arguments
78        parser = parser = argparse.ArgumentParser(description='Python Script to draw R.M.I.T. results')
79        parser.add_argument('-f', '--file', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
80        parser.add_argument('-o', '--out', nargs='?', type=str, default=None)
81        parser.add_argument('-y', nargs='?', type=str, default="")
82
83        try:
84                options =  parser.parse_args()
85        except:
86                print('ERROR: invalid arguments', file=sys.stderr)
87                parser.print_help(sys.stderr)
88                sys.exit(1)
89
90        # ================================================================================
91        # load data
92        try :
93                data = json.load(options.file)
94        except :
95                print('ERROR: could not read input', file=sys.stderr)
96                parser.print_help(sys.stderr)
97                sys.exit(1)
98
99        # ================================================================================
100        # identify the keys
101
102        series = set()
103        fields = set()
104
105        for entry in data:
106                series.add(entry[0])
107                for label in entry[2].keys():
108                        fields.add(label)
109
110        if not options.out :
111                print(series)
112                print("fields")
113                for f in fields:
114                        print("{}".format(f))
115
116        if options.y and options.y in field_names.keys():
117                plot(data, "Number of processors", options.y, options.out)
118        else:
119                if options.y:
120                        print("Could not find key '{}', defaulting to 'ns per ops'".format(options.y))
121                plot(data, "Number of processors", "ns per ops", options.out)
Note: See TracBrowser for help on using the repository browser.