Home | History | Annotate | Download | only in tracing
      1 #!/usr/bin/env python
      2 # Copyright 2015 The Chromium Authors. All rights reserved.
      3 # Use of this source code is governed by a BSD-style license that can be
      4 # found in the LICENSE file.
      5 
      6 """Produces a dot file showing dependency relationships between modules.
      7 
      8 The dot file contains a text-based representation of a directed graph that
      9 explains why given module names were included in a trace_viewer config.
     10 
     11 Example usage:
     12 $ ./why_imported ui.analysis.analysis_view > ~/analysis_view.dot
     13 
     14 This can then be converted to a graphical representation with the dot tool:
     15 $ dot -Grankdir=LR -Tpng ~/analysis_view.dot -o ~/analysis_view.png
     16 """
     17 
     18 import sys
     19 import optparse
     20 
     21 from tracing import tracing_project
     22 
     23 def Main(args):
     24   project = tracing_project.TracingProject()
     25 
     26   parser = optparse.OptionParser(
     27       usage='%prog <options> moduleNames', epilog=__doc__)
     28   parser.add_option(
     29       '--config', type='choice', choices=project.GetConfigNames())
     30   options, args = parser.parse_args(args)
     31 
     32   if options.config:
     33     names = ['tracing',
     34              project.GetModuleNameForConfigName(options.config)]
     35     load_sequence = project.CalcLoadSequenceForModuleNames(names)
     36   else:
     37     parser.parse_err('Unsupported')
     38   print project.GetDominatorGraphForModulesNamed(args, load_sequence)
     39 
     40 
     41 if __name__ == '__main__':
     42   sys.exit(Main(sys.argv[1:]))
     43