-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtj.py
More file actions
76 lines (67 loc) · 2.22 KB
/
tj.py
File metadata and controls
76 lines (67 loc) · 2.22 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import sys
import os
import re
EXCLUDE_DIRS = [
"C:\\Users\\codemao\\Desktop\\workspcae\\evm\\build",
"C:\\Users\\codemao\\Desktop\\workspcae\\evm\\release",
"C:\\Users\\codemao\\Desktop\\workspcae\\evm\\libevm"
]
def getCHppFiles(rootpath):
hfiles = []
cppfiles = []
cfiles = []
for root, dirs, files in os.walk(rootpath) :
if '.git' not in root:
for f in files:
fpath = os.path.abspath(os.sep.join([root, f]))
isExclude = False
for d in EXCLUDE_DIRS:
if fpath.startswith(d):
isExclude = True
if isExclude:
# print(fpath)
continue
if fpath.endswith(".h"):
hfiles.append(fpath)
elif fpath.endswith(".cpp") or f.endswith(".c"):
cppfiles.append(fpath)
return hfiles, cppfiles
def count(path, apis):
ret = {}
with open(path, "rb") as f:
content = str(f.read())
for api in apis:
ret[api] = content.count(api)
return ret
def main():
apis = []
with open("C:\\Users\\codemao\\Desktop\\workspcae\\evm\\libevm\\evm.h", "rb") as f:
for line in f.readlines():
s = str(line)
if "evm_" in s:
x = re.search("\sevm_.*", s)
if x and "(" in x.string:
es = x.string[x.start():].split("(")[0]
# if " " not in es:
api = es.split(" ")[1]
if api not in apis:
apis.append(api)
_, cFiles = getCHppFiles("C:\\Users\\codemao\\Desktop\\workspcae\\evm\\native")
apis = apis[1:]
rets = {}
for f in cFiles:
ret = count(f, apis)
if len(rets) == 0:
rets = ret
else:
for key in ret:
rets[key] += ret[key]
# print(rets)
rets = sorted(rets.items(), key=lambda item:item[1], reverse=True)
with open("apis_call_count_third.md", "wb") as f:
for item in rets:
f.write(("%30s:%d\r\n" % (str(item[0]), item[1])).encode())
# for api in apis:
# count()
if __name__ == '__main__':
main()