Debug

Env Variables

There are few ENV Variables that can be used to force some debugging features;

TERMTK_FILE_LOG - Log to a file

To force logging to a file (i.e. “session.log”)

TERMTK_FILE_LOG=session.log   python3   demo/demo.py

TERMTK_STACKTRACE - Force stacktrace generation with CTRL+C

Use this env variable to force a stacktrace generation to the file defined (i.e. “stacktrace.txt”)

TERMTK_STACKTRACE=stacktrace.txt   python3   demo/demo.py

TERMTK_FORCESERIAL - Force some workaround to pickup the terminal size from the serial console

Use this env variable if pyTermTk is running on a serial console

TERMTK_FORCESERIAL=1   python3   demo/demo.py

Gui

Visual Studio Code

vsCode debug feature comes out of the box, it only require the default **Python** extension installed

vsCode debug

intellij IDEA

I haven’t tried it recently since my vsCode experience is silk smooth but based on the results of the issue 102 I am pretty confident that intellij debug feature should work as well

PyCharm

Same for PyCharm, I mean, I tried both those IDEs at least once.

Profiling

VizTracer

https://github.com/ceccopierangiolieugenio/pyTermTk/assets/8876552/34ff9b77-f01b-45bd-a57e-971c7b68c4a2

this tool is able to generate a tracker file that can be viewed using Perfetto (UI)

# install cprofilev:
#     pip3 install viztracer
viztracer --tracer_entries 10000010 tests/paint.py

# View the results
# loading the "result.json" in https://ui.perfetto.dev
# or running
vizviewer result.json

cProfile, cProfilev

python3 -m cProfile -o profiler.bin tests/test.ui.004.py

# install cprofilev:
#     pip3 install cprofilev
cprofilev -f profiler.bin
# open http://127.0.0.1:4000

py-spy

# install
pip install py-spy

# run the application
python3 demo/demo.py

# on another terminal run the py-spy
sudo env "PATH=$PATH" \
    py-spy top \
    --pid  $(ps -A -o pid,cmd | grep demo.py | grep -v grep | sed 's,python.*,,')

pyroscope

pyroscope can be used as well (I guess) for profiling