CMS 3D CMS Logo

statics.py
Go to the documentation of this file.
1 #! /usr/bin/env python3
2 from __future__ import print_function
3 import fileinput
4 import networkx as nx
5 from builtins import range
6 import re
7 topfunc = re.compile(r"::(produce|analyze|filter|beginLuminosityBlock|beginRun|beginStream|streamBeginRun|streamBeginLuminosityBlock|streamEndRun|streamEndLuminosityBlock|globalBeginRun|globalEndRun|globalBeginLuminosityBlock|globalEndLuminosityBlock|endRun|endLuminosityBlock)\(")
8 baseclass = re.compile(
9  "edm::(one::|stream::|global::)?ED(Producer|Filter|Analyzer)(Base)?")
10 farg = re.compile(r"\(.*\)")
11 fre = re.compile("function")
12 
13 statics = set()
14 toplevelfuncs = set()
15 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::)")
16 skipfuncs = set()
17 
18 G = nx.DiGraph()
19 
20 for line in fileinput.input(files=('function-statics-db.txt', 'function-calls-db.txt')):
21  if fre.search(line):
22  fields = line.split("'")
23  if topfunc.search(fields[1]) and not baseclass.search(fields[1]):
24  toplevelfuncs.add(fields[1])
25  if fields[2] == ' calls function ':
26  if skipfunc.search(line):
27  skipfuncs.add(line)
28  else:
29  G.add_edge(fields[1], fields[3], kind=fields[2])
30  if fields[2] == ' overrides function ':
31  if baseclass.search(fields[3]):
32  if topfunc.search(fields[3]):
33  toplevelfuncs.add(fields[1])
34  G.add_edge(fields[1], fields[3], kind=fields[2])
35  else:
36  if skipfunc.search(line):
37  skipfuncs.add(line)
38  else:
39  G.add_edge(fields[3], fields[1], kind=' calls function ')
40  if fields[2] == ' static variable ':
41  G.add_edge(fields[1], fields[3], kind=fields[2])
42  statics.add(fields[3])
43  if fields[2] == ' known thread unsafe function ':
44  G.add_edge(fields[1], fields[3],
45  kind=' known thread unsafe function ')
46  statics.add(fields[3])
47 fileinput.close()
48 
49 for tfunc in sorted(toplevelfuncs):
50  for static in sorted(statics):
51  if G.has_node(tfunc) and G.has_node(static) and nx.has_path(G, tfunc, static):
52  path = nx.shortest_path(G, tfunc, static)
53 
54  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 ':
55  for key in G[tfunc].keys():
56  if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ':
57  print("Non-const static variable \'"+re.sub(farg, "()",
58  static)+"' is accessed in call stack '", end=' ')
59  for i in range(0, len(path)-1):
60  print(re.sub(farg, "()", path[i]) +
61  G[path[i]][path[i+1]]['kind'], end=' ')
62  print(re.sub(farg, "()", path[i+1])+"' ,", end=' ')
63  print("'"+re.sub(farg, "()", tfunc)+"' overrides '" +
64  re.sub(farg, "()", key)+"'", end=' ')
65  print()
66 
67  print("In call stack ' ", end=' ')
68  for i in range(0, len(path)-1):
69  print(re.sub(farg, "()", path[i]) +
70  G[path[i]][path[i+1]]['kind'], end=' ')
71  print(re.sub(farg, "()", path[i+1])+"' is accessed ,", end=' ')
72  print("'"+re.sub(farg, "()", tfunc)+"' overrides '" +
73  re.sub(farg, "()", key)+"'", end=' ')
74  print()
75 
76  else:
77  for key in G[tfunc].keys():
78  if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ' and not (key.startswith('edm::one') and 'TFileService::' in static):
79  print("Known thread unsafe function '"+re.sub(farg, "()",
80  static)+"' is called in call stack '", end=' ')
81  for i in range(0, len(path)-1):
82  print(re.sub(farg, "()", path[i]) +
83  G[path[i]][path[i+1]]['kind'], end=' ')
84  print(re.sub(farg, "()", path[i+1])+"' ,", end=' ')
85  print("'"+re.sub(farg, "()", tfunc)+"' overrides '" +
86  re.sub(farg, "()", key)+"'", end=' ')
87  print()
88 
89  print("In call stack ' ", end=' ')
90  for i in range(0, len(path)-1):
91  print(re.sub(farg, "()", path[i]) +
92  G[path[i]][path[i+1]]['kind'], end=' ')
93  print(re.sub(farg, "()", path[i+1])+"' known thread unsafe function '"+re.sub(farg, "()", static)+"' is called, ", end=' ')
94  print("'"+re.sub(farg, "()", tfunc)+"' overrides '" +
95  re.sub(farg, "()", key)+"'", end=' ')
96  print()
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47