Skip to main content

Show python modules dependency graph and static memory usage.

Project description

Module Graph

Show python modules dependency graph and static memory usage.

Install

First you need graphviz installed in your system.

  • Mac:

    brew install graphviz
    
  • Ubuntu:

    sudo apt-get update
    sudo apt-get install graphviz libgraphviz-dev pkg-config
    

Then:

pip install 'module-graph[all]'

Usage

Analysis current installed modules

Travel all modules and generate graph data:

python -m module_graph.run_traveler

Command reference:

usage: run_traveler.py [-h] [--modules MODULES] [--ignore IGNORE]

Module Graph Traveler

optional arguments:
  -h, --help         show this help message and exit
  --modules MODULES  top level modules to check, default all modules
  --ignore IGNORE    ignore modules (shell patterns)

Analysis modules used by application

Warning: the hooker will do crazy patch to sys module, your application may be slower or crash!

Setup hooker as early as possible in application.

import module_graph

if __name__ == "__main__":
    memory_hooker = module_graph.setup_hooker(
        save_to='data/module_graph.json', verbose=True)

Run your aplication for a while, then stop it. The hooker will generate data for all modules used by application.

Render graph

Use module-graph command to render graph, for example:

module-graph --input-filepath data/module_graph.json

Command reference:

usage: module-graph [-h] [--modules-filepath MODULES_FILEPATH]
                    [--input-filepath INPUT_FILEPATH]
                    [--output-filepath OUTPUT_FILEPATH]
                    [--threshold THRESHOLD]

Module Graph Render

optional arguments:
  -h, --help            show this help message and exit
  --modules-filepath MODULES_FILEPATH
                        modules to render, default all modules
  --input-filepath INPUT_FILEPATH
                        the module graph data generated by hooker (json file)
  --output-filepath OUTPUT_FILEPATH
                        render output PDF filepath
  --threshold THRESHOLD
                        donot show module which memory usage < threshold (MB)

How it work

It patch sys.meta_path, sys.modules and all module loaders, then record memory before and after module import.

License

This package is distributed under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

module-graph-0.0.1.tar.gz (8.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page