Package: progshot
progshotprogshot is a debugging tool that enables "offline-debugging" for your python program.Installpip install progshotUsageTraceTo capture a continuous run and be able to offline debug it like a real debugger, use@tracefromprogshotimporttracedefswap(arr,i,j):arr[i],arr[j]=arr[j],arr[i]@tracedefbubble_sort(arr):n=len(arr)foriinrange(n-1):forjinrange(n-i-1):ifarr[j]>arr[j+1]:swap(arr,j,j+1)@tracewill record every line executed in the decorated function and generated aout.pshotfile when the program exits. Withpsviewer, you can enjoy a debugger-like environment offline, where you can not only go forward, but go backward as well.Each capture is called afilm, which contains all the frames the local variables in them.By default,@traceis not recursive, but you can set thedepthof@tracefromprogshotimporttracedefswap(arr,i,j):# Now this function will be recorded as wellarr[i],arr[j]=arr[j],arr[i]@trace(depth=2)defbubble_sort(arr):n=len(arr)foriinrange(n-1):forjinrange(n-i-1):ifarr[j]>arr[j+1]:swap(arr,j,j+1)You can also manually dump to a file in your programfromprogshotimportdumpforiinrange(3):arr=[random.randint(0,100)for_inrange(10)]bubble_sort(arr)dump(filename=f"sort_{i}.pshot")By default,dumpwill clear the current data after dumping, you can passclear_data=Falseas an argument to prevent that.ViewTo view the report, you can use Web interface or CLI.Webpsview out.pshotCLIpsview-cli out.pshotWeb 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 commandspexpression- print eval of expressionppexpression- pretty print eval of expression withobjprintw(here) - show stack traceu(p) [count] - move the current framecountlevels up (to older frame)d(own) [count] - move the current framecountlevels down (to later frame)n(ext) - go to next line in current function if possible, otherwise next filmb(ack) - go to previous line in current function if possible, otherwise previous films(tep) - go to next films(tep)b(ack) - go to previous filmr(eturn) - go to the next film when the current function returnsr(eturn)b(ack) - go to the previous film before the current function entersunt(il) [lineno] - go forward until the line with a number that's >=linenois reachedunt(il)b(ack) [lineno] - go backward until the line with a number that's <=linenois reachedg(oto) [bookmark] - gotobookmarkfilm.bookmarkcan be film index or film namel(ist) [lineno] - show source code aroundlinenoll - show full source code of existing frameSingle CaptureYou can also usecapturefunction to do a single capture.fromprogshotimportcapturedefadd(a,b):capture()returna+bYou can give a name(bookmark) for the capture to switch to the film quicklyDo not use space innamefromprogshotimportcapturedefadd(a,b):capture(name="cap_in_add")returna+bConfigThere are some global configs that you can change throughconfig.fromprogshotimportconfig# Change the default dump file nameconfig(filename="other.pshot")# Do not auto-save when the program exitsconfig(save_at_exit=False)# Change default trace depth to 10config(depth=10)Bugs/RequestsPlease send bug reports and feature requests throughgithub issue tracker.LicenseCopyright Tian Gao, Mengjia Zhao, 2021.Distributed under the terms of theApache 2.0 license.