00001
00002
00003 import sys
00004 import os
00005 import os.path
00006
00007 class Col:
00008 def __init__(me):
00009 me.h=0.
00010 me.s=.5
00011 me.b=.5
00012
00013 def next(me):
00014 rc = "\"%f,%f,%f\""%(me.h,me.s,me.b)
00015 me.h += .1
00016 if me.h > 1.:
00017 me.h=0.
00018 me.s += .1
00019 if me.s> 1.:
00020 me.h=0.
00021 me.s = .5
00022 me.b += .1
00023 return rc
00024
00025 def readtable(flook):
00026
00027 tab = {}
00028 next = Col()
00029 cols = {}
00030 for line in flook.xreadlines():
00031 s = line.split()
00032 if not s[7] in cols:
00033 cols[s[7]] = next.next()
00034 s.append(cols[s[7]])
00035 tab[s[0]]=s
00036 return tab,cols
00037
00038
00039 def runme(infile,outfile,lookupfile,use_name):
00040 fin = open(infile,'r')
00041 flook = open(lookupfile,'r')
00042 fout = open(outfile,'w')
00043
00044 table,libcols = readtable(flook)
00045
00046 fout.write('digraph prof {')
00047
00048 uni = {}
00049
00050
00051
00052
00053
00054
00055 for line in fin.xreadlines():
00056 count,from_node,to_node = line.split()
00057 uni[from_node] = 1
00058 uni[to_node] = 1
00059 row_to = table[to_node]
00060 row_from = table[from_node]
00061
00062 if row_from[-1] == row_to[-1]:
00063 color="\"#000000\""
00064 else:
00065 row=table[to_node]
00066 color=row[-1]
00067
00068 print >>fout, '%s -> %s [label="%s",fontsize=18,color=%s];' % (from_node,to_node,count,color)
00069
00070
00071
00072 for function_id in uni.keys():
00073 function_data = table[function_id]
00074
00075 node_label = function_data[0]
00076 if use_name: node_label = function_data[-2].strip('"')
00077 leaf_fraction = float(function_data[5])
00078 recursive_fraction = float(function_data[6])
00079 if recursive_fraction > .03 and recursive_fraction <.20: shape="box"
00080 else: shape="circle"
00081 print >>fout,'%s [label="ID: %s\\nL: %5.1f%%\\nB: %5.1f%%",style=filled,color=%s,shape=%s,fontsize=18];' % (node_label,node_label,leaf_fraction*100, recursive_fraction*100,function_data[-1],shape)
00082
00083 fout.write('}')
00084
00085 if __name__ == "__main__":
00086 if len(sys.argv) < 4:
00087 print "usage: ", sys.argv[0], " edge_input_file digraph_output_file func_names_lookup_file"
00088 sys.exit(1)
00089
00090 infile = sys.argv[1]
00091 outfile = sys.argv[2]
00092 lookupfile = sys.argv[3]
00093 use_name = 0
00094 if len(sys.argv)>4: use_name=1
00095 runme(infile, outfile, lookupfile,use_name)