mirror of https://github.com/cool-RR/PySnooper.git
Rename relative_time to elapsed_time
This commit is contained in:
parent
73c2816121
commit
d94b0214f9
10
README.md
10
README.md
|
@ -72,12 +72,12 @@ Or if you don't want to trace an entire function, you can wrap the relevant part
|
||||||
import pysnooper
|
import pysnooper
|
||||||
import random
|
import random
|
||||||
|
|
||||||
def foo(relative_time=False):
|
def foo(elapsed_time=False):
|
||||||
lst = []
|
lst = []
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
lst.append(random.randrange(1, 1000))
|
lst.append(random.randrange(1, 1000))
|
||||||
|
|
||||||
with pysnooper.snoop(relative_time=relative_time):
|
with pysnooper.snoop(elapsed_time=elapsed_time):
|
||||||
lower = min(lst)
|
lower = min(lst)
|
||||||
upper = max(lst)
|
upper = max(lst)
|
||||||
mid = (lower + upper) / 2
|
mid = (lower + upper) / 2
|
||||||
|
@ -102,18 +102,18 @@ New var:....... mid = 453.0
|
||||||
Total elapsed time: 00:00:00.000344
|
Total elapsed time: 00:00:00.000344
|
||||||
```
|
```
|
||||||
|
|
||||||
If `relative_time` is `True`, print time format will be relative.
|
If `elapsed_time` is `True`, print elapsed time format.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import pysnooper
|
import pysnooper
|
||||||
import random
|
import random
|
||||||
|
|
||||||
def foo(relative_time=False):
|
def foo(elapsed_time=False):
|
||||||
lst = []
|
lst = []
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
lst.append(random.randrange(1, 1000))
|
lst.append(random.randrange(1, 1000))
|
||||||
|
|
||||||
with pysnooper.snoop(relative_time=relative_time):
|
with pysnooper.snoop(elapsed_time=elapsed_time):
|
||||||
lower = min(lst)
|
lower = min(lst)
|
||||||
upper = max(lst)
|
upper = max(lst)
|
||||||
mid = (lower + upper) / 2
|
mid = (lower + upper) / 2
|
||||||
|
|
|
@ -198,11 +198,15 @@ class Tracer:
|
||||||
|
|
||||||
You can also use `max_variable_length=None` to never truncate them.
|
You can also use `max_variable_length=None` to never truncate them.
|
||||||
|
|
||||||
|
Print time in elapsed time format::
|
||||||
|
|
||||||
|
@pysnooper.snoop(elapsed_time=True)
|
||||||
|
|
||||||
'''
|
'''
|
||||||
def __init__(self, output=None, watch=(), watch_explode=(), depth=1,
|
def __init__(self, output=None, watch=(), watch_explode=(), depth=1,
|
||||||
prefix='', overwrite=False, thread_info=False, custom_repr=(),
|
prefix='', overwrite=False, thread_info=False, custom_repr=(),
|
||||||
max_variable_length=100, normalize=False,
|
max_variable_length=100, normalize=False,
|
||||||
relative_time=False):
|
elapsed_time=False):
|
||||||
self._write = get_write_function(output, overwrite)
|
self._write = get_write_function(output, overwrite)
|
||||||
|
|
||||||
self.watch = [
|
self.watch = [
|
||||||
|
@ -228,7 +232,7 @@ class Tracer:
|
||||||
self.last_source_path = None
|
self.last_source_path = None
|
||||||
self.max_variable_length = max_variable_length
|
self.max_variable_length = max_variable_length
|
||||||
self.normalize = normalize
|
self.normalize = normalize
|
||||||
self.relative_time = relative_time
|
self.elapsed_time = elapsed_time
|
||||||
|
|
||||||
def __call__(self, function_or_class):
|
def __call__(self, function_or_class):
|
||||||
if DISABLED:
|
if DISABLED:
|
||||||
|
@ -359,7 +363,7 @@ class Tracer:
|
||||||
# #
|
# #
|
||||||
### Finished checking whether we should trace this line. ##############
|
### Finished checking whether we should trace this line. ##############
|
||||||
|
|
||||||
if self.relative_time:
|
if self.elapsed_time:
|
||||||
duration = datetime_module.datetime.now() - self.start_time
|
duration = datetime_module.datetime.now() - self.start_time
|
||||||
now_string = pycompat.timedelta_isoformat(
|
now_string = pycompat.timedelta_isoformat(
|
||||||
duration, timespec='microseconds') if not self.normalize else ' ' * 15
|
duration, timespec='microseconds') if not self.normalize else ' ' * 15
|
||||||
|
|
|
@ -50,10 +50,10 @@ def test_string_io():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_relative_time():
|
def test_elapsed_time():
|
||||||
string_io = io.StringIO()
|
string_io = io.StringIO()
|
||||||
|
|
||||||
@pysnooper.snoop(string_io, relative_time=True)
|
@pysnooper.snoop(string_io, elapsed_time=True)
|
||||||
def my_function(foo):
|
def my_function(foo):
|
||||||
x = 7
|
x = 7
|
||||||
y = 8
|
y = 8
|
||||||
|
|
Loading…
Reference in New Issue