Newer
Older
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/usr/bin/python3.5
# This Python file uses the following encoding: utf-8
#Télécharger matplotlib, PIL, et numpy
import re
import string
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import math
import PIL
from PIL import Image
import sys
if (len(sys.argv)!=2) :
print("Mettez en paramètre le fichier de statistique")
quit()
integrity = re.compile("instr_agent_(\w*)_\d+_\d+\.txt")
check = integrity.search(sys.argv[1])
print(sys.argv[1])
if check == None :
print("Mauvais paramètre "+sys.argv[1])
quit()
fichier_instruction = open(sys.argv[1])
lines = fichier_instruction.readlines()
rom = check.group(1)
print(rom)
#Les regexps pour capturer les registres et les index des registres
R = re.compile("R\[(\d+)\]")
M = re.compile("M\[(\d+)\]")
I = re.compile("I\[(\d+)\]")
O = re.compile("O\[(\d+)\]")
#Pour des pourcentages pour les figures
output_total = 0
memory_total = 0
register_total = 0
operation_total = 0
#Les dictionnaires pour stocker les index des registres et leur nombre d'occurences dans le programme
registerR = {}
registerM = {}
inputI = {}
registerO = {}
#Le dictionnaire des opérations
operations = {"nop":0," + ":0," - ":0,"max":0,"min":0,"-(":0,"*":0,"/":0,"log":0,"exp":0,"cos":0,"sin":0,"popcount":0,"if":0,"goto":0}
#print(operations)
#Boucle de capture
for line in lines :
line.lstrip()
line.rstrip('\n')
operation_total+=1
#Détecte les cases registres utilisées
catchR = R.findall(line)
if catchR != [] :
#print(catchR)
for num in catchR :
if num in registerR :
registerR[num] = registerR[num]+1
else :
registerR[num] = 1
register_total+=1
#Détecte les cases mémoire utilisées
catchM = M.findall(line)
if catchM != [] :
#print(catchM)
for num in catchM :
if num in registerM :
registerM[num] = registerM[num]+1
else :
registerM[num] = 1
memory_total+=1
#Détecte les cases input utilisées
catchI = I.findall(line)
if catchI != [] :
#print(catchI)
for num in catchI :
if num in inputI :
inputI[num] = inputI[num]+1
else :
inputI[num] = 1
#Détecte les cases output utilisées
catchO = O.findall(line)
if catchO != [] :
#print(catchO)
for num in catchO :
if num in registerO :
registerO[num] = registerO[num]+1
else :
registerO[num] = 1
output_total+=1
#Détecte les opérations appliquées
for op in operations:
if op in line:
operations[op]= operations[op]+1
#Nécessaire pour différencier les if, if_goto et +
operations['if']-=operations['goto']
operations[' + ']-=operations['goto']
#print(registerO)
#print(registerO.keys())
#print(registerO.values())
#Traitement pour rendre les outputs plus clair
trueO = list(registerO.keys())
i=0
while i < len(trueO) :
if trueO[i] == '0' :
trueO[i] = 'nope'
elif trueO[i] == '1' :
trueO[i] = 'fire'
elif trueO[i] == '2' :
trueO[i] = 'up'
elif trueO[i] == '3' :
trueO[i] = 'right'
elif trueO[i] == '4' :
trueO[i] = 'left'
elif trueO[i] == '5' :
trueO[i] = 'down'
elif trueO[i] == '6' :
trueO[i] = 'upright'
elif trueO[i] == '7' :
trueO[i] = 'upleft'
elif trueO[i] == '8' :
trueO[i] = 'downright'
elif trueO[i] == '9' :
trueO[i] = 'downleft'
elif trueO[i] == '10' :
trueO[i] = 'upfire'
elif trueO[i] == '11' :
trueO[i] = 'rightfire'
elif trueO[i] == '12' :
trueO[i] = 'leftfire'
elif trueO[i] == '13' :
trueO[i] = 'downfire'
elif trueO[i] == '14' :
trueO[i] = 'uprightfire'
elif trueO[i] == '15' :
trueO[i] = 'upleftfire'
elif trueO[i] == '16' :
trueO[i] = 'downrightfire'
elif trueO[i] == '17' :
trueO[i] = 'downleftfire'
i+=1
print(trueO)
#Traitement pour avoir des pourcentages
trueO_values = list(registerO.values())
for i in range(len(trueO_values)) :
trueO_values[i]=(trueO_values[i]/output_total)*100
R_values = list(registerR.values())
for i in range(len(R_values)):
R_values[i] = (R_values[i]/register_total)*100
M_values = list(registerM.values())
for i in range(len(M_values)) :
M_values[i] = (M_values[i]/memory_total)*100
op_values = list(operations.values())
for i in range(len(op_values)) :
op_values[i] = (op_values[i]/operation_total)*100
figO,axO = plt.subplots(2,1,figsize=(21, 27)) #figsize à ajuster pour modifier la taille des graphiques
plt.subplots_adjust(wspace=0.5,hspace=0.8)
axO[0].bar(trueO,trueO_values)
axO[0].set(xlabel = "Used Output Registers", ylabel = "Number of use (%)", title = "General Use of the Output Registers")
axO[1].barh(list(operations.keys()),op_values)
axO[1].set(xlabel = "Number of use (%)", ylabel = "Used Operations", title = "General Use of the Operations")
plt.show()
figR,axR = plt.subplots(2,1,figsize=(21,27))
plt.subplots_adjust(wspace=0.5,hspace=0.8)
axR[0].bar(list(registerR.keys()),R_values)
axR[0].set(xlabel = "Used Registers", ylabel = "Number of use (%)", title = "General Use of the short-term Registers")
axR[1].bar(list(registerM.keys()),M_values)
axR[1].set(xlabel = "Used Registers", ylabel = "Number of use (%)", title = "General Use of the long-term Registers")
plt.show()
#Traitement des images
#Création de la matrice 210x160
matrice_image = [[0 for x in range(160)] for y in range(210)]
max_input = max(inputI.values())
#print(max_input)
#On remplit la matrice
for inp,use in inputI.items() :
#print(inp)
aux1 = int(int(inp)/32)
h = aux1*5
#print(aux1)
aux2 = int(inp) - aux1*32
w = aux2*5
#print(aux2)
for i in np.arange(h,h+5,1.0) :
for j in np.arange(w,w+5,1.0) :
matrice_image[int(i)][int(j)]= (use/max_input)
#print(matrice_image)
#import resizeimage
image = Image.open("captures/"+rom+".png")
result1 = Image.new(image.mode,image.size)
result2 = Image.new(image.mode,image.size)
#On noircit les pixels non considérés par l'algorithme
for i in range(160) :
for j in range(210) :
if matrice_image[j][i] == 0 :
p=(0,0,0,255)
result1.putpixel((j,i),p)
else :
pixel=image.getpixel((j,i))
p = (255-pixel[0],255-pixel[1],255-pixel[2],255)
result1.putpixel((j,i),p)
result1 = result1.resize((420,320),Image.ANTIALIAS)
result1.show()
result1.save(fichier_instruction.name+"_scope.png")
#On met en rouge les pixels non vus et on pondère les valeurs RGB selon le maximum de l'utilisation d'un input
for i in range(160) :
for j in range(210) :
if matrice_image[j][i] == 0 :
p=(255,0,0,255)
result2.putpixel((j,i),p)
else :
pixel=image.getpixel((j,i))
percent = matrice_image[j][i]
p = (int((255-pixel[0])*percent),int((255-pixel[1])*percent),int((255-pixel[2])*percent))
result2.putpixel((j,i),p)
result2 = result2.resize((420,320),Image.ANTIALIAS)
result2.show()
result2.save(fichier_instruction.name+"_scope_ponderation.png")