CMS 3D CMS Logo

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