source: trunk/platforms/tsar_generic_xbar/scripts/create_graphs.py @ 734

Last change on this file since 734 was 706, checked in by meunier, 10 years ago
  • Replaced vci_dspin_local_crossbar with a vci_local_crossbar in tsar_generic_xbar
  • Added the scripts/ directory in tsar_generic_xbar
  • Property svn:executable set to *
File size: 18.9 KB
Line 
1#!/usr/bin/python
2
3import subprocess
4import os
5import re
6
7
8
9apps = [ 'histogram', 'mandel', 'filter', 'radix_ga', 'fft_ga', 'kmeans' ]
10nb_procs = [ 1, 4, 8, 16, 32, 64, 128, 256 ]
11
12top_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")
13scripts_path = os.path.join(top_path, 'scripts')
14counter_defs_name = os.path.join(scripts_path, "counter_defs.py")
15
16exec(file(counter_defs_name))
17
18gen_dir = 'generated'
19graph_dir = 'graph'
20template_dir = 'templates'
21data_dir = 'data'
22
23log_init_name = 'log_init_'
24log_term_name = 'log_term_'
25
26coherence_tmpl = os.path.join(scripts_path, template_dir, 'coherence_template.gp') # 1 graph per appli
27speedup_tmpl   = os.path.join(scripts_path, template_dir, 'speedup_template.gp')
28metric_tmpl    = os.path.join(scripts_path, template_dir, 'metric_template.gp') # 1 graph per metric
29stacked_tmpl   = os.path.join(scripts_path, template_dir, 'stacked_template.gp')
30
31
32
33def create_file(name, content):
34   file = open(name, 'w')
35   file.write(content)
36   file.close()
37   
38def is_numeric(s):
39   try:
40      float(s)
41      return True
42   except ValueError:
43      return False
44
45def get_x_y(nb_procs):
46   x = 1
47   y = 1
48   to_x = True
49   while (x * y * 4 < nb_procs):
50      if to_x:
51         x = x * 2
52      else:
53         y = y * 2
54      to_x = not to_x
55   return x, y
56
57
58
59# We first fill the m_metric_id table
60for metric in all_metrics:
61   for tag in all_tags:
62      if m_metric_tag[metric] == tag:
63         m_metric_id[tag] = metric
64         break
65
66
67# We start by processing all the log files
68# Term files are processed for exec time only
69# Init files are processed for all metrics
70exec_time = {}
71metrics_val = {}
72for app in apps:
73   exec_time[app] = {}
74   metrics_val[app] = {}
75   for i in nb_procs:
76      metrics_val[app][i] = {}
77      log_init_file = os.path.join(scripts_path, data_dir, app + '_' + log_init_name + str(i))
78      log_term_file = os.path.join(scripts_path, data_dir, app + '_' + log_term_name + str(i))
79
80      # Term
81      lines = open(log_term_file, 'r')
82      for line in lines:
83         tokens = line[:-1].split()
84         if len(tokens) > 0 and tokens[0] == "[ELAPSED2]":
85            exec_time[app][i] = int(tokens[len(tokens) - 1])
86
87      # Init files
88      lines = open(log_init_file, 'r')
89      for line in lines:
90         tokens = line[:-1].split()
91         if len(tokens) == 0:
92            continue
93         tag = tokens[0]
94         value = tokens[len(tokens) - 1]
95         pattern = re.compile('\[0[0-9][0-9]\]')
96         if pattern.match(tag):
97            metric = m_metric_id[tag]
98            if (not metrics_val[app][i].has_key(metric) or tag == "[000]" or tag == "[001]"):
99               # We don't add cycles of all Memcaches (they must be the same for all)
100               metrics_val[app][i][metric] = int(value)
101            else:
102               metrics_val[app][i][metric] += int(value)
103           
104# We make a 2nd pass to fill the derived fields, e.g. nb_total_updates
105for app in apps:
106   for i in nb_procs:
107      x, y = get_x_y(i)
108      metrics_val[app][i]['total_read']     = metrics_val[app][i]['local_read']    + metrics_val[app][i]['remote_read']
109      metrics_val[app][i]['total_write']    = metrics_val[app][i]['local_write']   + metrics_val[app][i]['remote_write']
110      metrics_val[app][i]['total_ll']       = metrics_val[app][i]['local_ll']      + metrics_val[app][i]['remote_ll']
111      metrics_val[app][i]['total_sc']       = metrics_val[app][i]['local_sc']      + metrics_val[app][i]['remote_sc']
112      metrics_val[app][i]['total_cas']      = metrics_val[app][i]['local_cas']     + metrics_val[app][i]['remote_cas']
113      metrics_val[app][i]['total_update']   = metrics_val[app][i]['local_update']  + metrics_val[app][i]['remote_update']
114      metrics_val[app][i]['total_m_inv']    = metrics_val[app][i]['local_m_inv']   + metrics_val[app][i]['remote_m_inv']
115      metrics_val[app][i]['total_cleanup']  = metrics_val[app][i]['local_cleanup'] + metrics_val[app][i]['remote_cleanup']
116      metrics_val[app][i]['total_direct']   = metrics_val[app][i]['total_read']    + metrics_val[app][i]['total_write']
117      metrics_val[app][i]['direct_cost']    = metrics_val[app][i]['read_cost']     + metrics_val[app][i]['write_cost']
118      metrics_val[app][i]['broadcast_cost'] = metrics_val[app][i]['broadcast'] * (x * y - 1)
119      if metrics_val[app][i]['broadcast'] < metrics_val[app][i]['write_broadcast']:
120         # test to patch a bug in mem_cache
121         metrics_val[app][i]['nonwrite_broadcast'] = 0
122      else:
123         metrics_val[app][i]['nonwrite_broadcast'] = metrics_val[app][i]['broadcast'] - metrics_val[app][i]['write_broadcast']
124
125      metrics_val[app][i]['total_stacked'] = 0
126      for stacked_metric in stacked_metrics:
127         metrics_val[app][i]['total_stacked'] += metrics_val[app][i][stacked_metric]
128
129           
130print "mkdir -p", os.path.join(scripts_path, gen_dir)
131subprocess.call([ 'mkdir', '-p', os.path.join(scripts_path, gen_dir) ])
132
133print "mkdir -p", os.path.join(scripts_path, graph_dir)
134subprocess.call([ 'mkdir', '-p', os.path.join(scripts_path, graph_dir) ])
135
136############################################################
137### Graph 1 : Coherence traffic Cost per application     ###
138############################################################
139
140for app in apps:
141   
142   data_coherence_name = os.path.join(scripts_path, gen_dir, app + '_coherence.dat')
143   gp_coherence_name   = os.path.join(scripts_path, gen_dir, app + '_coherence.gp')
144
145   # Creating the data file
146   width = 15
147   content = ""
148   
149   for metric in [ '#nb_procs' ] + grouped_metrics:
150      content += metric + " "
151      nb_spaces = width - len(metric)
152      content += nb_spaces * ' '
153   content += "\n"
154
155   for i in nb_procs:
156      content += "%-15d " % i
157      for metric in grouped_metrics:
158         val = float(metrics_val[app][i][metric]) / exec_time[app][i] * 1000
159         content += "%-15f " % val
160      content += "\n"
161   
162   create_file(data_coherence_name, content)
163
164   # Creating the gp file
165   template_file = open(coherence_tmpl, 'r')
166   template = template_file.read()
167   
168   plot_str = ""
169   col = 2
170   for metric in grouped_metrics:
171      if metric != grouped_metrics[0]:
172         plot_str += ", \\\n    "
173      plot_str += "\"" + data_coherence_name + "\" using ($1):($" + str(col) + ") lc rgb " + colors[col - 2] + " title \"" + m_metric_name[metric] + "\" with linespoint"
174      col += 1
175   gp_commands = template % dict(app_name = m_app_name[app], nb_procs = nb_procs[-1] + 1, plot_str = plot_str, svg_name = os.path.join(graph_dir, app + '_coherence'))
176   
177   create_file(gp_coherence_name, gp_commands)
178   
179   # Calling gnuplot
180   print "gnuplot", gp_coherence_name
181   subprocess.call([ 'gnuplot', gp_coherence_name ])
182
183
184############################################################
185### Graph 2 : Speedup per Application                    ###
186############################################################
187
188for app in apps:
189
190   data_speedup_name   = os.path.join(scripts_path, gen_dir, app + '_speedup.dat')
191   gp_speedup_name     = os.path.join(scripts_path, gen_dir, app + '_speedup.gp')
192   
193   # Creating data file
194   width = 15
195   content = "#nb_procs"
196   nb_spaces = width - len(content)
197   content += nb_spaces * ' '
198   content += "speedup\n"
199
200   for i in nb_procs:
201      content += "%-15d " % i
202      val = exec_time[app][i]
203      content += "%-15f\n" % (exec_time[app][1] / float(val))
204
205   plot_str = "\"" + data_speedup_name + "\" using ($1):($2) lc rgb \"#654387\" title \"Speedup\" with linespoint"
206   
207   create_file(data_speedup_name, content)
208   
209   # Creating the gp file
210   template_file = open(speedup_tmpl, 'r')
211   template = template_file.read()
212   
213   gp_commands = template % dict(appli = m_app_name[app], nb_procs = nb_procs[-1] + 1, plot_str = plot_str, svg_name = os.path.join(graph_dir, app + '_speedup'))
214   
215   create_file(gp_speedup_name, gp_commands)
216   
217   # Calling gnuplot
218   print "gnuplot", gp_speedup_name
219   subprocess.call([ 'gnuplot', gp_speedup_name ])
220
221
222############################################################
223### Graph 3 : All speedups on the same Graph             ###
224############################################################
225
226# This graph uses the same template as the graph 2
227
228data_speedup_name = os.path.join(scripts_path, gen_dir, 'all_speedup.dat')
229gp_speedup_name   = os.path.join(scripts_path, gen_dir, 'all_speedup.gp')
230
231# Creating data file
232width = 15
233content = "#nb_procs"
234nb_spaces = width - len(content)
235content += (nb_spaces + 1) * ' '
236for app in apps:
237   content += app + " "
238   content += (width - len(app)) * " "
239content += "\n"
240
241for i in nb_procs:
242   content += "%-15d " % i
243   for app in apps:
244      val = exec_time[app][i]
245      content += "%-15f " % (exec_time[app][1] / float(val))
246   content += "\n"
247
248create_file(data_speedup_name, content)
249
250# Creating gp file
251template_file = open(speedup_tmpl, 'r')
252template = template_file.read()
253
254plot_str = ""
255col = 2
256for app in apps:
257   if app != apps[0]:
258      plot_str += ", \\\n     "
259   plot_str += "\"" + data_speedup_name + "\" using ($1):($" + str(col) + ") lc rgb %s title \"" % (colors[col - 2])  + m_app_name[app] + "\" with linespoint"
260   col += 1
261
262gp_commands = template % dict(appli = "All Applications", nb_procs = nb_procs[-1] + 1, plot_str = plot_str, svg_name = os.path.join(graph_dir, 'all_speedup'))
263   
264create_file(gp_speedup_name, gp_commands)
265   
266# Calling gnuplot
267print "gnuplot", gp_speedup_name
268subprocess.call([ 'gnuplot', gp_speedup_name ])
269
270
271############################################################
272### Graph 4 : Graph per metric                           ###
273############################################################
274
275# The following section creates the graphs grouped by measure (e.g. #broadcasts)
276# The template file cannot be easily created otherwise it would not be generic
277# in many ways. This is why it is mainly created here.
278# Graphs are created for metric in the "individual_metrics" list
279
280for metric in individual_metrics:
281   data_metric_name = os.path.join(scripts_path, gen_dir, metric + '.dat')
282   gp_metric_name   = os.path.join(scripts_path, gen_dir, metric + '.gp')
283
284   # Creating the gp file
285   # Setting xtics, i.e. number of procs for each application
286   xtics_str = "("
287   first = True
288   xpos = 1
289   app_labels = ""
290   for num_appli in range(0, len(apps)):
291      for i in nb_procs:
292         if not first:
293            xtics_str += ", "
294         first = False
295         if i == nb_procs[0]:
296            xpos_first = xpos
297         xtics_str += "\"%d\" %.1f" % (i, xpos)
298         xpos_last = xpos
299         xpos += 1.5
300      xpos += 0.5
301      app_name_xpos = float((xpos_first + xpos_last)) / 2
302      app_labels += "set label \"%s\" at first %f,character 1 center font\"Times,12\"\n" % (m_app_name[apps[num_appli]], app_name_xpos)
303   xtics_str += ")"
304
305   xmax_val = xpos + 0.5
306
307   # Writing the lines of "plot"
308   plot_str = ""
309   xpos = 0
310   first = True
311   column = 2
312   for i in range(0, len(nb_procs)):
313      if not first:
314         plot_str += ", \\\n    "
315      first = False
316      plot_str += "\"%s\" using ($1+%.1f):($%d) lc rgb %s notitle with boxes" % (data_metric_name, xpos, column, colors[i])
317      column += 1
318      xpos += 1.5
319
320   template_file = open(metric_tmpl, 'r')
321   template = template_file.read()
322
323   gp_commands = template % dict(xtics_str = xtics_str, app_labels = app_labels, ylabel_str = m_metric_name[metric], norm_factor_str = m_norm_factor_name[m_metric_norm[metric]], xmax_val = xmax_val, plot_str = plot_str, svg_name = os.path.join(graph_dir, metric))
324
325   create_file(gp_metric_name, gp_commands)
326   
327   # Creating the data file
328   width = 15
329   content = "#x_pos"
330   nb_spaces = width - len(content)
331   content += nb_spaces * ' '
332   for i in nb_procs:
333      content += "%-15d" % i
334   content += "\n"
335
336   x_pos = 1
337   for app in apps:
338      # Computation of x_pos
339      content += "%-15f" % x_pos
340      x_pos += len(nb_procs) * 1.5 + 0.5
341      for i in nb_procs:
342         if m_metric_norm[metric] == "N":
343            content += "%-15d" % (metrics_val[app][i][metric])
344         elif m_metric_norm[metric] == "P":
345            content += "%-15f" % (float(metrics_val[app][i][metric]) / i)
346         elif m_metric_norm[metric] == "C":
347            content += "%-15f" % (float(metrics_val[app][i][metric]) / exec_time[app][i] * 1000)
348         elif m_metric_norm[metric] == "W":
349            content += "%-15f" % (float(metrics_val[app][i][metric]) / float(metrics_val[app][i]['total_write'])) # Number of writes
350         elif m_metric_norm[metric] == "R":
351            content += "%-15f" % (float(metrics_val[app][i][metric]) / float(metrics_val[app][i]['total_read'])) # Number of reads
352         elif m_metric_norm[metric] == "D":
353            content += "%-15f" % (float(metrics_val[app][i][metric]) / float(metrics_val[app][i]['total_direct'])) # Number of req.
354         elif is_numeric(m_metric_norm[metric]):
355            content += "%-15f" % (float(metrics_val[app][i][metric]) / float(metrics_val[app][int(m_metric_norm[metric])][metric]))
356         else:
357            assert(False)
358
359      app_name = m_app_name[app]
360      content += "#" + app_name + "\n"
361   
362   create_file(data_metric_name, content)
363
364   # Calling gnuplot
365   print "gnuplot", gp_metric_name
366   subprocess.call([ 'gnuplot', gp_metric_name ])
367
368
369############################################################
370### Graph 5 : Stacked histogram with counters            ###
371############################################################
372
373# The following section creates a stacked histogram containing
374# the metrics in the "stacked_metric" list
375# It is normalized per application w.r.t the values on 256 procs
376
377data_stacked_name = os.path.join(scripts_path, gen_dir, 'stacked.dat')
378gp_stacked_name   = os.path.join(scripts_path, gen_dir, 'stacked.gp')
379
380norm_factor_value = 256
381
382# Creating the gp file
383template_file = open(stacked_tmpl, 'r')
384template = template_file.read()
385
386xtics_str = "("
387first = True
388xpos = 1
389app_labels = ""
390for num_appli in range(0, len(apps)):
391   for i in nb_procs:
392      if not first:
393         xtics_str += ", "
394      first = False
395      if i == nb_procs[0]:
396         xpos_first = xpos
397      xtics_str += "\"%d\" %d -1" % (i, xpos)
398      xpos_last = xpos
399      xpos += 1
400   xpos += 1
401   app_name_xpos = float((xpos_first + xpos_last)) / 2
402   app_labels += "set label \"%s\" at first %f,character 1 center font\"Times,12\"\n" % (m_app_name[apps[num_appli]], app_name_xpos)
403xtics_str += ")"
404
405plot_str = "newhistogram \"\""
406n = 1
407for stacked_metric in stacked_metrics:
408   plot_str += ", \\\n    " + "'" + data_stacked_name + "'" + " using " + str(n) + " lc rgb " + colors[n] + " title \"" + m_metric_name[stacked_metric] + "\""
409   n += 1
410
411ylabel_str = "Breakdown of Coherence Traffic Normalized w.r.t. \\nthe Values on %d Processors" % norm_factor_value
412content = template % dict(svg_name = os.path.join(graph_dir, 'stacked'), xtics_str = xtics_str, plot_str = plot_str, ylabel_str = ylabel_str, app_labels = app_labels)
413
414create_file(gp_stacked_name, content)
415
416# Creating the data file
417# Values are normalized by application, w.r.t. the number of requests for a given number of procs
418content = "#"
419for stacked_metric in stacked_metrics:
420   content += stacked_metric
421   content += ' ' + ' ' * (15 - len(stacked_metric))
422content += "\n"
423for app in apps:
424   if app != apps[0]:
425      for i in range(0, len(stacked_metrics)):
426         content += "%-15f" % 0.0
427      content += "\n"
428   for i in nb_procs:
429      for stacked_metric in stacked_metrics:
430         content += "%-15f" % (float(metrics_val[app][i][stacked_metric]) / metrics_val[app][norm_factor_value]['total_stacked'])
431      content += "\n"
432
433create_file(data_stacked_name, content)
434# Calling gnuplot
435print "gnuplot", gp_stacked_name
436subprocess.call([ 'gnuplot', gp_stacked_name ])
437
438
439
440#################################################################################
441### Graph 6 : Stacked histogram with coherence cost compared to r/w cost      ###
442#################################################################################
443
444# The following section creates pairs of stacked histograms, normalized w.r.t. the first one.
445# The first one contains the cost of reads and writes, the second contains the cost
446# of m_inv, m_up and broadcasts (extrapolated)
447
448data_cost_filename = os.path.join(scripts_path, gen_dir, 'relative_cost.dat')
449gp_cost_filename   = os.path.join(scripts_path, gen_dir, 'relative_cost.gp')
450
451direct_cost_metrics = [ 'read_cost', 'write_cost' ]
452coherence_cost_metrics = ['update_cost', 'm_inv_cost', 'broadcast_cost' ]
453
454# Creating the gp file
455template_file = open(stacked_tmpl, 'r')
456template = template_file.read()
457
458xtics_str = "("
459first = True
460xpos = 1.5
461app_labels = ""
462for num_appli in range(0, len(apps)):
463   first_proc = True
464   for i in nb_procs:
465      if i > 4:
466         if not first:
467            xtics_str += ", "
468         first = False
469         if first_proc:
470            first_proc = False
471            xpos_first = xpos
472         xtics_str += "\"%d\" %f -1" % (i, xpos)
473         xpos_last = xpos
474         xpos += 3
475   app_name_xpos = float((xpos_first + xpos_last)) / 2
476   app_labels += "set label \"%s\" at first %f,character 1 center font\"Times,12\"\n" % (m_app_name[apps[num_appli]], app_name_xpos)
477   xpos += 1
478xtics_str += ")"
479
480plot_str = "newhistogram \"\""
481n = 1
482for cost_metric in direct_cost_metrics + coherence_cost_metrics:
483   plot_str += ", \\\n    " + "'" + data_cost_filename + "'" + " using " + str(n) + " lc rgb " + colors[n] + " title \"" + m_metric_name[cost_metric] + "\""
484   n += 1
485
486ylabel_str = "Coherence Cost Compared to Direct Requests Cost,\\nNormalized per Application for each Number of Processors"
487content = template % dict(svg_name = os.path.join(graph_dir, 'rel_cost'), xtics_str = xtics_str, plot_str = plot_str, ylabel_str = ylabel_str, app_labels = app_labels)
488
489create_file(gp_cost_filename, content)
490
491# Creating the data file
492# Values are normalized by application, w.r.t. the number of requests for a given number of procs
493content = "#"
494for cost_metric in direct_cost_metrics:
495   content += cost_metric
496   content += ' ' + ' ' * (15 - len(cost_metric))
497for cost_metric in coherence_cost_metrics:
498   content += cost_metric
499   content += ' ' + ' ' * (15 - len(cost_metric))
500content += "\n"
501for app in apps:
502   if app != apps[0]:
503      for i in range(0, len(direct_cost_metrics) + len(coherence_cost_metrics)):
504         content += "%-15f" % 0.0
505      content += "\n"
506   for i in nb_procs:
507      if i > 4:
508         for cost_metric in direct_cost_metrics:
509            content += "%-15f" % (float(metrics_val[app][i][cost_metric]) / metrics_val[app][i]['direct_cost'])
510         for cost_metric in coherence_cost_metrics:
511            content += "%-15f" % 0.0
512         content += "\n"
513         for cost_metric in direct_cost_metrics:
514            content += "%-15f" % 0.0
515         for cost_metric in coherence_cost_metrics:
516            content += "%-15f" % (float(metrics_val[app][i][cost_metric]) / metrics_val[app][i]['direct_cost'])
517         content += "\n"
518         for i in range(0, len(direct_cost_metrics) + len(coherence_cost_metrics)):
519            content += "%-15f" % 0.0
520         content += "\n"
521
522create_file(data_cost_filename, content)
523# Calling gnuplot
524print "gnuplot", gp_cost_filename
525subprocess.call([ 'gnuplot', gp_cost_filename ])
526
527
Note: See TracBrowser for help on using the repository browser.