⚠ This page is outdated. For more recent information have a look at the english original.
Debugging and Profiling
To enable debugging or profiling copy DEBUG_template.toml to DEBUG.toml and edit it
How create bash script for offline debugging from console
- in
DEBUG.tomlsetcreate_bash_script = true - call inkstitch.py extension from inkscape to create bash script named by bash_file_base in DEBUG.toml
- run bash script from console
Enable debugging
-
set debug_type to one of - vscode, pycharm, pydev, see below for details
- debug_type = vscode -
debugpyfor vscode editor - debug_type = pycharm -
pydevd-pycharmfor pycharm editor - debug_type = pydev -
pydevdfor eclipse editor
- debug_type = vscode -
-
set
debug_enable = trueinDEBUG.toml
or use command line argument-din bash script
or set environment variableINKSTITCH_DEBUG_ENABLE = True(or 1 or yes or y)
Enable profiling
-
set profiler_type to one of - cprofile, profile, pyinstrument, monkeytype
- profiler_type = cprofile -
cProfileprofiler - profiler_type = profile -
profileprofiler - profiler_type = pyinstrument -
pyinstrumentprofiler - profiler_type = monkeytype -
monkeytypeprofiler
- profiler_type = cprofile -
-
set
profile_enable = trueinDEBUG.toml
or use command line argument-pin bash script
or set environment variableINKSTITCH_PROFILE_ENABLE = True(or 1 or yes or y)
Miscellaneous notes
- to disable debugger when running from inkscape set
disable_from_inkscape = trueinDEBUG.toml - to change various output file names see
DEBUG.toml - to disable waiting for debugger to attach (vscode editor) set
wait_attach = falseinDEBUG.toml - to prefer inkscape version of inkex module over pip version set
prefer_pip_inkex = falseinDEBUG.toml
How to debug with …
LiClipse
- Install LiClipse – no need to install Eclipse first
- Start debug server as described here: http://www.pydev.org/manual_adv_remote_debugger.html
- follow the “Note:” to enable the debug server menu item
- Copy and edit a file named
DEBUG.tomlfromDEBUG_template.tomlnext to inkstitch.py in your git clone and setdebug_type = pydev - Run any extension and PyDev will start debugging.
PyCharm
You must use the PyCharm Professional Edition and not the Community Edition. Jetbrains has chosen to make remote debugging a Pro feature. To debug Inkscape python extensions, the extension code and Inkscape run independently of PyCharm, and only communicate with the debugger via a TCP socket. Thus, debugging is “remote,” even if it’s on the same machine, connected via the loopback interface.
-
pip install pydev_pycharmpydev_pycharm is versioned frequently. Jetbrains suggests installing a version at least compatible with the current build. For example, if your PyCharm build, as found in menu PyCharm -> About Pycharm is 223.8617.48, you could do:
pip install pydevd-pycharm~=223.8617.48 -
From the Pycharm “Run” menu, choose
Edit Configurations...and create a new configuration. SetIDE host name:tolocalhostandPort:to5678. You can leave the default settings for all other choices. -
Touch a file named
DEBUG.tomlat the top of your git repo, as above setdebug_type = pycharm -
Create a symbolic link in the Inkscape extensions directory to the top-level directory of your git repo. On a mac, for example:
cd ~/Library/Application\ Support/org.inkscape.Inkscape/config/inkscape/extensions/ ln -s <full path to the top level of your Ink/Stitch git repo>On other architectures it may be:
cd ~/.config/inkscape/extensions ln -s <full path to the top level of your Ink/Stitch git repo>Remove any other Ink/Stitch files or references to Ink/Stitch from the extensions directory, or you’ll see duplicate entries in the Ink/Stitch extensions menu in Inkscape. Or use the multiversion setup.
-
In Pycharm, either click on the green “bug” icon if visible in the upper right or press Ctrl-D to start debugging.The PyCharm debugger pane will display the message “Waiting for process connection…”
-
Do some action in Inkscape which invokes Ink/Stitch extension code, and the debugger will be triggered. If you’ve left “Suspend after connect” checked in the Run configuration, PyCharm will pause in the
self.log("Enabled PyDev debugger.)statement, below. Uncheck the box to have it continue automatically to your first set breakpoint.
VS Code
see:
- https://code.visualstudio.com/docs/python/debugging#_command-line-debugging
- https://code.visualstudio.com/docs/python/debugging#_debugging-by-attaching-over-a-network-connection
-
Install the Python extension for VS Code
pip install debugpy -
create .vscode/launch.json containing:
"configurations": [ ... { "name": "Python: Attach", "type": "python", "request": "attach", "connect": { "host": "localhost", "port": 5678 } } ] -
Touch a file named
DEBUG.tomlat the top of your git repo, as above setdebug_type = vscode -
Start the debug server in VS Code by clicking on the debug icon in the left pane select “Python: Attach” from the dropdown menu and click on the green arrow. The debug server will start and connect to already running python processes, but immediately exit if no python processes are running.
Profilers
Profile
Enable profiling as described above using profile. Ink/Stitch will then run under a profiler and dump the result to profile_stats. It will tell you what functions take how long to run.
Install snakeviz with pip install snakeviz.
Open the statistics with snakeviz profile_stats.prof.
This will display a really useful interactive graph in your browser.
Monkeytype
Much of our code, especially older code, lacks type annotations.
If you want to add type annotations to older code, or learn what types are used in a part of the codebase without type annotations, you my find MonkeyType useful.
- Set
profile_enable = True - Uncomment the
profiler_type = "monkeytype" - Install monkeytype with
pip install monkeytype.
After running Ink/Stitch command, a window will pop up telling you how to run Monkeytype and use your newly-collected type information. Multiple command runs will all add to the type information database.