3
3
# See LICENSE.TXT
4
4
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5
5
6
+ import re
6
7
import matplotlib .pyplot as plt
7
8
import mpld3
8
9
from collections import defaultdict
@@ -67,12 +68,22 @@ def prepare_normalized_data(latest_results: dict[str, LatestResults],
67
68
return normalized_data
68
69
69
70
def format_benchmark_label (label : str ) -> list [str ]:
70
- words = label .split ()
71
- if len ( words ) <= 2 :
72
- return [ label ]
71
+ words = re .split (' |_' , label )
72
+ lines = []
73
+ current_line = [ ]
73
74
74
- mid = len (words ) // 2
75
- return [' ' .join (words [:mid ]), ' ' .join (words [mid :])]
75
+ # max line length 30
76
+ for word in words :
77
+ if len (' ' .join (current_line + [word ])) > 30 :
78
+ lines .append (' ' .join (current_line ))
79
+ current_line = [word ]
80
+ else :
81
+ current_line .append (word )
82
+
83
+ if current_line :
84
+ lines .append (' ' .join (current_line ))
85
+
86
+ return lines
76
87
77
88
def create_bar_plot (ax : plt .Axes ,
78
89
normalized_data : list [list [float ]],
@@ -109,9 +120,8 @@ def create_bar_plot(ax: plt.Axes,
109
120
110
121
tooltip_labels = [
111
122
f"Run: { run_name } \n "
112
- f"Benchmark: { benchmark_label } \n "
113
123
f"Value: { current_value :.2f} { unit } \n "
114
- f"Baseline ({ baseline_name } ): { baseline_value :.2f} { unit } \n "
124
+ f"Normalized to ({ baseline_name } ): { baseline_value :.2f} { unit } \n "
115
125
f"Normalized: { value :.1f} %"
116
126
]
117
127
tooltip = mpld3 .plugins .LineHTMLTooltip (rect , tooltip_labels , css = '.mpld3-tooltip{background:white;padding:8px;border:1px solid #ddd;border-radius:4px;font-family:monospace;white-space:pre;}' )
@@ -141,6 +151,37 @@ def add_chart_elements(ax: plt.Axes,
141
151
ax .grid (True , axis = 'y' , alpha = 0.2 )
142
152
ax .legend (bbox_to_anchor = (1 , 1 ), loc = 'upper left' )
143
153
154
+ def split_large_groups (benchmark_groups ):
155
+ miscellaneous = []
156
+ new_groups = defaultdict (list )
157
+
158
+ split_happened = False
159
+ for group , labels in benchmark_groups .items ():
160
+ if len (labels ) == 1 :
161
+ miscellaneous .extend (labels )
162
+ elif len (labels ) > 5 :
163
+ split_happened = True
164
+ mid = len (labels ) // 2
165
+ new_groups [group ] = labels [:mid ]
166
+ new_groups [group + '_' ] = labels [mid :]
167
+ else :
168
+ new_groups [group ] = labels
169
+
170
+ if miscellaneous :
171
+ new_groups ['Miscellaneous' ] = miscellaneous
172
+
173
+ if split_happened :
174
+ return split_large_groups (new_groups )
175
+ else :
176
+ return new_groups
177
+
178
+ def group_benchmark_labels (benchmark_labels ):
179
+ benchmark_groups = defaultdict (list )
180
+ for label in benchmark_labels :
181
+ group = re .match (r'^[^_\s]+' , label )[0 ]
182
+ benchmark_groups [group ].append (label )
183
+ return split_large_groups (benchmark_groups )
184
+
144
185
def create_normalized_bar_chart (benchmarks : list [BenchmarkSeries ], baseline_name : str ) -> list [str ]:
145
186
latest_results = get_latest_results (benchmarks )
146
187
@@ -154,10 +195,7 @@ def create_normalized_bar_chart(benchmarks: list[BenchmarkSeries], baseline_name
154
195
155
196
benchmark_labels = [b .label for b in benchmarks ]
156
197
157
- benchmark_groups = defaultdict (list )
158
- for label in benchmark_labels :
159
- group_name = label .split ()[0 ]
160
- benchmark_groups [group_name ].append (label )
198
+ benchmark_groups = group_benchmark_labels (benchmark_labels )
161
199
162
200
html_charts = []
163
201
0 commit comments