Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/plot.py

    r41a6a78 r76f5e9f  
    1414import math
    1515import numpy
    16 import os
    1716import re
    1817import statistics
    1918import sys
    20 import time
    2119
    22 import matplotlib
    2320import matplotlib.pyplot as plt
    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"
     21from matplotlib.ticker import EngFormatter
    3322
    3423class Field:
    35         def __init__(self, unit, _min, _log, _name=None, _factor=1.0):
     24        def __init__(self, unit, _min, _log, _name=None):
    3625                self.unit = unit
    3726                self.min  = _min
    3827                self.log  = _log
    3928                self.name = _name
    40                 self.factor = _factor
    4129
    4230field_names = {
    4331        "ns per ops"            : Field('ns'    , 0, False),
    44         "Number of processors"  : Field(''      , 1, "exact"),
     32        "Number of processors"  : Field(''      , 1, False),
    4533        "Ops per procs"         : Field('Ops'   , 0, False),
    4634        "Ops per threads"       : Field('Ops'   , 0, False),
    47         "ns per ops/procs"      : Field(''      , 0, False, _name = "ns $\\times$ (Processor $/$ Total Ops)" ),
     35        "ns per ops/procs"      : Field(''    , 0, False, _name = "Latency (ns $/$ (Processor $\\times$ Operation))" ),
    4836        "Number of threads"     : Field(''      , 1, False),
    4937        "Total Operations(ops)" : Field('Ops'   , 0, False),
    5038        "Ops/sec/procs"         : Field('Ops'   , 0, False),
    5139        "Total blocks"          : Field('Blocks', 0, False),
    52         "Ops per second"        : Field(''      , 0, False),
     40        "Ops per second"        : Field(''   , 0, False),
    5341        "Cycle size (# thrds)"  : Field('thrd'  , 1, False),
    5442        "Duration (ms)"         : Field('ms'    , 0, False),
    5543        "Target QPS"            : Field(''      , 0, False),
    5644        "Actual QPS"            : 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),
     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),
    6752}
    6853
    69 def plot(in_data, x, y, options, prefix):
     54def plot(in_data, x, y, options):
    7055        fig, ax = plt.subplots()
    71         colors = itertools.cycle(['#006cb4','#0aa000','#ff6600','#8510a1','#0095e3','#fd8f00','#e30002','#8f00d6','#4b009a','#ffff00','#69df00','#fb0300','#b13f00'])
     56        colors = itertools.cycle(['#0095e3','#006cb4','#69df00','#0aa000','#fb0300','#e30002','#fd8f00','#ff7f00','#8f00d6','#4b009a','#ffff00','#b13f00'])
    7257        series = {} # scatter data for each individual data point
    7358        groups = {} # data points for x value
     
    7762        for entry in in_data:
    7863                name = entry[0]
    79                 if options.filter and not name.startswith(options.filter):
    80                         continue
    81 
    8264                if not name in series:
    8365                        series[name] = {'x':[], 'y':[]}
     
    8870                if x in entry[2] and y in entry[2]:
    8971                        xval = entry[2][x]
    90                         yval = entry[2][y] * field_names[y].factor
     72                        yval = entry[2][y]
    9173                        series[name]['x'].append(xval)
    9274                        series[name]['y'].append(yval)
     
    11698        for name, data in sorted(series.items()):
    11799                _col = next(colors)
    118                 plt.scatter(data['x'], data['y'], color=_col, label=name[len(prefix):], marker='x')
     100                plt.scatter(data['x'], data['y'], color=_col, label=name, marker='x')
    119101                plt.plot(lines[name]['x'], lines[name]['min'], '--', color=_col)
    120102                plt.plot(lines[name]['x'], lines[name]['max'], '--', color=_col)
     
    137119        elif field_names[x].log:
    138120                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)
    146121        else:
    147122                plt.xlim(field_names[x].min, mx + 0.25)
    148123
     124        ax.yaxis.set_major_formatter( EngFormatter(unit=field_names[y].unit) )
    149125        if options.logy:
    150126                ax.set_yscale('log')
     
    154130                plt.ylim(field_names[y].min, options.MaxY if options.MaxY else my*1.2)
    155131
    156         ax.yaxis.set_major_formatter( EngFormatter(unit=field_names[y].unit) )
    157 
    158132        plt.legend(loc='upper left')
    159133
    160134        print("Results Ready")
    161         start = time.time()
    162135        if options.out:
    163136                plt.savefig(options.out, bbox_inches='tight')
    164137        else:
    165138                plt.show()
    166         end = time.time()
    167         print("Took {}".format(fmtDur(end - start)))
    168139
    169140
     
    179150        parser.add_argument('--logy', action='store_true', help="if set, makes the y-axis logscale")
    180151        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")
    182152
    183153        options =  parser.parse_args()
    184 
    185         # if not options.out:
    186         #       matplotlib.use('SVG')
    187154
    188155        # ================================================================================
     
    206173                        fields.add(label)
    207174
    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 
    215175        if not options.out :
    216176                print(series)
     
    233193
    234194
    235         plot(data, wantx, wanty, options, prefix)
     195        plot(data, wantx, wanty, options)
Note: See TracChangeset for help on using the changeset viewer.