| [0bb691b1] | 1 | #!/usr/bin/python3 | 
|---|
|  | 2 | """ | 
|---|
|  | 3 | Python Script to plot values obtained by the rmit.py script | 
|---|
|  | 4 | Runs a R.I.P.L. | 
|---|
|  | 5 |  | 
|---|
|  | 6 | ./plot.py | 
|---|
|  | 7 | -t trials | 
|---|
|  | 8 | -o option:values | 
|---|
|  | 9 | """ | 
|---|
|  | 10 |  | 
|---|
|  | 11 | import argparse | 
|---|
|  | 12 | import itertools | 
|---|
|  | 13 | import json | 
|---|
|  | 14 | import math | 
|---|
|  | 15 | import numpy | 
|---|
|  | 16 | import re | 
|---|
|  | 17 | import sys | 
|---|
|  | 18 |  | 
|---|
|  | 19 | import matplotlib.pyplot as plt | 
|---|
|  | 20 | from matplotlib.ticker import EngFormatter | 
|---|
|  | 21 |  | 
|---|
| [44706d1] | 22 | class Field: | 
|---|
|  | 23 | def __init__(self, unit, _min): | 
|---|
|  | 24 | self.unit = unit | 
|---|
|  | 25 | self.min  = _min | 
|---|
|  | 26 |  | 
|---|
|  | 27 | field_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 | } | 
|---|
| [0bb691b1] | 41 |  | 
|---|
|  | 42 | def plot(data, x, y): | 
|---|
|  | 43 | fig, ax = plt.subplots() | 
|---|
| [44706d1] | 44 | colors = itertools.cycle(['#0095e3','#006cb4','#69df00','#0aa000','#fb0300','#e30002','#fd8f00','#ff7f00','#8f00d6','#4b009a','#ffff00','#b13f00']) | 
|---|
| [0bb691b1] | 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) | 
|---|
| [44706d1] | 61 | plt.xlim(field_names[x].min, mx + 0.25) | 
|---|
| [0bb691b1] | 62 | plt.xticks(range(1, math.ceil(mx) + 1)) | 
|---|
|  | 63 | plt.xlabel(x) | 
|---|
| [44706d1] | 64 | plt.ylim(field_names[y].min, my*1.2) | 
|---|
| [0bb691b1] | 65 | plt.grid(b = True) | 
|---|
| [44706d1] | 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') | 
|---|
| [0bb691b1] | 69 | plt.show() | 
|---|
|  | 70 |  | 
|---|
|  | 71 |  | 
|---|
|  | 72 | if __name__ == "__main__": | 
|---|
|  | 73 | # ================================================================================ | 
|---|
|  | 74 | # parse command line arguments | 
|---|
|  | 75 | parser = parser = argparse.ArgumentParser(description='Python Script to draw R.M.I.T. results') | 
|---|
|  | 76 | parser.add_argument('-f', '--file', nargs='?', type=argparse.FileType('r'), default=sys.stdin) | 
|---|
|  | 77 |  | 
|---|
|  | 78 | try: | 
|---|
|  | 79 | options =  parser.parse_args() | 
|---|
|  | 80 | except: | 
|---|
|  | 81 | print('ERROR: invalid arguments', file=sys.stderr) | 
|---|
|  | 82 | parser.print_help(sys.stderr) | 
|---|
|  | 83 | sys.exit(1) | 
|---|
|  | 84 |  | 
|---|
|  | 85 | # ================================================================================ | 
|---|
|  | 86 | # load data | 
|---|
|  | 87 | try : | 
|---|
|  | 88 | data = json.load(options.file) | 
|---|
|  | 89 | except : | 
|---|
|  | 90 | print('ERROR: could not read input', file=sys.stderr) | 
|---|
|  | 91 | parser.print_help(sys.stderr) | 
|---|
|  | 92 | sys.exit(1) | 
|---|
|  | 93 |  | 
|---|
|  | 94 | # ================================================================================ | 
|---|
|  | 95 | # identify the keys | 
|---|
|  | 96 |  | 
|---|
|  | 97 | series = set() | 
|---|
|  | 98 | fields = set() | 
|---|
|  | 99 |  | 
|---|
|  | 100 | for entry in data: | 
|---|
|  | 101 | series.add(entry[0]) | 
|---|
|  | 102 | for label in entry[2].keys(): | 
|---|
|  | 103 | fields.add(label) | 
|---|
|  | 104 |  | 
|---|
|  | 105 | print(series) | 
|---|
|  | 106 | print("fields") | 
|---|
|  | 107 | for f in fields: | 
|---|
| [44706d1] | 108 | print("{}".format(f)) | 
|---|
| [0bb691b1] | 109 |  | 
|---|
| [44706d1] | 110 | plot(data, "Number of processors", "ns per ops") | 
|---|