• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
9  merge-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)):
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]
31
32out = json.dumps(result, indent=2)
33print(out)
34