Skip to content

Commit 949f5bb

Browse files
authored
Add support for JSON dumps of benchmark diff reports. (google#1042). Fixes google#737.
NOTE: This is a fresh-start of google#738 pull-request which I messed up by re-editing the commiter email which I forgot to modify before pushing. Sorry for the inconvenience. This PR brings proposed solution for functionality described in google#737 Fixes google#737.
1 parent 7efada2 commit 949f5bb

File tree

2 files changed

+507
-132
lines changed

2 files changed

+507
-132
lines changed

tools/compare.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import argparse
99
from argparse import ArgumentParser
10+
import json
1011
import sys
1112
import gbench
1213
from gbench import util, report
@@ -56,6 +57,12 @@ def create_parser():
5657
help="Do not use colors in the terminal output"
5758
)
5859

60+
parser.add_argument(
61+
'-d',
62+
'--dump_to_json',
63+
dest='dump_to_json',
64+
help="Additionally, dump benchmark comparison output to this file in JSON format.")
65+
5966
utest = parser.add_argument_group()
6067
utest.add_argument(
6168
'--no-utest',
@@ -244,14 +251,20 @@ def main():
244251
json2 = gbench.report.filter_benchmark(
245252
json2_orig, filter_contender, replacement)
246253

247-
# Diff and output
248-
output_lines = gbench.report.generate_difference_report(
249-
json1, json2, args.display_aggregates_only,
254+
diff_report = gbench.report.get_difference_report(
255+
json1, json2, args.utest)
256+
output_lines = gbench.report.print_difference_report(
257+
diff_report,
258+
args.display_aggregates_only,
250259
args.utest, args.utest_alpha, args.color)
251260
print(description)
252261
for ln in output_lines:
253262
print(ln)
254263

264+
# Optionally, diff and output to JSON
265+
if args.dump_to_json is not None:
266+
with open(args.dump_to_json, 'w') as f_json:
267+
json.dump(diff_report, f_json)
255268

256269
class TestParser(unittest.TestCase):
257270
def setUp(self):

0 commit comments

Comments
 (0)