# HG changeset patch # User Nina Engelhardt # Date 1333039259 -7200 # Node ID 3092eb030708d695d43a7374167eaf0b016ac98c # Parent 0175af93cc54f97353e515f57aaa7f4ecec71591 cleaned up visualization code diff -r 0175af93cc54 -r 3092eb030708 scripts/ucc_and_loop_graph_treatment/column_view.py --- a/scripts/ucc_and_loop_graph_treatment/column_view.py Mon Mar 12 15:27:28 2012 +0100 +++ b/scripts/ucc_and_loop_graph_treatment/column_view.py Thu Mar 29 18:40:59 2012 +0200 @@ -1,19 +1,18 @@ #!/usr/bin/python import svgfig as sf +import colorsys -__column_width = 100 +__column_width = 110 +__node_width = 100 +__num_idle = 0 #graph.node['start']['numcores'] * 2 - -def fig_from_node(graph,node,positioning=None): +def fig_from_node(graph,node,num_cols,offset,positioning=None): """Build globally positioned node representation.""" core = graph.node[node]['core'] - if positioning==None: - x1 = core * 3 * __column_width + __column_width - else: - x1 = core * 3 * __column_width + 2 * __column_width - x2 = x1 + __column_width + x1 = core * num_cols * __column_width + offset * __column_width + x2 = x1 + __node_width if positioning != None: y1 = positioning[node] - graph.node[node]['weight'] elif graph.node[node].has_key('AssignerInvocation_start'): @@ -29,26 +28,27 @@ else: raise NameError('Node insufficiently annotated') y2 = y1 + graph.node[node]['weight'] - if node[0]>= 2*graph.node['start']['numcores']: + if node[0]>= __num_idle : if positioning != None: f='blue' else: f='red' else: f='gray' - r = sf.Rect(x1,y1,x2,y2,fill=f) - s = sf.Text((x1+x2)/2 , (y1+y2)/2 ,str(node),text_anchor="middle") + r = sf.Rect(x1,y1,x2,y2,fill=f,fill_opacity="40%") + r2 = sf.Rect(x1,y1+graph.node[node]['work_offset'],x2,y1+graph.node[node]['work_offset']+graph.node[node]['Work_end']-graph.node[node]['Work_start'],fill=f, stroke_opacity=0) + s = sf.Text((x1+x2)/2 , (y1+y2)/2 ,str(node),text_anchor="middle",font_size=20) if graph.node[node].has_key('AssignerInvocation_start') and graph.node[node].has_key('Assigner_start'): h = graph.node[node]['Assigner_start'] - graph.node[node]['AssignerInvocation_start'] r1 = sf.Rect(x1,y1,x2,y1+h,fill='green',fill_opacity="70%") - return sf.Fig(r,r1,s) - return sf.Fig(r,s) + return sf.Fig(r,r1,r2,s) + return sf.Fig(r,r2,s) -def tsc_fig_from_node(graph,node,maxh): +def tsc_fig_from_node(graph,node,num_cols,offset,maxh): tscstarttime = graph.node['start']['tscstarttime'] core = graph.node[node]['core'] - x1 = 3 * core * __column_width - x2 = x1 + __column_width + x1 = num_cols * core * __column_width + offset * __column_width + x2 = x1 + __node_width y1 = graph.node[node]['Timestamp_start'] - tscstarttime if graph.node[node].has_key('Timestamp_end'): y2 = graph.node[node]['Timestamp_end'] - tscstarttime @@ -67,43 +67,81 @@ pass return sf.Fig(r,s),maxh -def fig_nodes(graph,vertical_scale_factor,positioning=None): +def fig_nodes(graph,vertical_scale_factor,num_cols,offset,positioning=None): """Build all nodes.""" nodes = [] for node in graph: if node != 'start' and node != 'end': try: - nodes.append(fig_from_node(graph,node,positioning=positioning)) + nodes.append(fig_from_node(graph,node,num_cols,offset,positioning=positioning)) except Exception as e: print node,e - return sf.Fig(*nodes,trans="x,{0}*y".format(vertical_scale_factor)) + return sf.Fig(*nodes)#,trans="x,{0}*y".format(vertical_scale_factor)) -def save_column_view(graph,num_cores,total_height,positioning=None): - vertical_scale_factor = 10000.0/float(total_height) - f = sf.Fig(fig_nodes(graph,vertical_scale_factor,positioning=positioning)) - f.d.append(get_tsc_scale(graph,num_cores,total_height)) - if positioning!=None: - f.d.append(fig_nodes(graph,vertical_scale_factor)) - w = 3*__column_width*num_cores - c = sf.canvas(f.SVG(),width="{0}px".format(w),height="10000px",viewBox='0 0 {0} 10000'.format(w)) - c.save() - -def get_tsc_scale(graph,num_cores,total_height): +def get_tsc_scale(graph,num_cores,num_cols,offset): nodes=sf.Fig() maxh = 0 for node in graph: if node != 'start' and node != 'end': try: - n , maxh = tsc_fig_from_node(graph,node,maxh) + n , maxh = tsc_fig_from_node(graph,node,num_cols,offset,maxh) nodes.d.append(n) except Exception as e: print node,e - nodes.trans = "x,{0}*y".format(10000.0/float(total_height)) + #nodes.trans = "x,{0}*y".format(10000.0/float(total_height)) return nodes +def draw_dep(graph,num_cores,num_cols,offset,positioning,dep,color=(0,0,0)): + a,b = dep + core1 = graph.node[a]['core'] + x1 = core1 * num_cols * __column_width + offset * __column_width + 0.5 * __column_width + y1 = positioning[a] + core2 = graph.node[b]['core'] + x2 = core2 * num_cols * __column_width + offset * __column_width + 0.5 * __column_width + y2 = positioning[b] - graph.node[b]['weight'] + return sf.Line(x1,y1,x2,y2,style="stroke:rgb({},{},{});stroke-width:3".format(int(color[0]*255),int(color[1]*255),int(color[2]*255))) + + +def draw_cross_core_deps(graph,num_cores,num_cols,offset,positioning,dependencies): + f = sf.Fig() + hue = 0 + hue_incr = 1.0/len(dependencies) + for depl in dependencies: + for a,b in depl: + if graph.node[a]['core'] != graph.node[b]['core']: + f.d.append(draw_dep(graph,num_cores,num_cols,offset,positioning,(a,b),colorsys.hsv_to_rgb(hue,1,1))) + hue = hue + hue_incr + return f + +def save_comparative_column_view(graph,num_cores,total_height,positioning=None): + if positioning == None: + num_cols = 2 + else: + num_cols = 3 + vertical_scale_factor = 10000.0/float(total_height) + f = sf.Fig() + f.d.append(get_tsc_scale(graph,num_cores,num_cols,0)) + f.d.append(fig_nodes(graph,num_cols,1,positioning=positioning)) + if positioning!=None: + f.d.append(fig_nodes(graph,num_cols,2)) + w = __num_cols*__column_width*num_cores + f.trans = "x,{0}*y".format(10000.0/float(total_height)) + c = sf.canvas(f.SVG(),width="{0}px".format(w),height="10000px",viewBox='0 0 {0} 10000'.format(w)) + c.save() + +def save_computed_column_view(graph,num_cores,total_height,positioning,dependencies=None): + vertical_scale_factor = 10000.0/float(total_height) + __num_cols = 1 + f = sf.Fig(fig_nodes(graph,vertical_scale_factor,1,0,positioning)) + if dependencies != None: + f.d.append(draw_cross_core_deps(graph,num_cores,1,0,positioning,dependencies)) + f.trans = "x,{0}*y".format(10000.0/float(total_height)) + w = __num_cols*__column_width*num_cores + c = sf.canvas(f.SVG(),width="{0}px".format(w),height="10000px",viewBox='0 0 {0} 10000'.format(w)) + c.save() + def save_tsc_scale(graph,num_cores,total_height): - nodes = get_tsc_scale(graph,num_cores,total_height) - w = 3*__column_width*num_cores - #h = maxh + nodes = get_tsc_scale(graph,num_cores,1,0,total_height) + w = __column_width*num_cores c = sf.canvas(nodes.SVG(),width="{0}px".format(w),height="{0}px".format(10000),viewBox='0 0 {0} {1}'.format(w,10000)) c.save('tsc.svg') diff -r 0175af93cc54 -r 3092eb030708 scripts/ucc_and_loop_graph_treatment/parse_loop_graph.py --- a/scripts/ucc_and_loop_graph_treatment/parse_loop_graph.py Mon Mar 12 15:27:28 2012 +0100 +++ b/scripts/ucc_and_loop_graph_treatment/parse_loop_graph.py Thu Mar 29 18:40:59 2012 +0200 @@ -65,6 +65,7 @@ n = (int(row[2]),int(row[3])) g.node[n][row[1]] = int(row[4]) g.node[n]['core'] = int(row[6]) + g.node[n]['weight'] = 0 g.node["start"]['weight'] = 0 g.node["end"]['weight'] = 0 starttimes = {} @@ -81,6 +82,7 @@ weight += g.node[n]['Assigner_end'] - g.node[n]['Assigner_start'] if g.node[n].has_key('Work_start') and g.node[n].has_key('Assigner_end'): weight += g.node[n]['Work_start'] - g.node[n]['Assigner_end'] + g.node[n]['work_offset'] = weight if g.node[n].has_key('Work_end') and g.node[n].has_key('Work_start'): weight += g.node[n]['Work_end'] - g.node[n]['Work_start'] if g.node[n].has_key('AppResponderInvocation_start') and g.node[n].has_key('Work_end'): @@ -157,7 +159,11 @@ except KeyError: print node, nlend exit(0) - lend[end] = path_to_here + graph.node[end]['weight'] + try: + lend[end] = path_to_here + graph.node[end]['weight'] + except KeyError: + print end, "'weight'" + exit(0) return lend,predd def get_path(predd,end): @@ -203,7 +209,7 @@ print "(Difference:", dif, "- Relative Error:", 100*float(dif)/float(lend['end']),"%)" print g.node['start']['starttimes'] print g.node['start']['tscstarttimes'] - column_view.save_column_view(g,g.node['start']['numcores'],max(actual_time,lend['end']),lend) + column_view.save_computed_column_view(g,g.node['start']['numcores'],max(actual_time,lend['end']),lend,[d["commDep"], d["dynDep"], d["ctlDep"]]) #column_view.save_tsc_scale(g,g.node['start']['numcores'],lend['end']) return # print "Node \tCalculated\t Actual\tCore\tDifference\tNon-cumulative part" @@ -247,8 +253,8 @@ if __name__ == "__main__": - sys.setrecursionlimit(10000) - try: - main() - except Exception as e: - print e + sys.setrecursionlimit(20000) + #try: + main() + #except Exception as e: + # print e