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