Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:49

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             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 ':
0055                 for key in G[tfunc].keys():
0056                     if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ':
0057                         print("Non-const static variable \'"+re.sub(farg, "()",
0058                                                                     static)+"' is accessed in call stack '", end=' ')
0059                         for i in range(0, len(path)-1):
0060                             print(re.sub(farg, "()", path[i]) +
0061                                   G[path[i]][path[i+1]]['kind'], end=' ')
0062                         print(re.sub(farg, "()", path[i+1])+"' ,", end=' ')
0063                         print("'"+re.sub(farg, "()", tfunc)+"' overrides '" +
0064                               re.sub(farg, "()", key)+"'", end=' ')
0065                         print()
0066 
0067                         print("In call stack ' ", end=' ')
0068                         for i in range(0, len(path)-1):
0069                             print(re.sub(farg, "()", path[i]) +
0070                                   G[path[i]][path[i+1]]['kind'], end=' ')
0071                         print(re.sub(farg, "()", path[i+1])+"' is accessed ,", end=' ')
0072                         print("'"+re.sub(farg, "()", tfunc)+"' overrides '" +
0073                               re.sub(farg, "()", key)+"'", end=' ')
0074                         print()
0075 
0076             else:
0077                 for key in G[tfunc].keys():
0078                     if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ' and not (key.startswith('edm::one') and 'TFileService::' in static):
0079                         print("Known thread unsafe function '"+re.sub(farg, "()",
0080                                                                        static)+"' is called in call stack '", end=' ')
0081                         for i in range(0, len(path)-1):
0082                             print(re.sub(farg, "()", path[i]) +
0083                                   G[path[i]][path[i+1]]['kind'], end=' ')
0084                         print(re.sub(farg, "()", path[i+1])+"' ,", end=' ')
0085                         print("'"+re.sub(farg, "()", tfunc)+"' overrides '" +
0086                                   re.sub(farg, "()", key)+"'", end=' ')
0087                         print()
0088 
0089                         print("In call stack ' ", end=' ')
0090                         for i in range(0, len(path)-1):
0091                             print(re.sub(farg, "()", path[i]) +
0092                                   G[path[i]][path[i+1]]['kind'], end=' ')
0093                         print(re.sub(farg, "()", path[i+1])+"' known thread unsafe function '"+re.sub(farg, "()", static)+"' is called, ", end=' ')
0094                         print("'"+re.sub(farg, "()", tfunc)+"' overrides '" +
0095                                       re.sub(farg, "()", key)+"'", end=' ')
0096                         print()