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