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