[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / llvm / utils / merge-stats.py
blob342be3c9002e74e40ac83d28418bb47e01dcc126
1 #!/usr/bin/env python3
2 '''
3 Merge .stats files generated by llvm tools
5 merge-stats.py takes as argument a list of stats files to merge
6 and output the result on stdout
8 Usage:
9 merge-stats.py $(find ./builddir/ -name "*.stats") > total.stats
10 '''
12 import json
13 import sys
15 result = {}
17 for arg in range(1, len(sys.argv)):
18 with open(sys.argv[arg], "r", encoding='utf-8',
19 errors='ignore') as f:
20 text = f.read()
21 try:
22 data = json.loads(text)
23 except:
24 print('ignored %s: failed to parse' % sys.argv[arg], file= sys.stderr)
25 continue
26 for key in data:
27 if key in result:
28 result[key] += data[key]
29 else:
30 result[key] = data[key]
32 out = json.dumps(result, indent=2)
33 print(out)