Control Flow Visualization of Python


My advisor for this project is Dr. Clinton Jeffery. I thank him for his valuable suggestions and guidance through out the project.

Program visualization is a promising area of software engineering and is a branch of software visualization. Program visualization is a process of depicting the dynamic behavior of an executing program by continuously updating a graphic display or representing the program's control and/or data with the help of graphics at a particular moment. Several important applications of program visualization include debugging, performance tuning, and the study of algorithms.

Control flow visualization is a part of program visualization which deals with graphical representation of control in a program. This project is about control flow visualization of Python programs. Python is an interpreted, interactive, object oriented programming language. This project aims to visualize the control flow of Python programs. It has the potential to make debugging easier and to help in performance tuning. The visualizations also help in understanding the program behavior.

Description:

Visualize Python executions, especially control flow, at coarse fine granularities.

Procedure:
  • Study Python monitoring/debugging hooks API.
  • Extend instrumentation to atleast line-level granularity.
  • Write visualizations.
  • Run on a suite of Python programs.
Results obtained
  • Tool which visualizes function/method call in a Python program.
  • It shows both 3D and 2D visualization for a given program.
  • The visualizations plotted by this tool appear to be useful in helping programmers understand programs, which may aid them in debugging or performance tuning tasks.

The tool develped in this project shows the control flow in any Python program. The user has to run this tool with his program as input. The visualization produced by this tool shows all the function and method calls in the user program graphically.

Below is a list of videos captured by running my visualization tool on a set of python programs which were extracted from different Python software repositories. This tool produces both a 3D and a 2D visualization for each input program. All the videos are avi files.

  1. Polynomial.py
    • It is a simple Python program for calculating addition, multiplication, derivatives, and integrals of polynomials and also has simple functions that convert polynomials to a python list.
    • This was extracted from ASPN cookbook this program was written by Rick Muller.
    • 3D Visualization Video
    • 2D Visualization Video

  2. Dataenc.py
    • This module was extracted from Vaults of Paranassus : Python Resources and is written by Michael Foord.
    • This module can be used for combining data using a ‘binary interleave' where two pieces of data are woven together a bit at a time. The resulting binary string can be converted into an ASCII string using a table encoding. This module provides a simple mechanism for secure, time limited, logins when writing CGIs.
    • 3D Visualization Video
    • 2D Visualization Video

  3. Recursion.py
    • This program is a combination of recursion and mutual recursion.
    • The recursive part of the program is to calculate nth Fibonacci number. The mutual recursion part checks whether a given integer is odd or even.
    • 3D Visualization Video
    • 2D Visualization Video

  4. cccheck.py
    • This program is written by Sean Reifschneider. It was extracted from Vaults of Paranassus: Python Resources.
    • This module implements several methods for dealing with credit card numbers.
    • This module has methods for checking legal credit card numbers based on the check digit and generating the check digit. It can also determine the type of card based on card number.
    • 3D Visualization Video
    • 2D Visualization Video

Profiling and tracing facilities provided by the Python Interpreter are used in tracing the events of the user program. The traced events are written into a log file. Visualizations are drawn by reading the information form the log file. Python doesn't support graphics on its own. Hence VPython graphics package is used to draw the visualizations.

Weekly meetings during the Project.