Visualize the calling relationship between functions in python

When there are a lot of project files, how to effectively sort out the relationship between the project files is particularly important! ! !

Use the following three modules (mainly 1 and 2) to generate a function call graph:

1. Graphviz (Graph Visualization Software-Graph Visualization Software)

Two, pycallgraph (creating python visualization graphs)

3. Objgraph (see python object graph) please refer to: https://blog.csdn.net/anque1234/article/details/101423303?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-6.control&depth_1-utm_source= distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-6.control


一、graphviz

 graphviz is a graph visualization software that can use dot files to generate relational graphs.

1. Download and install graphviz

Download link:  https://graphviz.gitlab.io/_pages/Download/windows/graphviz-2.38.msi

Note: The installation path can be chosen arbitrarily

2. Configure environment variables

For example, my installation path is

c:\Graphviz2.38

Then add the following items in the system environment variable path

c:\Graphviz2.38\bin

Enter dot --help to verify whether the installation is successful, the following result indicates that the installation is successful.

3. Install pycallgraph

pip install pycallgraph

Two, pycallgraph

pycallgraph can create python functional relationship visualization graphs, because it depends on the dot command, you need to install graphviz first.

1. Download and install

Install from official website source code or use pip:

pip install pycallgraph

 2. Import the following library functions into the code

from pycallgraph import PyCallGraph
from pycallgraph.output import GraphvizOutput

 Then add the red box content:

 After the program is finished, the basic.png file is generated in the current directory, and the effect is as shown in the figure below after opening.

Reference: https://www.codercto.com/a/61853.html

 

Guess you like

Origin blog.csdn.net/MasterCayman/article/details/113001034