11import matplotlib.pyplot
as plt
12from matplotlib.backends.backend_pdf
import PdfPages
as pdfp
17 def __init__(self, name, backend, time_unit, draw_call_count):
29 return 'Name: % s\nBackend: % s\nSeries: % s\nSeriesLabels: % s\n' % (
34 if family
not in self.
series:
35 self.
series[family] = {
'x': [],
'y': []}
60 figures.append(plt.figure(dpi=1200, frameon=
False, figsize=(11, 8.5)))
65 plt.xlabel(
'Benchmark Seed')
66 plt.ylabel(
'Time (' + self.
time_unit +
')')
72 title = self.
name +
' ' + self.
backend +
' (Cropped)'
81 plt.grid(which=
'both', axis=
'both')
83 plt.legend(fontsize=
'xx-small')
88 figures.append(plt.figure(dpi=1200, frameon=
False, figsize=(11, 8.5)))
94 plt.xlabel(
'Benchmark Seed')
95 plt.ylabel(
'Time (' + self.
time_unit +
')')
96 title = self.
name +
' ' + self.
backend +
' (Complete)'
103 plt.grid(which=
'both', axis=
'both')
105 plt.legend(fontsize=
'xx-small')
115 for family
in self.
series:
116 x_values = [
'x'] + self.
series[family][
'x']
123 y_values.append(column)
126 for line, _
in enumerate(x_values):
127 row = [x_values[line]]
128 for series, _
in enumerate(y_values):
129 row.append(y_values[series][line])
134 parser = argparse.ArgumentParser()
137 'filename', action=
'store', help=
'Path to the JSON output from Google Benchmark'
144 default=
'output.pdf',
145 help=
'Filename to output the PDF of graphs to.'
152 default=
'output.csv',
153 help=
'Filename to output the CSV data to.'
156 args = parser.parse_args()
172 attributes = [
'AntiAliasing',
'HairlineStroke',
'StrokedStyle',
'FilledStyle']
175 for attr
in attributes:
177 if benchmark_result[attr] != 0:
186 benchmark_results_data = {}
188 for benchmark_result
in benchmark_json:
190 if 'aggregate_name' in benchmark_result:
193 benchmark_variant = benchmark_result[
'name'].split(
'/')
195 benchmark_variant.remove(
'real_time')
197 splits =
len(benchmark_variant)
199 benchmark_name = benchmark_variant[0]
201 benchmark_seeded_value = benchmark_variant[splits - 1]
203 benchmark_backend = benchmark_variant[splits - 2]
205 benchmark_real_time = benchmark_result[
'real_time']
206 benchmark_unit = benchmark_result[
'time_unit']
208 benchmark_family_index = benchmark_result[
'family_index']
210 benchmark_family_label =
''
212 for i
in range(1, splits - 2):
213 benchmark_family_label += benchmark_variant[i] +
', '
217 if benchmark_family_attributes ==
'':
218 benchmark_family_label = benchmark_family_label[:-2]
220 benchmark_family_label = benchmark_family_label + benchmark_family_attributes
222 if 'DrawCallCount' in benchmark_result:
223 benchmark_draw_call_count = benchmark_result[
'DrawCallCount']
225 benchmark_draw_call_count = -1
227 optional_keys = [
'DrawCallCount_Varies',
'VerbCount',
'PointCount',
'VertexCount',
'GlyphCount']
229 if benchmark_name
not in benchmark_results_data:
231 benchmark_name, benchmark_backend, benchmark_unit, benchmark_draw_call_count
234 for key
in optional_keys:
235 if key
in benchmark_result:
236 benchmark_results_data[benchmark_name].add_optional_value(
237 key, benchmark_seeded_value, benchmark_result[key]
240 benchmark_results_data[benchmark_name].add_data_point(
241 benchmark_family_index, benchmark_seeded_value, benchmark_real_time
243 benchmark_results_data[benchmark_name].set_family_label(
244 benchmark_family_index, benchmark_family_label
247 pdf = pdfp(output_pdf)
249 csv_file = open(output_csv,
'w')
250 csv_writer = csv.writer(csv_file)
252 for benchmark
in benchmark_results_data:
253 figures = benchmark_results_data[benchmark].
plot()
256 benchmark_results_data[benchmark].write_csv(csv_writer)
262 json_file = open(filename,
'r')
264 error(
'Unable to load file.')
267 json_data = json.load(json_file)
268 except JSONDecodeError:
269 error(
'Invalid JSON. Unable to parse.')
271 return json_data[
'benchmarks']
274if __name__ ==
'__main__':
def add_data_point(self, family, xval, yval)
def add_optional_value(self, name, xval, yval)
def write_csv(self, writer)
def set_family_label(self, family, label)
def __init__(self, name, backend, time_unit, draw_call_count)
static void append(char **dst, size_t *count, const char *src, size_t n)
def extrac_attributes_label(benchmark_result)
def process_benchmark_data(benchmark_json, output_pdf, output_csv)
def print(*args, **kwargs)
static void plot(SkCanvas *canvas, const char *fn, float xMin, float xMax, float yMin, float yMax, const char *label=nullptr, bool requireES3=false)