-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkmap.py
More file actions
55 lines (50 loc) · 1.84 KB
/
linkmap.py
File metadata and controls
55 lines (50 loc) · 1.84 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
if __name__ == '__main__':
import sys, os
filenameArray = []
no_dir = 1
if len(sys.argv) > 1:
# walk around
no_dir = 0
rootDir = sys.argv[2]
for root, dirs, files in os.walk(rootDir):
for filespath in files:
if filespath.endswith(".m") or filespath.endswith(".mm") or filespath.endswith(".cpp"):
# print(filespath)
file_parts = os.path.splitext(filespath)
filenameArray.append(file_parts[0])
parseState = 0
oDict = {}
sizeDict = {}
for line in open(sys.argv[1]):
if line.startswith(r"# Object files:"):
parseState = 1
elif line.startswith(r"# Address Size File Name"):
parseState = 2
elif line.startswith("#"):
parseState = 0
elif parseState == 1:
parts = line.split("] /")
if len(parts) > 1:
filename = os.path.basename(parts[1])
file_parts = os.path.splitext(filename)
if no_dir == 1:
oDict[parts[0]] = file_parts[0]
else:
if file_parts[0] in filenameArray:
oDict[parts[0]] = file_parts[0]
elif parseState == 2:
parts = line.split("\t")
if len(parts) < 3:
continue
fileno = parts[2].split("] ")[0]
if oDict.has_key(fileno):
filename = oDict[fileno]
size = int(parts[1], 0)
if sizeDict.has_key(filename):
sizeDict[filename] += size
else:
sizeDict[filename] = size
import operator
sorted_sizeDict = sorted(sizeDict.items(), key=operator.itemgetter(1), reverse=True)
for item in sorted_sizeDict:
print item