Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
63 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import time | ||
from functools import wraps | ||
|
||
|
||
class UtilizationCollector(object): | ||
"""Collects stats for overall callback durations""" | ||
|
||
def __init__(self, monitor, flush_interval): | ||
self.monitor = monitor | ||
self.flush_interval = flush_interval or 10000 | ||
|
||
def start(self): | ||
self.original_add_callback = self.monitor.io_loop.add_callback | ||
|
||
def measure_callback(callback): | ||
@wraps(callback) | ||
def timed_callback(*args, **kwargs): | ||
last_start_time = time.time() | ||
result = callback(*args, **kwargs) | ||
duration = (time.time() - last_start_time) | ||
self.monitor.accumulated_kv('callback_duration', duration) | ||
|
||
return result | ||
|
||
return timed_callback | ||
|
||
@wraps(self.original_add_callback) | ||
def add_timed_callback(callback, *args, **kwargs): | ||
return self.original_add_callback(measure_callback(callback), *args, **kwargs) | ||
|
||
self.monitor.io_loop.add_callback = add_timed_callback | ||
|
||
def stop(self): | ||
self.monitor.add_callback = self.original_add_callback | ||
self.flush_callback.stop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters