CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
statics.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 statics = set()
7 toplevelfuncs = set()
8 skipfunc = re.compile("(edm::EDProductGetter::getIt|edm::Event::|edm::eventsetup::EventSetupRecord::get|edm::eventsetup::DataProxy::getImpl|edm::EventPrincipal::unscheduledFill|edm::ServiceRegistry::get|edm::eventsetup::EventSetupRecord::getImplementation|edm::eventsetup::EventSetupRecord::getFromProxy|edm::eventsetup::DataProxy::get)")
9 skipfuncs=set()
10 
11 import networkx as nx
12 G=nx.DiGraph()
13 
14 f = open('db.txt')
15 
16 for line in f :
17  fields = line.split("'")
18  if fields[2] == ' calls function ' :
19  if skipfunc.search(line) : skipfuncs.add(line)
20  else : G.add_edge(fields[1],fields[3],kind=fields[2])
21  if fields[2] == ' overrides function ' :
22  if baseclass.search(fields[3]) :
23  if topfunc.search(fields[3]) : toplevelfuncs.add(fields[1])
24  G.add_edge(fields[1],fields[3],kind=' overrides function ')
25  else :
26  if skipfunc.search(line) : skipfuncs.add(line)
27  else : G.add_edge(fields[3],fields[1],kind=' calls function ')
28  if fields[2] == ' static variable ' :
29  G.add_edge(fields[1],fields[3],kind=' static variable ')
30  statics.add(fields[3])
31 f.close()
32 
33 for static in statics:
34  for tfunc in toplevelfuncs:
35  if nx.has_path(G,tfunc,static):
36  path = nx.shortest_path(G,tfunc,static)
37  print "Non-const static variable \'"+re.sub(farg,"()",static)+"\' is accessed in call stack ",
38  print " \'",
39  for p in path :
40  print re.sub(farg,"()",p)+"; ",
41  print " \'. ",
42  for key in G[tfunc].keys() :
43  if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ' :
44  print "'"+re.sub(farg,"()",tfunc)+"'"+G[tfunc][key]['kind']+"'"+re.sub(farg,"()",key)+"'",
45  print ""
46  path = nx.shortest_path(G,tfunc,static)
47  print "In call stack ' ",
48  for p in path:
49  print re.sub(farg,"()",p)+"; ",
50  print "\'",
51  print " non-const static variable \'"+re.sub(farg,"()",static)+"\' is accessed. ",
52  for key in G[tfunc].keys() :
53  if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ' :
54  print "'"+re.sub(farg,"()",tfunc)+"'"+G[tfunc][key]['kind']+"'"+re.sub(farg,"()",key)+"'",
55  print
56