-
Notifications
You must be signed in to change notification settings - Fork 342
/
stackcollapse.py
33 lines (23 loc) · 1.01 KB
/
stackcollapse.py
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
import argparse
import json
parser = argparse.ArgumentParser(description = 'Collapse stack trace logs to FlameGraph input file.')
parser.add_argument("--input", "-i", type=str, required=True, help="Input stack trace file")
args = parser.parse_args()
inputFile = args.input
with open(inputFile) as f:
stacktraceDict = {}
for line in f.readlines():
stacktraceLog = json.loads(line)
assert 'stacktrace' in stacktraceLog, "Malformated json. 'stacktrace' key doesn't exist."
stacktrace = stacktraceLog['stacktrace']
if len(stacktrace) == 0:
continue
assert 'count' in stacktraceLog, "Malformated json. 'count' key doesn't exist."
count = stacktraceLog['count']
key = ';'.join(list(reversed(stacktrace)))
if key in stacktraceDict:
stacktraceDict[key] += count
else:
stacktraceDict[key] = count
for stacktraceItem in stacktraceDict:
print("%s %i" % (stacktraceItem, stacktraceDict[stacktraceItem]))