stats.Timer: don't send intermediates immediately.

This allows us to change the base name of the timer before stop/flush is
called and have the intermediates update as well.
This commit is contained in:
Neil Williams
2012-11-08 16:42:38 -08:00
parent d476208e38
commit 4ce98dcbb5
2 changed files with 10 additions and 1 deletions

View File

@@ -1505,4 +1505,6 @@ def process_votes(qname, limit=0):
handle_vote(voter, votee, dir, ip, organic,
cheater = cheater, foreground=True, timer=timer)
timer.flush()
amqp.consume_items(qname, _handle_vote, verbose = False)

View File

@@ -163,6 +163,12 @@ class Timer:
self._start = None
self._last = None
self._stop = None
self._timings = []
def flush(self):
for timing in self._timings:
self.send(*timing)
self._timings = []
def elapsed_seconds(self):
if self._start is None:
@@ -184,7 +190,7 @@ class Timer:
if self._stop is not None:
raise AssertionError("timer is stopped")
last, self._last = self._last, self._time()
self.send(subname, self._last - last)
self._timings.append((subname, self._last - last))
def stop(self, subname='total'):
if self._start is None:
@@ -192,6 +198,7 @@ class Timer:
if self._stop is not None:
raise AssertionError('timer is already stopped')
self._stop = self._time()
self.flush()
self.send(subname, self._stop - self._start)