CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  print("Non-const static variable \'"+re.sub(farg, "()",
55  static)+"' is accessed in call stack '", end=' ')
56  for i in range(0, len(path)-1):
57  print(re.sub(farg, "()", path[i]) +
58  G[path[i]][path[i+1]]['kind'], end=' ')
59  print(re.sub(farg, "()", path[i+1])+"' ,", end=' ')
60  for key in G[tfunc].keys():
61  if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ':
62  print("'"+re.sub(farg, "()", tfunc)+"' overrides '" +
63  re.sub(farg, "()", key)+"'", end=' ')
64  print()
65 
66  print("In call stack ' ", end=' ')
67  for i in range(0, len(path)-1):
68  print(re.sub(farg, "()", path[i]) +
69  G[path[i]][path[i+1]]['kind'], end=' ')
70  print(re.sub(farg, "()", path[i+1])+"' is accessed ,", end=' ')
71  for key in G[tfunc].keys():
72  if 'kind' in G[tfunc][key] and G[tfunc][key]['kind'] == ' overrides function ':
73  print("'"+re.sub(farg, "()", tfunc)+"' overrides '" +
74  re.sub(farg, "()", key)+"'", end=' ')
75  print()
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47