显示python模块依赖关系图和静态内存使用情况。
module-graph的Python项目详细描述
模块图
显示python模块依赖关系图和静态内存使用情况。在
安装
首先需要在系统中安装graphviz。在
- 在
马克:
在brew install graphviz
- 在
Ubuntu:
^{pr2}$ 在
然后:
pip install 'module-graph[all]'
使用
分析当前安装的模块
移动所有模块并生成图形数据:
python -m module_graph.run_traveler
命令参考:
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)
应用程序使用的分析模块
Warning: the hooker will do crazy patch to
sys
module, your application may be slower or crash!
在应用中尽早安装钩子。在
importmodule_graphif__name__=="__main__":memory_hooker=module_graph.setup_hooker(save_to='data/module_graph.json',verbose=True)
运行你的应用程序一段时间,然后停止它。 钩子将为应用程序使用的所有模块生成数据。在
渲染图形
使用module-graph
命令呈现图形,例如:
module-graph --input-filepath data/module_graph.json
命令参考:
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)
工作原理
它修补sys.meta_path
,sys.modules
和所有模块加载程序,
然后记录模块导入前后的内存。在
许可证
这个软件包是在麻省理工学院许可下发布的。在
- 项目
标签: