2 from __future__
import print_function
5 from builtins
import range
7 topfunc = re.compile(
r"::(produce|analyze|filter|beginLuminosityBlock|beginRun|beginStream|streamBeginRun|streamBeginLuminosityBlock|streamEndRun|streamEndLuminosityBlock|globalBeginRun|globalEndRun|globalBeginLuminosityBlock|globalEndLuminosityBlock|endRun|endLuminosityBlock)\(")
8 baseclass = re.compile(
9 "edm::(one::|stream::|global::)?ED(Producer|Filter|Analyzer)(Base)?")
10 farg = re.compile(
r"\(.*\)")
11 fre = re.compile(
"function")
15 skipfunc = re.compile(
r"(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::)")
20 for line
in fileinput.input(files=(
'function-statics-db.txt',
'function-calls-db.txt')):
22 fields = line.split(
"'")
23 if topfunc.search(fields[1])
and not baseclass.search(fields[1]):
24 toplevelfuncs.add(fields[1])
25 if fields[2] ==
' calls function ':
26 if skipfunc.search(line):
29 G.add_edge(fields[1], fields[3], kind=fields[2])
30 if fields[2] ==
' overrides function ':
31 if baseclass.search(fields[3]):
32 if topfunc.search(fields[3]):
33 toplevelfuncs.add(fields[1])
34 G.add_edge(fields[1], fields[3], kind=fields[2])
36 if skipfunc.search(line):
39 G.add_edge(fields[3], fields[1], kind=
' calls function ')
40 if fields[2] ==
' static variable ':
41 G.add_edge(fields[1], fields[3], kind=fields[2])
42 statics.add(fields[3])
43 if fields[2] ==
' known thread unsafe function ':
44 G.add_edge(fields[1], fields[3],
45 kind=
' known thread unsafe function ')
46 statics.add(fields[3])
49 for tfunc
in sorted(toplevelfuncs):
50 for static
in sorted(statics):
51 if G.has_node(tfunc)
and G.has_node(static)
and nx.has_path(G, tfunc, static):
52 path = nx.shortest_path(G, tfunc, static)
54 print(
"Non-const static variable \'"+re.sub(farg,
"()",
55 static)+
"' is accessed in call stack '", end=
' ')
56 for i
in range(0, len(path)-1):
57 print(re.sub(farg,
"()", path[i]) +
58 G[path[i]][path[i+1]][
'kind'], end=
' ')
59 print(re.sub(farg,
"()", path[i+1])+
"' ,", end=
' ')
60 for key
in G[tfunc].
keys():
61 if 'kind' in G[tfunc][key]
and G[tfunc][key][
'kind'] ==
' overrides function ':
62 print(
"'"+re.sub(farg,
"()", tfunc)+
"' overrides '" +
63 re.sub(farg,
"()", key)+
"'", end=
' ')
66 print(
"In call stack ' ", end=
' ')
67 for i
in range(0, len(path)-1):
68 print(re.sub(farg,
"()", path[i]) +
69 G[path[i]][path[i+1]][
'kind'], end=
' ')
70 print(re.sub(farg,
"()", path[i+1])+
"' is accessed ,", end=
' ')
71 for key
in G[tfunc].
keys():
72 if 'kind' in G[tfunc][key]
and G[tfunc][key][
'kind'] ==
' overrides function ':
73 print(
"'"+re.sub(farg,
"()", tfunc)+
"' overrides '" +
74 re.sub(farg,
"()", key)+
"'", end=
' ')