Skip to content

Commit e8e149e

Browse files
committed
Add script to merge multiple -ftime-trace outputs.
1 parent b59767b commit e8e149e

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

scripts/profile-compilation-merge

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python3
2+
3+
"""Combine JSON from multiple -ftime-traces into one.
4+
5+
scripts/profile-compilation-merge foo.json bar.json.
6+
7+
results in ./combined.json
8+
"""
9+
10+
import json
11+
import sys
12+
13+
if __name__ == '__main__':
14+
start_time = 0
15+
combined_data = []
16+
for filename in sys.argv[1:]:
17+
with open(filename, 'r') as f:
18+
file_time = None
19+
for event in json.load(f)['traceEvents']:
20+
# Skip metadata events
21+
# Skip total events
22+
# Filter out shorter events to reduce data size
23+
if event['ph'] == 'M' or \
24+
event['name'].startswith('Total') or \
25+
event['dur'] < 5000:
26+
continue
27+
28+
if event['name'] == 'ExecuteCompiler':
29+
# Find how long this compilation takes
30+
file_time = event['dur']
31+
# Set the file name in ExecuteCompiler
32+
#event['args']['detail'] = filename
33+
34+
# Offset start time to make compiles sequential
35+
event['ts'] += start_time
36+
37+
# Add data to combined
38+
combined_data.append(event)
39+
40+
# Increase the start time for the next file
41+
# Add 1 to avoid issues with simultaneous events
42+
start_time += file_time + 1
43+
44+
with open('combined.json', 'w') as f:
45+
json.dump({'traceEvents': sorted(combined_data, key=lambda k: k['ts'])}, f)

0 commit comments

Comments
 (0)