ATLAS Offline Software
Classes | Functions
dlldep Namespace Reference

Classes

class  Cache
 
class  Color
 
class  SharedLib
 
class  Stats
 

Functions

def anaLib (lib, opt, cache, select=[], ignore=[], depth=0)
 
def processLib (lib, opt, dotFileName=None)
 
def printStats ()
 
def main ()
 

Function Documentation

◆ anaLib()

def dlldep.anaLib (   lib,
  opt,
  cache,
  select = [],
  ignore = [],
  depth = 0 
)
Get dependencies of shared library recursively

Definition at line 143 of file dlldep.py.

143 def anaLib(lib, opt, cache, select = [], ignore = [], depth = 0):
144  """Get dependencies of shared library recursively"""
145 
146  def process(path):
147  """Should this lib be processed?"""
148  for regexp in select:
149  if regexp.match(path): return True
150  if len(select)>0: return False
151 
152  for regexp in ignore:
153  if regexp.match(path): return False
154  return True
155 
156  if opt.maxdepth and depth>=opt.maxdepth: return
157 
158  # Check if we analyzed this lib already
159  cachedlib = cache.myfiles.get(lib)
160  if cachedlib:
161  # Always save minimum distance
162  if depth<cachedlib.distance: cachedlib.distance=depth
163  return
164 
165  shlib = SharedLib(depth, lib)
166  cache.add(shlib)
167 
168  for l in shlib.deplibs:
169  if process(l):
170  cache.dot(' "%s" -> "%s"' % (basename(lib), basename(l)))
171  anaLib(l, opt, cache, select, ignore, depth+1)
172 
173  return
174 
175 

◆ main()

def dlldep.main ( )

Definition at line 238 of file dlldep.py.

238 def main():
239 
240  import optparse
241  parser = optparse.OptionParser(description="Create runtime dependecy graph for shared library. The output is a graph in DOT language. To visualize it use, e.g. 'dot -O -Tps mygraph.dot'. The rectangular nodes represent direct dependencies. Nodes belonging to the same project have the same color.",
242  usage="%prog [OPTIONS] LIB [LIB...]")
243 
244  parser.add_option("-o", "--output",
245  help="File for DOT source code (default is LIB.dot)")
246 
247  parser.add_option("-d", "--maxdepth", type="int",
248  help="Maximum depth of dependency tree [1..]")
249 
250  parser.add_option("-f", "--filter", action="append",
251  help="Only analyze libraries matching regular expression (can be specified multiple times) [default: .*atlas/software.*]")
252 
253  parser.add_option("--nocolor", action="store_true",
254  help="Do not use colors")
255 
256  parser.add_option("-s", "--stats", action="store_true",
257  help="Print statistics")
258 
259  (opt, args) = parser.parse_args()
260  if len(args)==0:
261  parser.error("Invalid number of arguments specified")
262 
263 
264  if len(args)>1 and opt.output:
265  print ("Multiple libraries specified. Ignoring output file name.")
266  opt.output = None
267 
268  for lib in args:
269  processLib(lib, opt, opt.output)
270 
271  if opt.stats:
272  printStats()
273 
274  return 0
275 
276 

◆ printStats()

def dlldep.printStats ( )
Print statistics

Definition at line 226 of file dlldep.py.

226 def printStats():
227  """Print statistics"""
228  import operator
229 
230  print ("%-50s %7s %7s" % ("Library dependencies","Direct","Total"))
231  print ("-"*70)
232  for s in sorted(Cache.stats, key=operator.attrgetter("depDirect"), reverse=True):
233  print ("%-50s %7d %7d" % (basename(s.lib), s.depDirect, s.depTotal))
234 
235  return
236 
237 

◆ processLib()

def dlldep.processLib (   lib,
  opt,
  dotFileName = None 
)
Process one library

Definition at line 176 of file dlldep.py.

176 def processLib(lib, opt, dotFileName = None):
177  """Process one library"""
178 
179  cache = Cache()
180  dot = cache.dot # shortcut
181 
182  dot('digraph DependencyTree {')
183  dot(' ratio=0.9 nodesep=0.05') # some reasonable default values
184  dot(' "%s" [shape=box]' % basename(lib))
185 
186  select = []
187  ignore = [] # currently not used
188  if opt.filter:
189  for f in opt.filter: select += [re.compile(f)]
190  else:
191  select = [re.compile(".*atlas/software.*")]
192 
193  anaLib(lib, opt, cache, select, ignore)
194 
195  # Declare style of all nodes
196  for l,v in cache.myfiles.items():
197  style = {}
198  # Special style for direct dependencies
199  if v.distance==1:
200  style["shape"] = "box"
201 
202  if not opt.nocolor:
203  style["style"] = "filled"
204  style["fillcolor"] = Color.get(l)
205 
206  dot(' "%s"' % (basename(l)), style)
207 
208  dot('}')
209 
210  # Write output to file
211  if dotFileName: outFile = open(dotFileName, "w")
212  else: outFile = open(basename(lib)+".dot", "w")
213 
214  cache.writeDOT(outFile)
215 
216  # Calculate statistics
217  if opt.stats:
218  st = Stats(lib, cache)
219  Cache.stats += [st]
220  return st
221 
222  return None
223 
224 
225 
dlldep.processLib
def processLib(lib, opt, dotFileName=None)
Definition: dlldep.py:176
dlldep.anaLib
def anaLib(lib, opt, cache, select=[], ignore=[], depth=0)
Definition: dlldep.py:143
SUSY_SimplifiedModel_PostInclude.process
string process
Definition: SUSY_SimplifiedModel_PostInclude.py:42
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
dlldep.printStats
def printStats()
Definition: dlldep.py:226
Trk::open
@ open
Definition: BinningType.h:40
dlldep.main
def main()
Definition: dlldep.py:238
dot
Definition: dot.py:1
beamspotman.basename
basename
Definition: beamspotman.py:640