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 fre = re.compile("function")
7 
8 statics = set()
9 toplevelfuncs = set()
10 skipfunc = re.compile("(edm::(LuminosityBlock::|Run::|Event::)getBy(Label|Token))|(fwlite::|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|edm::serviceregistry::ServicesManager::MakerHolder::add)")
11 skipfuncs=set()
12 
13 import networkx as nx
14 G=nx.DiGraph()
15 
16 f = open('db.txt')
17 
18 for line in f :
19  if fre.search(line):
20  fields = line.split("'")
21  if fields[2] == ' calls function ':
22  if skipfunc.search(line) : skipfuncs.add(line)
23  else : G.add_edge(fields[1],fields[3],kind=fields[2])
24  if fields[2] == ' overrides function ' :
25  if baseclass.search(fields[3]) :
26  if topfunc.search(fields[3]) : toplevelfuncs.add(fields[1])
27  G.add_edge(fields[1],fields[3],kind=fields[2])
28  else :
29  if skipfunc.search(line) : skipfuncs.add(line)
30  else : G.add_edge(fields[3],fields[1],kind=' calls function ')
31  if fields[2] == ' static variable ' :
32  G.add_edge(fields[1],fields[3],kind=' static variable ')
33  statics.add(fields[3])
34  if fields[2] == ' known thread unsafe function ' :
35  G.add_edge(fields[1],fields[3],kind=' known thread unsafe function ')
36  statics.add(fields[3])
37 f.close()
38 for tfunc in sorted(toplevelfuncs):
39  for static in sorted(statics):
40  if nx.has_path(G,tfunc,static):
41  path = nx.shortest_path(G,tfunc,static)
42 
43  print "Non-const static variable \'"+re.sub(farg,"()",static)+"' is accessed in call stack '",
44  for i in range(0,len(path)-1) :
45  print re.sub(farg,"()",path[i])+G[path[i]][path[i+1]]['kind'],
46  print re.sub(farg,"()",path[i+1])+"' ,",
47  for key in G[tfunc].keys() :
48  if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ' :
49  print "'"+re.sub(farg,"()",tfunc)+"' overrides '"+re.sub(farg,"()",key)+"'",
50  print
51 
52  print "In call stack ' ",
53  for i in range(0,len(path)-1) :
54  print re.sub(farg,"()",path[i])+G[path[i]][path[i+1]]['kind'],
55  print re.sub(farg,"()",path[i+1])+"' is accessed ,",
56  for key in G[tfunc].keys() :
57  if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ' :
58  print "'"+re.sub(farg,"()",tfunc)+"' overrides '"+re.sub(farg,"()",key)+"'",
59  print
60