CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
callgraph.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 import re
3 topfunc = re.compile("::(produce|analyze|filter|beginLuminosityBlock|beginRun)\(")
4 baseclass = re.compile("edm::(one::|stream::|global::)?ED(Producer|Filter|Analyzer)(Base)?")
5 farg = re.compile("\(.*\)")
6 toplevelfuncs = set()
7 epfunc = re.compile("TGraph::(.*)\(.*\)")
8 skipfunc = re.compile("TGraph::IsA\(.*\)")
9 epfuncs=set()
10 
11 import networkx as nx
12 G=nx.DiGraph()
13 
14 f = open('function-calls-db.txt')
15 
16 for line in f :
17  fields = line.split("'")
18  if fields[2] == ' calls function ' :
19  if not skipfunc.search(line) :
20  G.add_edge(fields[1],fields[3],kind=fields[2])
21  if epfunc.search(fields[3]) : epfuncs.add(fields[3])
22  if fields[2] == ' overrides function ' :
23  if baseclass.search(fields[3]) :
24  if topfunc.search(fields[3]) : toplevelfuncs.add(fields[1])
25  G.add_edge(fields[1],fields[3],kind=' overrides function ')
26  else :
27  if not skipfunc.search(line) :
28  G.add_edge(fields[3],fields[1],kind=' calls override function ')
29  if epfunc.search(fields[1]) : epfuncs.add(fields[1])
30 f.close()
31 
32 for epfunc in sorted(epfuncs): print epfunc
33 print
34 
35 for epfunc in epfuncs:
36  for tfunc in toplevelfuncs:
37  if nx.has_path(G,tfunc,epfunc) :
38  path = nx.shortest_path(G,tfunc,epfunc)
39  print "Call stack \'",
40  for p in path :
41  print re.sub(farg,"()",p)+"; ",
42  print " \'. "
43