Skip to content

Commit

Permalink
Remove debug prints. Baseclass regex include function.
Browse files Browse the repository at this point in the history
  • Loading branch information
gartung committed Jul 14, 2021
1 parent 58f0b7a commit ca3787e
Showing 1 changed file with 10 additions and 31 deletions.
41 changes: 10 additions & 31 deletions Utilities/StaticAnalyzers/scripts/callgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,33 @@
except ImportError:
from yaml import Loader, Dumper

topfunc = re.compile(r"::(accumulate|acquire|startingNewLoop|duringLoop|endOfLoop|beginOfJob|endOfJob|produce|analyze|filter|beginLuminosityBlock|beginRun|beginStream|streamBeginRun|streamBeginLuminosityBlock|streamEndRun|streamEndLuminosityBlock|globalBeginRun|globalEndRun|globalBeginLuminosityBlock|globalEndLuminosityBlock|endRun|endLuminosityBlock)\(")
topfunc = r"::(accumulate|acquire|startingNewLoop|duringLoop|endOfLoop|beginOfJob|endOfJob|produce|analyze|filter|beginLuminosityBlock|beginRun|beginStream|streamBeginRun|streamBeginLuminosityBlock|streamEndRun|streamEndLuminosityBlock|globalBeginRun|globalEndRun|globalBeginLuminosityBlock|globalEndLuminosityBlock|endRun|endLuminosityBlock)\(.*\) (const)?"
topfuncre = re.compile(topfunc)

baseclass = re.compile(
r"(edm::)?(one::|stream::|global::)?((DQM)?(Global|One)?ED(Producer|Filter|Analyzer|(IterateNTimes|NavigateEvents)?Looper)(Base)?|impl::(ExternalWork|Accumulator))")

assert(baseclass.match('edm::global::EDFilterBase::filter()'))
assert(topfunc.search('edm::global::EDFilterBase::filter()'))
baseclass = r"(edm::)?(one::|stream::|global::)?((DQM)?(Global|One)?ED(Producer|Filter|Analyzer|(IterateNTimes|NavigateEvents)?Looper)(Base)?|impl::(ExternalWork|Accumulator))"
baseclassre = re.compile(baseclass+topfunc)
assert(baseclassre.match('edm::global::EDFilterBase::filter(*) const'))
assert(topfuncre.search('edm::global::EDFilterBase::filter(&) const'))

farg = re.compile(r"\(.*?\)")
tmpl = re.compile(r'<.*?>')
toplevelfuncs = set()

#epfuncre = re.compile(r"edm::eventsetup::EventSetupRecord::get<.*>\(.*\)")
epfuncre = re.compile(r"edm::eventsetup::EventSetupRecord::get<(class|struct) edm::ES(Transient)?Handle<(class|struct) .*>>\((const char \*, |const std::string &, )(class|struct) edm::ES(Transient)?Handle<(class|struct).*> &\) const")
f= 'edm::eventsetup::EventSetupRecord::get<class edm::ESHandle<class CaloTopology>>(const std::string &, class edm::ESHandle<class CaloTopology> &) const'
assert(epfuncre.search(f))

skipfunc = re.compile(r"TGraph::IsA\(.*\)")
epfuncs = set()



function='(anonymous namespace in /src/RecoTracker/TkHitPairs/plugins/HitPairEDProducer.cc)::Impl<(anonymous namespace)::ImplSeedingHitSets, (anonymous namespace)::DoNothing, (anonymous namespace)::RegionsLayersSeparate>::produce(const _Bool, edm::Event &, const edm::EventSetup &);'
function2='HitPairEDProducer::produce(edm::Event &, const edm::EventSetup &);'
value='HitPairEDProducer'
valuere=r'\b%s\b' % value
vre=re.compile(valuere)
m=vre.search(function)
print(m)
assert(m)
m2=vre.search(function2)
print(m2)
assert(m2)

modules = list()
Expand All @@ -51,22 +46,16 @@
mods_regex=r'\b(' + mods+ r'QQQQQQQQ)\b'
comp_mods_regex=re.compile(mods_regex)
n=comp_mods_regex.search(function)
print(n)
assert(n)
n2=comp_mods_regex.search(function2)
print(n2)
assert(n2)

h = open('module_to_package.yaml', 'r')
module2package = yaml.load(h, Loader=yaml.FullLoader)
#print(module2package)

for k in module2package.keys():
module2package[k]=sorted(set(module2package[k]))

#h = open('new_module_to_package.yaml', 'w')
#yaml.dump(module2package,h)

G = nx.DiGraph()
with open('function-calls-db.txt') as f:
for line in f:
Expand All @@ -78,27 +67,20 @@
if epfuncre.search(fields[3]):
epfuncs.add(fields[3])
if fields[2] == ' overrides function ':
if baseclass.search(fields[3]):
if baseclassre.match(fields[3]):
G.add_edge(fields[1], fields[3], kind=' overrides function ')
if topfunc.search(fields[3]) and comp_mods_regex.search(fields[1]):
if topfuncre.search(fields[1]) and comp_mods_regex.search(fields[1]):
toplevelfuncs.add(fields[1])
else:
G.add_edge(fields[3], fields[1], kind=' overriden function calls function ')
if epfuncre.search(fields[3]):
epfuncs.add(fields[3])

print('Top Level Functions')
for tlf in toplevelfuncs:
print(tlf)
print('End Point Functions')
for epf in epfuncs:
print(epf)

print('Callstacks')
callstacks = set()
for tfunc in toplevelfuncs:
for epfunc in epfuncs:
if G.has_node(tfunc) and G.has_node(epfunc) and nx.has_path(G, tfunc, epfunc):
for path in nx.all_shortest_paths(G, tfunc, epfunc):
# path = nx.shortest_path(G, tfunc, epfunc)
cs = str("")
previous = str("")
for p in path:
Expand All @@ -111,18 +93,15 @@
previous = stripped
if cs not in callstacks:
callstacks.add(cs)
print(cs)

report = dict()
for key in sorted(set(module2package.keys())):
for value in sorted(set(module2package[key])):
if comp_mods_regex.match(value):
print(key, value)
regex_str = r'\b%s\b'%value
vre=re.compile(regex_str)
for callstack in sorted(callstacks):
if vre.search(callstack):
print(callstack)
report.setdefault(str(key), {}).setdefault(str(value), []).append(str(callstack))

r = open('eventsetuprecord-get.yaml', 'w')
Expand Down

0 comments on commit ca3787e

Please sign in to comment.