Magic function for gprof2dot
to profile any Python statement as a DOT graph in JupyterLab or Jupyter Notebook.
Make sure you've the Python package gprof2dot_magic
.
pip install gprof2dot_magic
This will also install its dependencies gprof2dot
and graphviz
.
It is also important to have the Graphviz software installed.
Apperently you can use conda as such (I don't have conda):
conda install python-graphviz
Without conda
For macOS:
brew install graphviz
For Windows (source):
- Install windows package from: https://graphviz.gitlab.io/_pages/Download/Download_windows.html
- Add
C:\Program Files (x86)\Graphviz2.38\bin
to User path - Add
C:\Program Files (x86)\Graphviz2.38\bin\dot.exe
to System Path
Note: close your "cmd" in which jupyter lab/notebook is running. Existing running CMD dont catch the new changes in Environment variables
To enable the magic function, first load the gprof2dot_magic
module
%load_ext gprof2dot_magic
and then profile any line statement as a DOT graph as such:
%gprof2dot print('hello world')