-
Notifications
You must be signed in to change notification settings - Fork 0
/
genPowGraph.py
executable file
·258 lines (224 loc) · 8.25 KB
/
genPowGraph.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
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
255
256
257
258
#!/usr/bin/python
#============================================================#
# Python 2.7.x
# Run as follows: python read_temperatures.py xe-matrix-vector.*
#============================================================#
#General imports.
from __future__ import print_function
import collections; #for OrderedDicts.
import datetime; #For recording script speed data.
import re #Regex for parsing files.
import os #For movie writer stall workaround.
import sys #For passed in arguments.
import pylab
#============================================================#
#Delimiter Characters
prefix_temperatures = "\[RMD_TRACE_POWER\]" #prefix delimiter.
#============================================================#
#Dictionary to temperatures where key='cycle' and value='temperature matrix'.
data = collections.OrderedDict();
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
# Globals
blk_width = 0;
blk_height = 0;
unt_width = 0;
unt_height = 0;
def get_hms(seconds):
minutes = seconds/60;
seconds -= minutes*60;
hours = minutes/60;
minutes -= hours*60;
return [hours, minutes, seconds];
#============================================================#
def parse_temperatures(logfile):
#{
global blk_width, blk_height, unt_width, unt_height;
eprint( "Parsing file " + logfile + "...")
#Figure out layout id.
tuple = re.findall(r'brd\d+.chp\d+.unt\d+.blk\d+.*', logfile);
if(len(tuple) == 0):
return;
tuple = re.findall(r'\d+', tuple[0]);
brd = int(tuple[0]); chp = int(tuple[1]);
unt = int(tuple[2]); blk = int(tuple[3]);
#compute row and column numbers for the given id.
col = blk%blk_width + unt%unt_width*blk_width;
row = blk/blk_width + unt/unt_width*blk_width;
datafile = file(logfile);
for line in datafile: #iterate each line of file.
#{
for string in re.findall(prefix_temperatures+" Power (.*)", line): #iterate each encapsulated string in line.
tuple = re.findall(r'\d+[.]*\d*', string);
temperature = float(tuple[0]); cycle = int(float(tuple[1]));
if(row >= blk_height*unt_height or col >= blk_width*unt_width):
continue;
if cycle in data:
data[cycle][row, col] = temperature;
else:
data[cycle] = pylab.np.empty((blk_height*unt_height, blk_width*unt_width));
data[cycle].fill(0);
data[cycle][row, col] = temperature;
#}
#}
#============================================================#
def parse_dimensions(logfile):
#{
global blk_width, blk_height, unt_width, unt_height;
#Figure out layout id.
tuple = re.findall(r'brd\d+.chp\d+.unt\d+.blk\d+.*', logfile);
if(len(tuple) == 0):
return;
datafile = file(logfile);
for line in datafile: #iterate each line of file.
#{
for line in re.findall(prefix_temperatures+" Simulated (.*)", line): #iterate each encapsulated string in line.
tuple = re.findall(r'.\d+', line);
if "block layout" in line:
blk_width = int(tuple[0]);
blk_height = int(tuple[1]);
elif "unit layout" in line:
unt_width = int(tuple[0]);
unt_height = int(tuple[1]);
#}
#}
CLOCK_SPEED = 4200.0*1e3
def avg_temps():
#{
print ("Power Over Time")
print ( "time (ms) , Power (W)")
for cycle in data:
#{
accum = 0.0
for row in range(0, blk_width*unt_width):
for col in range(0, blk_height*unt_height):
accum = accum + data[cycle][row,col]
print ( cycle/CLOCK_SPEED, ",", accum)
#}
#}
#============================================================#
#def animation_update(data, ax, last_cycle, stdout):
##{
# #Set data.
# ax.set_title(title%data[0]);
#
# ax.collections = [];
# ret = ax.pcolormesh(data[1], vmin=min_temperature, vmax=max_temperature, edgecolors='black', linewidth=1.5, cmap=mycmap);
#
# #Get estimate time to finish.
# time_elapsed = datetime.datetime.now() - begin_time;
# percent_complete = (data[0]/last_cycle);
# seconds_elapsed = int(time_elapsed.total_seconds());
# t1 = get_hms(seconds_elapsed); #elapsed time.
# if (percent_complete>0.005):
# #{
# t2 = get_hms(int(seconds_elapsed * (1/percent_complete-1))); #ETA.
# stdout.write("\rPercent done {:.2f}% (Elapsed Time: {:02}:{:02}:{:02}) (ETA: {:02}:{:02}:{:02})"
# .format(percent_complete*100, t1[0], t1[1], t1[2], t2[0], t2[1], t2[2]));
# stdout.flush();
# #}
# else:
# #{
# stdout.write("\rPercent done {:.2f}% (Elapsed Time: {:02}:{:02}:{:02}) (ETA: ...)"
# .format(percent_complete*100, t1[0], t1[1], t1[2]));
# stdout.flush();
# #}
#
# return ret;
##}
#============================================================#
#def create_graph():
##{
# global blk_width, blk_height, unt_width, unt_height;
#
# #Create figure.
# fig = matplotlib.pyplot.figure();
#
# #Figure out max length and specify file name format.
# digit_length = len(str(max(data.iterkeys())));
# format = "block-heat-%%0%dd.png" %(digit_length);
#
# # Using contourf to provide my colorbar info, then clearing the figure
# Z = [[0,0],[0,0]];
# levels = range(min_temperature,max_temperature+step,step);
# color_bar = matplotlib.pyplot.contourf(Z, levels, cmap=mycmap);
# matplotlib.pyplot.clf();
#
# #Add temperature range scale.
# fig.subplots_adjust(right=0.8);
# colorbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7]);
# fig.colorbar(color_bar, cax=colorbar_ax).set_label(temperature_units);
#
# #Create axes and set it up.
# ##Need to specify limits below or some installations of matplotlib won't create the mesh correctly.
# ax = fig.add_subplot(111, xlim=[0,blk_width*unt_width],ylim=[0,blk_height*unt_height]);
#
# #Order the blocks so that the first is on top-left.
# ax.invert_yaxis();
# ax.xaxis.tick_top();
#
# #Disable Tick text.
# ax.set_xticklabels([], minor=False);
# ax.set_yticklabels([], minor=False);
#
# # Workaround for non-'_file' encoders which stall because stderr stdout PIPE buffers filling...
# stdout = sys.stdout;
# matplotlib.verbose.level = "debug";
# sys.stdout = matplotlib.verbose.fileo = open(os.devnull, 'w');
#
# anim = matplotlib.animation.FuncAnimation(fig, animation_update, data.items(), fargs=[ax, float(data.keys()[-1]), stdout], interval =500);
#
# # Set up formatting for the movie files
# for encoder in matplotlib.animation.writers.list():
# #{
# #encode.
# Writer = matplotlib.animation.writers[encoder];
# writer = Writer(fps=2);
# anim.save('block-heat.mp4', writer=writer);
#
# break;
# #}
# #}
#
# # Workaround for non-'_file' encoders which stall because stderr stdout PIPE buffers filling...
# sys.stdout = stdout;
#
# print;
#}
#============================================================#
#============================================================#
#if len(matplotlib.animation.writers.list()) == 0:
#{
# print "Error generating plot, please install MEncoder or FFMpeg...";
# sys.exit();
#}
begin_time = datetime.datetime.now();
eprint( "Generating graph...");
blk_width = 4;
blk_height = 4;
unt_width = 4;
unt_height = 4;
if (blk_width == 0 or blk_height == 0):
#{
eprint( "Error: invalid block dimensions of {} by {} specified!".format(blk_width, blk_height));
exit(0);
#}
if (unt_width == 0 or unt_height == 0):
#{
eprint( "Error: invalid unit dimensions of {} by {} specified!".format(unt_width, unt_height));
exit(0);
#}
eprint( "Block layout: {} by {}...".format(blk_width, blk_height));
eprint( "Unit layout: {} by {}...".format(unt_width, unt_height));
for arg in sys.argv:
#{
parse_temperatures(arg);
#}
max_cycle = str(max(data.iterkeys()));
#print "Last cycle:", max_cycle
avg_temps()
#create_graph();
end_time = datetime.datetime.now();
t = get_hms(int((end_time - begin_time).total_seconds()));
eprint( "Time to generate graph : {:02}:{:02}:{:02}...".format(t[0], t[1], t[2]));
#============================================================#