tree: 57636cc96797f99ed339048743db63d6799c4c0c [path history] [tgz]
  1. js/
  2. .style.yapf
  3. chrome_names.py
  4. chrome_names_unittest.py
  5. class_dependency.py
  6. class_dependency_unittest.py
  7. class_json_consts.py
  8. count_cycles.py
  9. count_cycles_unittest.py
  10. diff_graphs.py
  11. DIR_METADATA
  12. generate_json_dependency_graph.py
  13. generate_json_dependency_graph_unittest.py
  14. graph.py
  15. graph_unittest.py
  16. group_json_consts.py
  17. java_group.py
  18. java_group_unittest.py
  19. json_consts.py
  20. modularization_stats.py
  21. OWNERS
  22. package_dependency.py
  23. package_dependency_unittest.py
  24. PRESUBMIT.py
  25. print_class_dependencies.py
  26. print_dependencies_helper.py
  27. print_dependencies_helper_unittest.py
  28. print_package_dependencies.py
  29. README.md
  30. serialization.py
  31. serialization_unittest.py
  32. start_server.sh
  33. target_dependency.py
  34. target_dependency_unittest.py
  35. upload_html_viewer.py
android/dependency_analysis/README.md

Chrome Android Dependency Analysis Tool

Overview

As part of Chrome Modularization, this directory contains various tools for analyzing the dependencies contained within the Chrome Android project.

If you'd like to just view the graph, the simplest way is to use the script:

tools/android/dependency_analysis/start_server.sh

Usage

Start by generating a JSON dependency file with a snapshot of the dependencies for your JAR files using the JSON dependency generator command-line tool.

This snapshot file can then be used as input for various other analysis tools listed below.

See the visualization js/README.md for details on how to start a local server to view your local dependency graphs.

Command-line tools

The usage information for any of the following tools is also accessible via toolname -h or toolname --help.

JSON Dependency Generator

Runs jdeps (dependency analysis tool) on all JARs a root build target depends on and writes the resulting dependency graph into a JSON file. The default root build target is chrome/android:monochrome_public_bundle.

usage: generate_json_dependency_graph.py [-h] -o OUTPUT [-C BUILD_OUTPUT_DIR]
                                         [-p PREFIX] [-t TARGET]
                                         [-d CHECKOUT_DIR] [-j JDEPS_PATH]
                                         [-g GN_PATH] [--skip-rebuild]
                                         [--show-ninja] [-v]

Runs jdeps (dependency analysis tool) on all JARs and writes the resulting
dependency graph into a JSON file.
options:
  -h, --help            show this help message and exit
  -C BUILD_OUTPUT_DIR, --build_output_dir BUILD_OUTPUT_DIR
                        Build output directory, will attempt to guess if not
                        provided.
  -p PREFIX, --prefix PREFIX
                        If any package prefixes are passed, these will be used
                        to filter classes so that only classes with a package
                        matching one of the prefixes are kept in the graph. By
                        default no filtering is performed.
  -t TARGET, --target TARGET
                        If a specific target is specified, only transitive
                        deps of that target are included in the graph. By
                        default all known javac jars are included.
  -d CHECKOUT_DIR, --checkout-dir CHECKOUT_DIR
                        Path to the chromium checkout directory. By default
                        the checkout containing this script is used.
  -j JDEPS_PATH, --jdeps-path JDEPS_PATH
                        Path to the jdeps executable.
  -g GN_PATH, --gn-path GN_PATH
                        Path to the gn executable.
  --skip-rebuild        Skip rebuilding, useful on bots where compile is a
                        separate step right before running this script.
  --show-ninja          Used to show ninja output.
  -v, --verbose         Used to display detailed logging.

required arguments:
  -o OUTPUT, --output OUTPUT
                        Path to the file to write JSON output to. Will be
                        created if it does not yet exist and overwrite
                        existing content if it does.

Class Dependency Audit

Given a JSON dependency graph, output the class-level dependencies for a given list of classes.

An example is given at the end of this page. To see the options:

tools/android/dependency_analysis/print_class_dependencies.py -h

Package Dependency Audit

Given a JSON dependency graph, output the package-level dependencies for a given package and the class dependencies comprising those dependencies.

An example is given at the end of this page. To see the options:

tools/android/dependency_analysis/print_package_dependencies.py -h

Package Cycle Counting

Given a JSON dependency graph, counts package cycles up to a given size.

To see the options:

tools/android/dependency_analysis/count_cycles.py -h

Example Usage

This Linux example assumes Chromium is contained in a directory ~/cr and that Chromium has been built as per the instructions here, although the only things these assumptions affect are the file paths.

$ tools/android/dependency_analysis/generate_json_dependency_graph.py -C out/Debug -o ~/graph.json
>>> Running jdeps and parsing output...
>>> Parsed class-level dependency graph, got 3239 nodes and 19272 edges.
>>> Created package-level dependency graph, got 500 nodes and 4954 edges.
>>> Dumping JSON representation to ~/graph.json.

tools/android/dependency_analysis/print_class_dependencies.py -f ~/graph.json -c AppHooks
>>> Printing class dependencies for org.chromium.chrome.browser.AppHooks:
>>> 35 inbound dependency(ies) for org.chromium.chrome.browser.AppHooks:
>>> 	org.chromium.chrome.browser.AppHooksImpl
>>> 	org.chromium.chrome.browser.ChromeActivity
>>> ...

tools/android/dependency_analysis/print_package_dependencies.py -f ~/graph.json -p chrome.browser
>>> Printing package dependencies for org.chromium.chrome.browser:
>>> 121 inbound dependency(ies) for org.chromium.chrome.browser:
>>> 	org.chromium.chrome.browser.about_settings -> org.chromium.chrome.browser
>>> 	1 class edge(s) comprising the dependency:
>>> 		AboutChromeSettings -> ChromeVersionInfo
>>> ...