File indexing completed on 2024-12-01 23:40:44
0001
0002 import fileinput
0003 import networkx as nx
0004 from builtins import range
0005 import re
0006 topfunc = re.compile(r"::(produce|analyze|filter|beginLuminosityBlock|beginRun|beginStream|streamBeginRun|streamBeginLuminosityBlock|streamEndRun|streamEndLuminosityBlock|globalBeginRun|globalEndRun|globalBeginLuminosityBlock|globalEndLuminosityBlock|endRun|endLuminosityBlock)\(")
0007 baseclass = re.compile(
0008 "edm::(one::|stream::|global::)?ED(Producer|Filter|Analyzer)(Base)?")
0009 farg = re.compile(r"\(.*\)")
0010 fre = re.compile("function")
0011
0012 statics = set()
0013 toplevelfuncs = set()
0014 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::)")
0015 skipfuncs = set()
0016
0017 G = nx.DiGraph()
0018
0019 for line in fileinput.input(files=('function-statics-db.txt', 'function-calls-db.txt')):
0020 if fre.search(line):
0021 fields = line.split("'")
0022 if topfunc.search(fields[1]) and not baseclass.search(fields[1]):
0023 toplevelfuncs.add(fields[1])
0024 if fields[2] == ' calls function ':
0025 if skipfunc.search(line):
0026 skipfuncs.add(line)
0027 else:
0028 G.add_edge(fields[1], fields[3], kind=fields[2])
0029 if fields[2] == ' overrides function ':
0030 if baseclass.search(fields[3]):
0031 if topfunc.search(fields[3]):
0032 toplevelfuncs.add(fields[1])
0033 G.add_edge(fields[1], fields[3], kind=fields[2])
0034 else:
0035 if skipfunc.search(line):
0036 skipfuncs.add(line)
0037 else:
0038 G.add_edge(fields[3], fields[1], kind=' calls function ')
0039 if fields[2] == ' static variable ':
0040 G.add_edge(fields[1], fields[3], kind=fields[2])
0041 statics.add(fields[3])
0042 if fields[2] == ' known thread unsafe function ':
0043 G.add_edge(fields[1], fields[3],
0044 kind=' known thread unsafe function ')
0045 statics.add(fields[3])
0046 fileinput.close()
0047
0048 for tfunc in sorted(toplevelfuncs):
0049 for static in sorted(statics):
0050 if G.has_node(tfunc) and G.has_node(static) and nx.has_path(G, tfunc, static):
0051 path = nx.shortest_path(G, tfunc, static)
0052
0053 if 'kind' in G[path[len(path)-2]][path[len(path)-1]] and G[path[len(path)-2]][path[len(path)-1]]['kind'] == ' static variable ':
0054 for key in G[tfunc].keys():
0055 if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ':
0056 print("Non-const static variable \'"+re.sub(farg, "()",
0057 static)+"' is accessed in call stack '", end=' ')
0058 for i in range(0, len(path)-1):
0059 print(re.sub(farg, "()", path[i]) +
0060 G[path[i]][path[i+1]]['kind'], end=' ')
0061 print(re.sub(farg, "()", path[i+1])+"' ,", end=' ')
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 print("'"+re.sub(farg, "()", tfunc)+"' overrides '" +
0072 re.sub(farg, "()", key)+"'", end=' ')
0073 print()
0074
0075 else:
0076 for key in G[tfunc].keys():
0077 if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ' and not (key.startswith('edm::one') and 'TFileService::' in static):
0078 print("Known thread unsafe function '"+re.sub(farg, "()",
0079 static)+"' is called in call stack '", end=' ')
0080 for i in range(0, len(path)-1):
0081 print(re.sub(farg, "()", path[i]) +
0082 G[path[i]][path[i+1]]['kind'], end=' ')
0083 print(re.sub(farg, "()", path[i+1])+"' ,", end=' ')
0084 print("'"+re.sub(farg, "()", tfunc)+"' overrides '" +
0085 re.sub(farg, "()", key)+"'", end=' ')
0086 print()
0087
0088 print("In call stack ' ", end=' ')
0089 for i in range(0, len(path)-1):
0090 print(re.sub(farg, "()", path[i]) +
0091 G[path[i]][path[i+1]]['kind'], end=' ')
0092 print(re.sub(farg, "()", path[i+1])+"' known thread unsafe function '"+re.sub(farg, "()", static)+"' is called, ", end=' ')
0093 print("'"+re.sub(farg, "()", tfunc)+"' overrides '" +
0094 re.sub(farg, "()", key)+"'", end=' ')
0095 print()