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 details)

Uploaded Source

File details

Details for the file module-graph-0.0.1.tar.gz.

File metadata

  • Download URL: module-graph-0.0.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.9

File hashes

Hashes for module-graph-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8d28b8ca24a7f83f8b4388b2fabfb17802e6ac489e33488b463dc67e168f8338
MD5 06ce93a7bd1b21e1d1a6757fa5badc13
BLAKE2b-256 1e7f5342a99e5dfaf0a5b9db1239878398461195ca34906125cb5a7c54b9981f

See more details on using hashes here.

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