From 433cab250f45711f126f4a5b6bafc70b2de4d708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Kuzn=C3=ADk?= Date: Wed, 14 Oct 2015 11:37:26 +0100 Subject: [PATCH] Add timing information on traced function --- q.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/q.py b/q.py index ceacd74..dd89bec 100644 --- a/q.py +++ b/q.py @@ -275,6 +275,7 @@ def wrapper(*args, **kwargs): # Call the function. self.indent += 2 + start_time = self.time.time() try: result = func(*args, **kwargs) except: @@ -283,6 +284,9 @@ def wrapper(*args, **kwargs): etype, evalue, etb = self.sys.exc_info() info = self.inspect.getframeinfo(etb.tb_next, context=3) s = self.Stanza(self.indent) + s.add([self.YELLOW, + '(+%.1fs) ' % (self.time.time() - start_time), + self.NORMAL]) s.add([self.RED, '!> ', self.safe_repr(evalue), self.NORMAL]) s.add(['at ', info.filename, ':', info.lineno], ' ') lines = self.unindent(info.code_context) @@ -297,9 +301,11 @@ def wrapper(*args, **kwargs): self.writer.write(s.chunks) raise - # Display the return value. + # Display the time taken and return value. self.indent -= 2 s = self.Stanza(self.indent) + s.add([self.YELLOW, '(+%.1fs) ' % (self.time.time() - start_time), + self.NORMAL]) s.add([self.GREEN, '-> ', self.CYAN, self.safe_repr(result), self.NORMAL]) self.writer.write(s.chunks)