gramex.debug
¶
Debugging and profiling tools for Gramex
Timer(msg='', level=logging.WARNING)
¶
Find how long a code blocks takes to execute. Wrap any code block like this:
Examples:
>>> from gramex.debug import Timer
>>> with Timer('optional message'):
>>> slow_running_code()
WARNING:gramex:1.000s optional message [<file>:<func>:line]
Source code in gramex\debug.py
34 35 36 |
|
print(args, kwargs)
¶
A replacement for the print
function that also logs the (file, function,
line, msg) from where it is called. For example:
Examples:
>>> from gramex.debug import print # import print function
>>> print('hello world') # It works like the print function
<file>(line).<function>: hello world
>>> print(x=1, y=2) # Use kwargs to print variable names
<file>(line).<function>:
.. x = 1
.. y = 2
It automatically pretty-prints complex variables.
Source code in gramex\debug.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
trace(trace=True, exclude=None, kwargs)
¶
Decorator to trace line execution. Usage:
@trace()
def method(...):
...
When method()
is called, every line of execution is traced.
Source code in gramex\debug.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
lineprofile(func)
¶
A decorator that prints the time taken for each line of a function every time it is called. This example prints each line’s performance:
Examples:
>>> from gramex.debug import lineprofile
>>> @lineprofile
>>> def calc():
>>> ...
Source code in gramex\debug.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|