2 from __future__
import print_function
3 from builtins
import range
5 topfunc = re.compile(
"::(produce|analyze|filter|beginLuminosityBlock|beginRun|beginStream|streamBeginRun|streamBeginLuminosityBlock|streamEndRun|streamEndLuminosityBlock|globalBeginRun|globalEndRun|globalBeginLuminosityBlock|globalEndLuminosityBlock|endRun|endLuminosityBlock)\(")
6 baseclass = re.compile(
"edm::(one::|stream::|global::)?ED(Producer|Filter|Analyzer)(Base)?")
7 farg = re.compile(
"\(.*\)")
8 fre = re.compile(
"function")
12 skipfunc = re.compile(
"(edm::(LuminosityBlock::|Run::|Event::|Principal::)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|(cond::service::PoolDBOutputService::(writeOne|appendSinceTime|tagInfo))|edm::EventProcessor::|edm::SubProcess::)")
19 for line
in fileinput.input(files =(
'function-statics-db.txt',
'function-calls-db.txt')):
21 fields = line.split(
"'")
22 if topfunc.search(fields[1])
and not baseclass.search(fields[1]): toplevelfuncs.add(fields[1])
23 if fields[2] ==
' calls function ':
24 if skipfunc.search(line) : skipfuncs.add(line)
25 else : G.add_edge(fields[1],fields[3],kind=fields[2])
26 if fields[2] ==
' overrides function ' :
27 if baseclass.search(fields[3]) :
28 if topfunc.search(fields[3]) : toplevelfuncs.add(fields[1])
29 G.add_edge(fields[1],fields[3],kind=fields[2])
31 if skipfunc.search(line) : skipfuncs.add(line)
32 else : G.add_edge(fields[3],fields[1],kind=
' calls function ')
33 if fields[2] ==
' static variable ' :
34 G.add_edge(fields[1],fields[3],kind=fields[2])
35 statics.add(fields[3])
36 if fields[2] ==
' known thread unsafe function ' :
37 G.add_edge(fields[1],fields[3],kind=
' known thread unsafe function ')
38 statics.add(fields[3])
41 for tfunc
in sorted(toplevelfuncs):
42 for static
in sorted(statics):
43 if nx.has_path(G,tfunc,static):
44 path = nx.shortest_path(G,tfunc,static)
46 print(
"Non-const static variable \'"+re.sub(farg,
"()",static)+
"' is accessed in call stack '", end=
' ')
47 for i
in range(0,len(path)-1) :
48 print(re.sub(farg,
"()",path[i])+G[path[i]][path[i+1]][
'kind'], end=
' ')
49 print(re.sub(farg,
"()",path[i+1])+
"' ,", end=
' ')
50 for key
in G[tfunc].
keys() :
51 if 'kind' in G[tfunc][key]
and G[tfunc][key][
'kind'] ==
' overrides function ' :
52 print(
"'"+re.sub(farg,
"()",tfunc)+
"' overrides '"+re.sub(farg,
"()",key)+
"'", end=
' ')
55 print(
"In call stack ' ", end=
' ')
56 for i
in range(0,len(path)-1) :
57 print(re.sub(farg,
"()",path[i])+G[path[i]][path[i+1]][
'kind'], end=
' ')
58 print(re.sub(farg,
"()",path[i+1])+
"' is accessed ,", end=
' ')
59 for key
in G[tfunc].
keys() :
60 if 'kind' in G[tfunc][key]
and G[tfunc][key][
'kind'] ==
' overrides function ' :
61 print(
"'"+re.sub(farg,
"()",tfunc)+
"' overrides '"+re.sub(farg,
"()",key)+
"'", end=
' ')