We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fd12c23 commit 0976485Copy full SHA for 0976485
statsd/timer.py
@@ -88,6 +88,26 @@ def stop(self, subname='total'):
88
self._stop = time.time()
89
return self.send(subname, self._stop - self._start)
90
91
+ def __enter__(self):
92
+ '''
93
+ Make a context manager out of self to measure time execution in a block of code.
94
+
95
+ :return:
96
97
+ self.start()
98
+ return self
99
100
+ def __exit__(self, exc_type, exc_val, exc_tb):
101
102
+ Stop measuring time sending total metric, while exiting block of code.
103
104
+ :param exc_type:
105
+ :param exc_val:
106
+ :param exc_tb:
107
108
109
+ self.stop()
110
111
def _decorate(self, name, function, class_=None):
112
class_ = class_ or Timer
113
0 commit comments