• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
8The dot file contains a text-based representation of a directed graph that
9explains why given module names were included in a trace_viewer config.
10
11Example usage:
12$ ./why_imported tracing.ui.analysis.analysis_view > ~/analysis_view.dot
13
14This 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
18import os
19import sys
20import argparse
21
22
23def 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
42if __name__ == '__main__':
43  tracing_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
44                                 os.path.pardir))
45  sys.path.append(tracing_path)
46  import tracing_project
47  tracing_project.UpdateSysPathIfNeeded()
48  sys.exit(Main())
49