Package: vardbg
vardbgA simple Python debugger and profiler that generates animated visualizations of program flow. It is meant to help with learning algorithms by allowing you to visualize what the algorithms are doing.Python 3.6or newer is required due to the use of f-strings.This project was created duringGoogle Code-in2019 forCCExtractor Development.DemoFeaturesTracking the history of each variable and its contentsTracking elements within containers (lists, sets, dicts, etc.)Ignoring specific variablesProfiling the execution of each lineSummarizing all variables and execution times after executionPassing arguments to debugged programsExporting execution history in JSON format and replaying (including program output)Creating videos that show program flow, execution times, variables (with relationships), and outputWriting videos in MP4, GIF, and WebP formatsInstallationThe latest tagged version can be obtained from PyPI:pipinstallvardbgAlternatively, one can clone this repository and run it directly after installing dependencies:gitclonehttps://github.com/CCExtractor/vardbgcdvardbg
python3-mvenvvenvsourcevenv/bin/activate
pipinstallpoetry
poetryinstall.
./debug.pyIt can also be installed from the repository:pipinstall.The above instructions assume the use of a virtual environment to avoid interfering with the system install of Python.UsageAll of the debugger's subcommands and options are documented in the usage help, which is readily available on the command line.For example, this command will debug the functionquick_sortfrom the filesort.pywith the arguments9 3 5 1and record the session to a JSON file namedsort1.json:vardbgrunsort.pyquick_sort-oqsort.json-a9-a3-a5-a1A video can then be generated from the above recording:vardbgreplayqsort.json-vsort_vis.mp4It is possible to generate videos live while running the debugged program, but this is discouraged because the overhead of video creation inflates execution times greatly and thus ruins profiler results. However, if profiling is not important to you, it is a valid use case.ConfigurationThe video generator has many options: resolution, speed, fonts, and sizes. These options can be modified using aTOMLconfig file. Thedefault configdocuments the available options, which can be customized in an minimal overlay config without having to duplicate the entire config. The config can then be used by passing the-cargument on the command line.An example of a simple overlay is theconfigused to generate official demo videos for embedding in READMEs. This simple config increases the speed (FPS) slightly and adds an intro screen at the beginning of the video.Behavior ControlSpecial comments can be added to lines of code that define variables to control how vardbg handles said variable:# vardbg: ignore— do not display this variable or track its values# vardbg: ref lst[i]— treat variableias the index/key of an element in containerlst(only shown in videos)Specifying the name of the variable may appear to be redundant, but there are two reasons behind this: reliably parsing all code that defines variables is very hard (there are more possible methods than one might think — loops, unpacking, direct assignments,execcalls, etc.), and more than one variable can be declared on a line. For example, tuple unpacking and function arguments are common occurrences of multiple variables being added on a single line. Thus, specifying the variable name in references is mandatory to prevent ambiguity.ContributingFeel free to contribute to this project! You can add features, fix bugs, or make any other improvements you see fit. We just ask that you follow thecode style guidelinesto keep the code consistent and coherent. These guidelines can easily be enforced before pushing with thepre-commitframework, which can install Git pre-commit hooks with thepre-commit installcommand.Once your contribution meets the guidelines,open a pull requestto make things official.