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 141 of file dlldep.py.

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

◆ main()

def dlldep.main ( )

Definition at line 236 of file dlldep.py.

236 def main():
237 
238  import optparse
239  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.",
240  usage="%prog [OPTIONS] LIB [LIB...]")
241 
242  parser.add_option("-o", "--output",
243  help="File for DOT source code (default is LIB.dot)")
244 
245  parser.add_option("-d", "--maxdepth", type="int",
246  help="Maximum depth of dependency tree [1..]")
247 
248  parser.add_option("-f", "--filter", action="append",
249  help="Only analyze libraries matching regular expression (can be specified multiple times) [default: .*atlas/software.*]")
250 
251  parser.add_option("--nocolor", action="store_true",
252  help="Do not use colors")
253 
254  parser.add_option("-s", "--stats", action="store_true",
255  help="Print statistics")
256 
257  (opt, args) = parser.parse_args()
258  if len(args)==0:
259  parser.error("Invalid number of arguments specified")
260 
261 
262  if len(args)>1 and opt.output:
263  print ("Multiple libraries specified. Ignoring output file name.")
264  opt.output = None
265 
266  for lib in args:
267  processLib(lib, opt, opt.output)
268 
269  if opt.stats:
270  printStats()
271 
272  return 0
273 
274 

◆ printStats()

def dlldep.printStats ( )
Print statistics

Definition at line 224 of file dlldep.py.

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

◆ processLib()

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

Definition at line 174 of file dlldep.py.

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