Skip to main content

A debugging tool to take 'screenshot' of your program

Project description

progshot

build flake8 coverage pypi support-version license

progshot is a debugging tool that enables "offline-debugging" for your python program.

example_img

Install

pip install progshot

Usage

Trace

To capture a continuous run and be able to offline debug it like a real debugger, use @trace

from progshot import trace

def swap(arr, i, j):
    arr[i], arr[j] = arr[j], arr[i]

@trace
def bubble_sort(arr):
    n = len(arr)
    for i in range(n - 1):
        for j in range(n - i - 1):
            if arr[j] > arr[j + 1]:
                swap(arr, j, j + 1)

@trace will record every line executed in the decorated function and generated a out.pshot file when the program exits. With psviewer, you can enjoy a debugger-like environment offline, where you can not only go forward, but go backward as well.

Each capture is called a film, which contains all the frames the local variables in them.

By default, @trace is not recursive, but you can set the depth of @trace
from progshot import trace

def swap(arr, i, j):
    # Now this function will be recorded as well
    arr[i], arr[j] = arr[j], arr[i]

@trace(depth=2)
def bubble_sort(arr):
    n = len(arr)
    for i in range(n - 1):
        for j in range(n - i - 1):
            if arr[j] > arr[j + 1]:
                swap(arr, j, j + 1)
You can also manually dump to a file in your program
from progshot import dump

for i in range(3):
    arr = [random.randint(0, 100) for _ in range(10)]
    bubble_sort(arr)
    dump(filename=f"sort_{i}.pshot")

By default, dump will clear the current data after dumping, you can pass clear_data=False as an argument to prevent that.

View

To view the report, you can use Web interface or CLI.

Web

psview out.pshot

CLI

psview-cli out.pshot

Web interface also provides a terminal which behaves like the CLI.

The CLI interface is similar to pdb. You can use commands that have the similar meanings in pdb, except that you have a set of "backward debugging" commands.

psview commands
  • p expression - print eval of expression
  • pp expression - pretty print eval of expression with objprint
  • w(here) - show stack trace
  • u(p) [count] - move the current frame count levels up (to older frame)
  • d(own) [count] - move the current frame count levels down (to later frame)
  • n(ext) - go to next line in current function if possible, otherwise next film
  • b(ack) - go to previous line in current function if possible, otherwise previous film
  • s(tep) - go to next film
  • s(tep)b(ack) - go to previous film
  • r(eturn) - go to the next film when the current function returns
  • r(eturn)b(ack) - go to the previous film before the current function enters
  • unt(il) [lineno] - go forward until the line with a number that's >= lineno is reached
  • unt(il)b(ack) [lineno] - go backward until the line with a number that's <= lineno is reached
  • g(oto) [bookmark] - goto bookmark film. bookmark can be film index or film name
  • l(ist) [lineno] - show source code around lineno
  • ll - show full source code of existing frame

Single Capture

You can also use capture function to do a single capture.

from progshot import capture

def add(a, b):
    capture()
    return a + b
You can give a name(bookmark) for the capture to switch to the film quickly

Do not use space in name

from progshot import capture

def add(a, b):
    capture(name="cap_in_add")
    return a + b

Config

There are some global configs that you can change through config.

from progshot import config

# Change the default dump file name
config(filename="other.pshot")

# Do not auto-save when the program exits
config(save_at_exit=False)

# Change default trace depth to 10
config(depth=10)

Bugs/Requests

Please send bug reports and feature requests through github issue tracker.

License

Copyright Tian Gao, Mengjia Zhao, 2021.

Distributed under the terms of the Apache 2.0 license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

progshot-0.0.1.tar.gz (399.1 kB view details)

Uploaded Source

Built Distribution

progshot-0.0.1-py3-none-any.whl (408.1 kB view details)

Uploaded Python 3

File details

Details for the file progshot-0.0.1.tar.gz.

File metadata

  • Download URL: progshot-0.0.1.tar.gz
  • Upload date:
  • Size: 399.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.10

File hashes

Hashes for progshot-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a9e5496d38dcae61718143ad3bdfc3ae8f634acde00b6bff80676c06a9d09edf
MD5 cee16fa3b808eb4c6f5c6e05a8b11b75
BLAKE2b-256 ad85687820cf8738aa6ca252a47aad4a43cabea5b0525bdc85731167d21228e8

See more details on using hashes here.

File details

Details for the file progshot-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: progshot-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 408.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.10

File hashes

Hashes for progshot-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9dbc652f530233c4b2a1783a73a7132ebf078857c3ef8fb892fd7ccbb09381ef
MD5 7c23d0052bf924cfe5ec360c55978c22
BLAKE2b-256 66134e1033c9a7ebf26f5978008d0ffa6fab7305ff81409c30d702b207c44ae0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page