Changes in benchmark/plot.py [76f5e9f:41a6a78]
- File:
-
- 1 edited
-
benchmark/plot.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
benchmark/plot.py
r76f5e9f r41a6a78 14 14 import math 15 15 import numpy 16 import os 16 17 import re 17 18 import statistics 18 19 import sys 19 20 import time 21 22 import matplotlib 20 23 import matplotlib.pyplot as plt 21 from matplotlib.ticker import EngFormatter 24 from matplotlib.ticker import EngFormatter, ScalarFormatter 25 26 def fmtDur( duration ): 27 if duration : 28 hours, rem = divmod(duration, 3600) 29 minutes, rem = divmod(rem, 60) 30 seconds, millis = divmod(rem, 1) 31 return "%2d:%02d.%03d" % (minutes, seconds, millis * 1000) 32 return " n/a" 22 33 23 34 class Field: 24 def __init__(self, unit, _min, _log, _name=None ):35 def __init__(self, unit, _min, _log, _name=None, _factor=1.0): 25 36 self.unit = unit 26 37 self.min = _min 27 38 self.log = _log 28 39 self.name = _name 40 self.factor = _factor 29 41 30 42 field_names = { 31 43 "ns per ops" : Field('ns' , 0, False), 32 "Number of processors" : Field('' , 1, False),44 "Number of processors" : Field('' , 1, "exact"), 33 45 "Ops per procs" : Field('Ops' , 0, False), 34 46 "Ops per threads" : Field('Ops' , 0, False), 35 "ns per ops/procs" : Field('' , 0, False, _name = "Latency (ns $/$ (Processor $\\times$ Operation))" ),47 "ns per ops/procs" : Field('' , 0, False, _name = "ns $\\times$ (Processor $/$ Total Ops)" ), 36 48 "Number of threads" : Field('' , 1, False), 37 49 "Total Operations(ops)" : Field('Ops' , 0, False), 38 50 "Ops/sec/procs" : Field('Ops' , 0, False), 39 51 "Total blocks" : Field('Blocks', 0, False), 40 "Ops per second" : Field('' , 0, False),52 "Ops per second" : Field('' , 0, False), 41 53 "Cycle size (# thrds)" : Field('thrd' , 1, False), 42 54 "Duration (ms)" : Field('ms' , 0, False), 43 55 "Target QPS" : Field('' , 0, False), 44 56 "Actual QPS" : Field('' , 0, False), 45 "Average Read Latency" : Field('us' , 0, True), 46 "Median Read Latency" : Field('us' , 0, True), 47 "Tail Read Latency" : Field('us' , 0, True), 48 "Average Update Latency": Field('us' , 0, True), 49 "Median Update Latency" : Field('us' , 0, True), 50 "Tail Update Latency" : Field('us' , 0, True), 51 "Update Ratio" : Field('\%' , 0, False), 57 "Average Read Latency" : Field('s' , 0, False, _factor = 0.000001), 58 "Median Read Latency" : Field('s' , 0, True, _factor = 0.000001), 59 "Tail Read Latency" : Field('s' , 0, True, _factor = 0.000001), 60 "Average Update Latency": Field('s' , 0, True, _factor = 0.000001), 61 "Median Update Latency" : Field('s' , 0, True, _factor = 0.000001), 62 "Tail Update Latency" : Field('s' , 0, True, _factor = 0.000001), 63 "Update Ratio" : Field('%' , 0, False), 64 "Request Rate" : Field('req/s' , 0, False), 65 "Data Rate" : Field('b/s' , 0, False, _factor = 1000 * 1000, _name = "Response Throughput"), 66 "Errors" : Field('%' , 0, False), 52 67 } 53 68 54 def plot(in_data, x, y, options ):69 def plot(in_data, x, y, options, prefix): 55 70 fig, ax = plt.subplots() 56 colors = itertools.cycle(['#00 95e3','#006cb4','#69df00','#0aa000','#fb0300','#e30002','#fd8f00','#ff7f00','#8f00d6','#4b009a','#ffff00','#b13f00'])71 colors = itertools.cycle(['#006cb4','#0aa000','#ff6600','#8510a1','#0095e3','#fd8f00','#e30002','#8f00d6','#4b009a','#ffff00','#69df00','#fb0300','#b13f00']) 57 72 series = {} # scatter data for each individual data point 58 73 groups = {} # data points for x value … … 62 77 for entry in in_data: 63 78 name = entry[0] 79 if options.filter and not name.startswith(options.filter): 80 continue 81 64 82 if not name in series: 65 83 series[name] = {'x':[], 'y':[]} … … 70 88 if x in entry[2] and y in entry[2]: 71 89 xval = entry[2][x] 72 yval = entry[2][y] 90 yval = entry[2][y] * field_names[y].factor 73 91 series[name]['x'].append(xval) 74 92 series[name]['y'].append(yval) … … 98 116 for name, data in sorted(series.items()): 99 117 _col = next(colors) 100 plt.scatter(data['x'], data['y'], color=_col, label=name , marker='x')118 plt.scatter(data['x'], data['y'], color=_col, label=name[len(prefix):], marker='x') 101 119 plt.plot(lines[name]['x'], lines[name]['min'], '--', color=_col) 102 120 plt.plot(lines[name]['x'], lines[name]['max'], '--', color=_col) … … 119 137 elif field_names[x].log: 120 138 ax.set_xscale('log') 139 if field_names[x].log == "exact": 140 xvals = set() 141 for s in series.values(): 142 xvals |= set(s['x']) 143 ax.set_xticks(sorted(xvals)) 144 ax.get_xaxis().set_major_formatter(ScalarFormatter()) 145 plt.xticks(rotation = 45) 121 146 else: 122 147 plt.xlim(field_names[x].min, mx + 0.25) 123 148 124 ax.yaxis.set_major_formatter( EngFormatter(unit=field_names[y].unit) )125 149 if options.logy: 126 150 ax.set_yscale('log') … … 130 154 plt.ylim(field_names[y].min, options.MaxY if options.MaxY else my*1.2) 131 155 156 ax.yaxis.set_major_formatter( EngFormatter(unit=field_names[y].unit) ) 157 132 158 plt.legend(loc='upper left') 133 159 134 160 print("Results Ready") 161 start = time.time() 135 162 if options.out: 136 163 plt.savefig(options.out, bbox_inches='tight') 137 164 else: 138 165 plt.show() 166 end = time.time() 167 print("Took {}".format(fmtDur(end - start))) 139 168 140 169 … … 150 179 parser.add_argument('--logy', action='store_true', help="if set, makes the y-axis logscale") 151 180 parser.add_argument('--MaxY', nargs='?', type=int, help="maximum value of the y-axis") 181 parser.add_argument('--filter', nargs='?', type=str, default="", help="if not empty, only print series that start with specified filter") 152 182 153 183 options = parser.parse_args() 184 185 # if not options.out: 186 # matplotlib.use('SVG') 154 187 155 188 # ================================================================================ … … 173 206 fields.add(label) 174 207 208 # filter out the series if needed 209 if options.filter: 210 series = set(filter(lambda elem: elem.startswith(options.filter), series)) 211 212 # find the common prefix on series for removal (only if no filter) 213 prefix = os.path.commonprefix(list(series)) 214 175 215 if not options.out : 176 216 print(series) … … 193 233 194 234 195 plot(data, wantx, wanty, options )235 plot(data, wantx, wanty, options, prefix)
Note:
See TracChangeset
for help on using the changeset viewer.