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|beginStream)\(")
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 import fileinput
17 for line in fileinput.input(files =('function-statics-db.txt','function-calls-db.txt')):
18  if fre.search(line):
19  fields = line.split("'")
20  if topfunc.search(fields[1]) and not baseclass.search(fields[1]): toplevelfuncs.add(fields[1])
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=fields[2])
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 fileinput.close()
38 
39 for tfunc in sorted(toplevelfuncs):
40  for static in sorted(statics):
41  if nx.has_path(G,tfunc,static):
42  path = nx.shortest_path(G,tfunc,static)
43 
44  print "Non-const static variable \'"+re.sub(farg,"()",static)+"' is accessed in call stack '",
45  for i in range(0,len(path)-1) :
46  print re.sub(farg,"()",path[i])+G[path[i]][path[i+1]]['kind'],
47  print re.sub(farg,"()",path[i+1])+"' ,",
48  for key in G[tfunc].keys() :
49  if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ' :
50  print "'"+re.sub(farg,"()",tfunc)+"' overrides '"+re.sub(farg,"()",key)+"'",
51  print
52 
53  print "In call stack ' ",
54  for i in range(0,len(path)-1) :
55  print re.sub(farg,"()",path[i])+G[path[i]][path[i+1]]['kind'],
56  print re.sub(farg,"()",path[i+1])+"' is accessed ,",
57  for key in G[tfunc].keys() :
58  if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ' :
59  print "'"+re.sub(farg,"()",tfunc)+"' overrides '"+re.sub(farg,"()",key)+"'",
60  print
61