1- from re import findall , search
1+ from re import findall , search , split
22import matplotlib .pyplot as plt
33from matplotlib .ticker import StrMethodFormatter
44from glob import glob
@@ -15,6 +15,7 @@ def __init__(self, filenames):
1515 if not filenames :
1616 raise PlotError ('No data to plot' )
1717
18+ filenames .sort (key = self ._natural_keys )
1819 self .results = []
1920 try :
2021 for filename in filenames :
@@ -23,6 +24,10 @@ def __init__(self, filenames):
2324 except OSError as e :
2425 raise PlotError (f'Failed to load log files: { e } ' )
2526
27+ def _natural_keys (self , text ):
28+ def try_cast (text ): return int (text ) if text .isdigit () else text
29+ return [try_cast (c ) for c in split ('(\d+)' , text )]
30+
2631 def _tps (self , data ):
2732 values = findall (r' TPS: (\d+) \+/- (\d+)' , data )
2833 values = [(int (x ), int (y )) for x , y in values ]
@@ -46,7 +51,7 @@ def _bps2tps(self, x):
4651 size = int (search (r'Transaction size: (\d+)' , data ).group (1 ))
4752 return x * 10 ** 6 / size
4853
49- def _plot (self , x_label , y_label , y_axis , z_axis , filename ):
54+ def _plot (self , x_label , y_label , y_axis , z_axis , type ):
5055 plt .figure ()
5156 for result in self .results :
5257 y_values , y_err = y_axis (result )
@@ -58,12 +63,14 @@ def _plot(self, x_label, y_label, y_axis, z_axis, filename):
5863 x_values , y_values , yerr = y_err , # uplims=True, lolims=True,
5964 marker = 'o' , label = z_axis (result ), linestyle = 'dotted'
6065 )
66+ # if type == 'latency':
67+ # plt.yscale('log')
6168
6269 plt .xlim (xmin = 0 )
6370 plt .ylim (bottom = 0 )
6471 plt .xlabel (x_label )
6572 plt .ylabel (y_label [0 ])
66- plt .legend (loc = 'upper right ' )
73+ plt .legend (loc = 'upper left ' )
6774 ax = plt .gca ()
6875 ax .xaxis .set_major_formatter (StrMethodFormatter ('{x:,.0f}' ))
6976 ax .yaxis .set_major_formatter (StrMethodFormatter ('{x:,.0f}' ))
@@ -75,7 +82,7 @@ def _plot(self, x_label, y_label, y_axis, z_axis, filename):
7582 secaxy .yaxis .set_major_formatter (StrMethodFormatter ('{x:,.0f}' ))
7683
7784 for x in ['pdf' , 'png' ]:
78- plt .savefig (PathMaker .plot_file (filename , x ), bbox_inches = 'tight' )
85+ plt .savefig (PathMaker .plot_file (type , x ), bbox_inches = 'tight' )
7986
8087 @staticmethod
8188 def nodes (data ):
@@ -86,13 +93,18 @@ def nodes(data):
8693 def tx_size (data ):
8794 return search (r'Transaction size: .*' , data ).group (0 )
8895
96+ @staticmethod
97+ def max_latency (data ):
98+ x = search (r'Max latency: (\d+)' , data ).group (1 )
99+ return f'Max latency: { float (x ) / 1000 :,.0f} s'
100+
89101 @classmethod
90102 def plot_robustness (cls , z_axis ):
91103 assert hasattr (z_axis , '__call__' )
92104 x_label = 'Input rate (tx/s)'
93105 y_label = ['Throughput (tx/s)' , 'Throughput (MB/s)' ]
94106
95- files = glob (PathMaker .agg_file (r'[0-9]*' , 'x' , r'*' ))
107+ files = glob (PathMaker .agg_file (r'[0-9]*' , 'x' , r'*' , 'any' ))
96108 ploter = cls (files )
97109 ploter ._plot (x_label , y_label , ploter ._tps , z_axis , 'robustness' )
98110
@@ -102,7 +114,7 @@ def plot_latency(cls, z_axis):
102114 x_label = 'Throughput (tx/s)'
103115 y_label = ['Latency (ms)' ]
104116
105- files = glob (PathMaker .agg_file (r'[0-9]*' , 'any' , r'*' ))
117+ files = glob (PathMaker .agg_file (r'[0-9]*' , 'any' , r'*' , 'any' ))
106118 ploter = cls (files )
107119 ploter ._plot (x_label , y_label , ploter ._latency , z_axis , 'latency' )
108120
@@ -112,6 +124,6 @@ def plot_tps(cls, z_axis):
112124 x_label = 'Committee size'
113125 y_label = ['Throughput (tx/s)' , 'Throughput (MB/s)' ]
114126
115- files = glob (PathMaker .agg_file ('x' , 'any' , r'*' ))
127+ files = glob (PathMaker .agg_file ('x' , 'any' , r'*' , r'*' ))
116128 ploter = cls (files )
117129 ploter ._plot (x_label , y_label , ploter ._tps , z_axis , 'tps' )
0 commit comments