merge hostsim in main
[aversive.git] / projects / profiling_example / parse_symbols.py
1 #!/usr/bin/python
2
3 import sys
4
5 if len(sys.argv) != 2:
6     print "Bad arguments"
7     print "Usage: parse_symbols.py file.sym"
8     sys.exit(1)
9
10 symlist=[]
11 global_cpt=0
12
13 f=open(sys.argv[1])
14
15 # parse .sym file and fill a list
16 while True:
17     l=f.readline()
18     if l=='':
19         break
20
21     address, type, name = l[:-1].split(' ')
22     if type != 'T':
23         continue
24
25     #    print "%x %s"%(int(address,16),name)
26     symlist.append([int(address, 16), name, 0])
27     
28 f.close()
29
30
31 while True:
32     l=sys.stdin.readline()
33     if l=='':
34         break
35
36     try:
37         add=int(l, 16)*2
38     except:
39         print "Bad value"
40         continue
41
42     prev = None
43     i=1
44     while i < len(symlist):
45         address, name, cpt = symlist[i]
46         if add < address:
47             symlist[i-1][2] += 1
48             global_cpt += 1
49             break
50         i+=1
51         
52     # address cannot be in last symbols, so we
53     # suppose it is not found
54     if i == len(symlist):
55         print "Cannot find symbol"
56         break
57
58 symlist.sort(cmp=lambda x,y:x[2]<y[2] and 1 or -1)
59
60 for sym in symlist:
61     address, name, cpt = sym
62     if not cpt:
63         continue
64     print "%2.2f%% (%.3d/%.3d) %s[%.8x]"%( (float(cpt)*100.)/global_cpt, cpt,
65                                            global_cpt, name, address)