llvm-capstone/llvm/utils/merge-stats.py
Tobias Hieta b71edfaa4e
[NFC][Py Reformat] Reformat python files in llvm
This is the first commit in a series that will reformat
all the python files in the LLVM repository.

Reformatting is done with `black`.

See more information here:

https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Reviewed By: jhenderson, JDevlieghere, MatzeB

Differential Revision: https://reviews.llvm.org/D150545
2023-05-17 10:48:52 +02:00

33 lines
788 B
Python
Executable File

#!/usr/bin/env python3
"""
Merge .stats files generated by llvm tools
merge-stats.py takes as argument a list of stats files to merge
and output the result on stdout
Usage:
merge-stats.py $(find ./builddir/ -name "*.stats") > total.stats
"""
import json
import sys
result = {}
for arg in range(1, len(sys.argv)):
with open(sys.argv[arg], "r", encoding="utf-8", errors="ignore") as f:
text = f.read()
try:
data = json.loads(text)
except:
print("ignored %s: failed to parse" % sys.argv[arg], file=sys.stderr)
continue
for key in data:
if key in result:
result[key] += data[key]
else:
result[key] = data[key]
out = json.dumps(result, indent=2)
print(out)