CMS 3D CMS Logo

statics.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 from __future__ import print_function
3 from builtins import range
4 import re
5 topfunc = re.compile("::(produce|analyze|filter|beginLuminosityBlock|beginRun|beginStream|streamBeginRun|streamBeginLuminosityBlock|streamEndRun|streamEndLuminosityBlock|globalBeginRun|globalEndRun|globalBeginLuminosityBlock|globalEndLuminosityBlock|endRun|endLuminosityBlock)\(")
6 baseclass = re.compile("edm::(one::|stream::|global::)?ED(Producer|Filter|Analyzer)(Base)?")
7 farg = re.compile("\(.*\)")
8 fre = re.compile("function")
9 
10 statics = set()
11 toplevelfuncs = set()
12 skipfunc = re.compile("(edm::(LuminosityBlock::|Run::|Event::)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::)")
13 skipfuncs=set()
14 
15 import networkx as nx
16 G=nx.DiGraph()
17 
18 import fileinput
19 for line in fileinput.input(files =('function-statics-db.txt','function-calls-db.txt')):
20  if fre.search(line):
21  fields = line.split("'")
22  if topfunc.search(fields[1]) and not baseclass.search(fields[1]): toplevelfuncs.add(fields[1])
23  if fields[2] == ' calls function ':
24  if skipfunc.search(line) : skipfuncs.add(line)
25  else : G.add_edge(fields[1],fields[3],kind=fields[2])
26  if fields[2] == ' overrides function ' :
27  if baseclass.search(fields[3]) :
28  if topfunc.search(fields[3]) : toplevelfuncs.add(fields[1])
29  G.add_edge(fields[1],fields[3],kind=fields[2])
30  else :
31  if skipfunc.search(line) : skipfuncs.add(line)
32  else : G.add_edge(fields[3],fields[1],kind=' calls function ')
33  if fields[2] == ' static variable ' :
34  G.add_edge(fields[1],fields[3],kind=fields[2])
35  statics.add(fields[3])
36  if fields[2] == ' known thread unsafe function ' :
37  G.add_edge(fields[1],fields[3],kind=' known thread unsafe function ')
38  statics.add(fields[3])
39 fileinput.close()
40 
41 for tfunc in sorted(toplevelfuncs):
42  for static in sorted(statics):
43  if nx.has_path(G,tfunc,static):
44  path = nx.shortest_path(G,tfunc,static)
45 
46  print("Non-const static variable \'"+re.sub(farg,"()",static)+"' is accessed in call stack '", end=' ')
47  for i in range(0,len(path)-1) :
48  print(re.sub(farg,"()",path[i])+G[path[i]][path[i+1]]['kind'], end=' ')
49  print(re.sub(farg,"()",path[i+1])+"' ,", end=' ')
50  for key in G[tfunc].keys() :
51  if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ' :
52  print("'"+re.sub(farg,"()",tfunc)+"' overrides '"+re.sub(farg,"()",key)+"'", end=' ')
53  print()
54 
55  print("In call stack ' ", end=' ')
56  for i in range(0,len(path)-1) :
57  print(re.sub(farg,"()",path[i])+G[path[i]][path[i+1]]['kind'], end=' ')
58  print(re.sub(farg,"()",path[i+1])+"' is accessed ,", end=' ')
59  for key in G[tfunc].keys() :
60  if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ' :
61  print("'"+re.sub(farg,"()",tfunc)+"' overrides '"+re.sub(farg,"()",key)+"'", end=' ')
62  print()
63 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66