@@ -112,7 +112,7 @@ def truncate_lines(string, n, marker=None):
112112 assert len (truncated ) <= n , "broken post-condition"
113113 return '\n ' .join (truncated )
114114
115- def create_plot (data , metric , subtitle = None ):
115+ def create_plot (data , metric , trendline = None , subtitle = None ):
116116 """
117117 Create a plot object showing the evolution of each benchmark throughout the given commits for
118118 the given metric.
@@ -126,7 +126,7 @@ def create_plot(data, metric, subtitle=None):
126126 symbol = 'benchmark' ,
127127 color = 'benchmark' ,
128128 hover_name = [hover_info [c ] for c in data ['commit' ]],
129- trendline = "lowess" )
129+ trendline = trendline )
130130 return figure
131131
132132def directory_path (string ):
@@ -221,6 +221,10 @@ def main(argv):
221221 parser .add_argument ('--open' , action = 'store_true' ,
222222 help = 'Whether to automatically open the generated HTML file when finished. If no output file is provided, '
223223 'the resulting benchmark is opened automatically by default.' )
224+ parser .add_argument ('--trendline' , type = str , required = False , default = None , choices = ('ols' , 'lowess' , 'expanding' ),
225+ help = 'Optional trendline to add on each series in the chart. See the documentation in '
226+ 'https://plotly.com/python-api-reference/generated/plotly.express.trendline_functions.html '
227+ 'details on each option.' )
224228 args = parser .parse_args (argv )
225229
226230 # Extract benchmark data from the directory.
@@ -250,9 +254,11 @@ def main(argv):
250254 if args .filter is not None :
251255 keeplist = [b for b in data ['benchmark' ] if re .search (args .filter , b ) is not None ]
252256 data = data [data ['benchmark' ].isin (keeplist )]
257+ if len (data ) == 0 :
258+ raise RuntimeError (f'Filter "{ args .filter } " resulted in empty data set -- nothing to plot' )
253259
254260 # Plot the data for all the required benchmarks.
255- figure = create_plot (data , args .metric , subtitle = args .subtitle )
261+ figure = create_plot (data , args .metric , trendline = args . trendline , subtitle = args .subtitle )
256262 do_open = args .output is None or args .open
257263 output = args .output if args .output is not None else tempfile .NamedTemporaryFile (suffix = '.html' ).name
258264 plotly .io .write_html (figure , file = output , auto_open = do_open )
0 commit comments