CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EdgesToViz.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import sys
4 import os
5 import os.path
6 
7 class Col:
8  def __init__(me):
9  me.h=0.
10  me.s=.5
11  me.b=.5
12 
13  def next(me):
14  rc = "\"%f,%f,%f\""%(me.h,me.s,me.b)
15  me.h += .1
16  if me.h > 1.:
17  me.h=0.
18  me.s += .1
19  if me.s> 1.:
20  me.h=0.
21  me.s = .5
22  me.b += .1
23  return rc
24 
25 def readtable(flook):
26  # field 7 is the library name
27  tab = {}
28  next = Col()
29  cols = {}
30  for line in flook.xreadlines():
31  s = line.split()
32  if not s[7] in cols:
33  cols[s[7]] = next.next()
34  s.append(cols[s[7]])
35  tab[s[0]]=s
36  return tab,cols
37 
38 
39 def runme(infile,outfile,lookupfile,use_name):
40  fin = open(infile,'r')
41  flook = open(lookupfile,'r')
42  fout = open(outfile,'w')
43 
44  table,libcols = readtable(flook)
45 
46  fout.write('digraph prof {')
47 
48  uni = {}
49 # d=1
50 # for i in libcols.items():
51 # print >>fout,'lib%d [label="%s",style=filled,color=%s,fontsize=18];' % (d,os.path.basename(i[0].strip('"')),i[1])
52 # d += 1
53 
54 
55  for line in fin.xreadlines():
56  count,from_node,to_node = line.split()
57  uni[from_node] = 1
58  uni[to_node] = 1
59  row_to = table[to_node]
60  row_from = table[from_node]
61 
62  if row_from[-1] == row_to[-1]:
63  color="\"#000000\""
64  else:
65  row=table[to_node]
66  color=row[-1]
67 
68  print >>fout, '%s -> %s [label="%s",fontsize=18,color=%s];' % (from_node,to_node,count,color)
69 
70  # print "blob",uni.keys
71 
72  for function_id in uni.keys():
73  function_data = table[function_id]
74  # print e
75  node_label = function_data[0]
76  if use_name: node_label = function_data[-2].strip('"')
77  leaf_fraction = float(function_data[5])
78  recursive_fraction = float(function_data[6])
79  if recursive_fraction > .03 and recursive_fraction <.20: shape="box"
80  else: shape="circle"
81  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)
82 
83  fout.write('}')
84 
85 if __name__ == "__main__":
86  if len(sys.argv) < 4:
87  print "usage: ", sys.argv[0], " edge_input_file digraph_output_file func_names_lookup_file"
88  sys.exit(1)
89 
90  infile = sys.argv[1]
91  outfile = sys.argv[2]
92  lookupfile = sys.argv[3]
93  use_name = 0
94  if len(sys.argv)>4: use_name=1
95  runme(infile, outfile, lookupfile,use_name)
def readtable
Definition: EdgesToViz.py:25