Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-29 02:32:58

0001 #! /usr/bin/env python3
0002 from __future__ import print_function
0003 import fileinput
0004 import networkx as nx
0005 from builtins import range
0006 import re
0007 topfunc = re.compile(r"::(produce|analyze|filter|beginLuminosityBlock|beginRun|beginStream|streamBeginRun|streamBeginLuminosityBlock|streamEndRun|streamEndLuminosityBlock|globalBeginRun|globalEndRun|globalBeginLuminosityBlock|globalEndLuminosityBlock|endRun|endLuminosityBlock)\(")
0008 baseclass = re.compile(
0009     "edm::(one::|stream::|global::)?ED(Producer|Filter|Analyzer)(Base)?")
0010 farg = re.compile(r"\(.*\)")
0011 fre = re.compile("function")
0012 
0013 statics = set()
0014 toplevelfuncs = set()
0015 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::)")
0016 skipfuncs = set()
0017 
0018 G = nx.DiGraph()
0019 
0020 for line in fileinput.input(files=('function-statics-db.txt', 'function-calls-db.txt')):
0021     if fre.search(line):
0022         fields = line.split("'")
0023         if topfunc.search(fields[1]) and not baseclass.search(fields[1]):
0024             toplevelfuncs.add(fields[1])
0025         if fields[2] == ' calls function ':
0026             if skipfunc.search(line):
0027                 skipfuncs.add(line)
0028             else:
0029                 G.add_edge(fields[1], fields[3], kind=fields[2])
0030         if fields[2] == ' overrides function ':
0031             if baseclass.search(fields[3]):
0032                 if topfunc.search(fields[3]):
0033                     toplevelfuncs.add(fields[1])
0034                 G.add_edge(fields[1], fields[3], kind=fields[2])
0035             else:
0036                 if skipfunc.search(line):
0037                     skipfuncs.add(line)
0038                 else:
0039                     G.add_edge(fields[3], fields[1], kind=' calls function ')
0040         if fields[2] == ' static variable ':
0041             G.add_edge(fields[1], fields[3], kind=fields[2])
0042             statics.add(fields[3])
0043         if fields[2] == ' known thread unsafe function ':
0044             G.add_edge(fields[1], fields[3],
0045                        kind=' known thread unsafe function ')
0046             statics.add(fields[3])
0047 fileinput.close()
0048 
0049 for tfunc in sorted(toplevelfuncs):
0050     for static in sorted(statics):
0051         if G.has_node(tfunc) and G.has_node(static) and nx.has_path(G, tfunc, static):
0052             path = nx.shortest_path(G, tfunc, static)
0053 
0054             print("Non-const static variable \'"+re.sub(farg, "()",
0055                                                         static)+"' is accessed in call stack '", end=' ')
0056             for i in range(0, len(path)-1):
0057                 print(re.sub(farg, "()", path[i]) +
0058                       G[path[i]][path[i+1]]['kind'], end=' ')
0059             print(re.sub(farg, "()", path[i+1])+"' ,", end=' ')
0060             for key in G[tfunc].keys():
0061                 if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ':
0062                     print("'"+re.sub(farg, "()", tfunc)+"' overrides '" +
0063                           re.sub(farg, "()", key)+"'", end=' ')
0064             print()
0065 
0066             print("In call stack ' ", end=' ')
0067             for i in range(0, len(path)-1):
0068                 print(re.sub(farg, "()", path[i]) +
0069                       G[path[i]][path[i+1]]['kind'], end=' ')
0070             print(re.sub(farg, "()", path[i+1])+"' is accessed ,", end=' ')
0071             for key in G[tfunc].keys():
0072                 if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ':
0073                     print("'"+re.sub(farg, "()", tfunc)+"' overrides '" +
0074                           re.sub(farg, "()", key)+"'", end=' ')
0075             print()