-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.py
executable file
·40 lines (31 loc) · 1.24 KB
/
stats.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
34
35
36
37
38
39
40
#!/usr/bin/env python
# stats.py - calling context tree stats.
import argparse
from collections import defaultdict
import json
from cct import CCT, Function
def _loadCCT(file):
with open (file, 'r') as inFile:
data = inFile.read()
return CCT.fromRecord(data)
def _countFunctionCallNames(subtree, functionNameCount):
for function in subtree.calls:
functionNameCount[function.name] += 1
_countFunctionCallNames(function, functionNameCount)
def _topCalledFunctionCallNames(cct, count):
functionNamesCount = defaultdict(int)
_countFunctionCallNames(cct, functionNamesCount)
sortedFunctionNameCount = [(functionNamesCount[name], name) for name in functionNamesCount]
sortedFunctionNameCount.sort()
sortedFunctionNameCount.reverse()
return sortedFunctionNameCount[:count]
def main():
parser = argparse.ArgumentParser(description="Calling context tree stats")
parser.add_argument("recording", help="Calling context tree recording")
args = parser.parse_args()
cct = _loadCCT(args.recording)
print "Top called functions:"
for count, functionName in _topCalledFunctionCallNames(cct, 100):
print "{:12}".format(count) + " " + functionName
if __name__ == "__main__":
main()