Home | History | Annotate | Download | only in bin
      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 tracing.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 os
     19 import sys
     20 import argparse
     21 
     22 
     23 def Main():
     24   project = tracing_project.TracingProject()
     25 
     26   parser = argparse.ArgumentParser(
     27       usage='%(prog)s <options> moduleNames', epilog=__doc__)
     28   parser.add_argument('--config', choices=project.GetConfigNames())
     29   parser.add_argument('module_names', nargs='+')
     30   args = parser.parse_args()
     31 
     32   if args.config:
     33     names = [project.GetModuleNameForConfigName(options.config)]
     34     vulcanizer = project.CreateVulcanizer()
     35     load_sequence = vulcanizer.CalcLoadSequenceForModuleNames(names)
     36   else:
     37     parser.error('No config specified.')
     38   print vulcanizer.GetDominatorGraphForModulesNamed(
     39       args.module_names, load_sequence)
     40 
     41 
     42 if __name__ == '__main__':
     43   tracing_path = os.path.abspath(os.path.join(
     44     os.path.dirname(os.path.realpath(__file__)), '..'))
     45   sys.path.append(tracing_path)
     46   import tracing_project
     47   tracing_project.UpdateSysPathIfNeeded()
     48   sys.exit(Main())
     49