diff options
| author | Mingming Liu <mingmingl@google.com> | 2025-09-10 15:25:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-10 15:25:31 -0700 |
| commit | 1417dafa1db9cb1b2b09438aa9f53ea5ab6e36e2 (patch) | |
| tree | 57f4b1f313c8cf74eed8819870f39c36ea263c68 /libcxx/utils/parse-google-benchmark-results | |
| parent | 898b813bc8a6d0276bf0f4769f5f2f64b34e632d (diff) | |
| parent | b8cefcb601ddaa18482555c4ff363c01a270c2fe (diff) | |
Merge branch 'main' into users/mingmingl-llvm/samplefdo-profile-formatusers/mingmingl-llvm/samplefdo-profile-format
Diffstat (limited to 'libcxx/utils/parse-google-benchmark-results')
| -rwxr-xr-x | libcxx/utils/parse-google-benchmark-results | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/libcxx/utils/parse-google-benchmark-results b/libcxx/utils/parse-google-benchmark-results new file mode 100755 index 000000000000..280c8045db6c --- /dev/null +++ b/libcxx/utils/parse-google-benchmark-results @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 + +import argparse +import csv +import json +import sys + +def main(argv): + parser = argparse.ArgumentParser( + prog='parse-google-benchmark-results', + description='Parse Google Benchmark result files (in JSON format) into CSV or LNT compatible output.') + parser.add_argument('filename', type=argparse.FileType('r'), nargs='+', + help='One of more JSON files to extract the results from. The results parsed from each ' + 'file are concatenated together.') + parser.add_argument('--timing', type=str, choices=['real_time', 'cpu_time'], default='real_time', + help='The timing to extract from the Google Benchmark results. This can either be the ' + '"real time" or the "CPU time". Default is "real time".') + parser.add_argument('--output-format', type=str, choices=['csv', 'lnt'], default='csv', + help='The desired output format for the data. `csv` is CSV format and `lnt` is a format compatible with ' + '`lnt importreport` (see https://llvm.org/docs/lnt/importing_data.html#importing-data-in-a-text-file).') + args = parser.parse_args(argv) + + # Parse the data from all files, aggregating the results + headers = ['Benchmark', args.timing] + rows = [] + for file in args.filename: + js = json.load(file) + for bm in js['benchmarks']: + row = [bm['name'], bm[args.timing]] + rows.append(row) + + # Print the results in the right format + if args.output_format == 'csv': + writer = csv.writer(sys.stdout) + writer.writerow(headers) + for row in rows: + writer.writerow(row) + elif args.output_format == 'lnt': + benchmark = headers.index('Benchmark') + time = headers.index(args.timing) + for row in rows: + print(f'{row[benchmark].replace(".", "_")}.execution_time {row[time]}') + +if __name__ == '__main__': + main(sys.argv[1:]) |
