From 9e1d4aedd04b4ed8b465439899a18abc0b81b579 Mon Sep 17 00:00:00 2001 From: timotheyca Date: Fri, 15 Jul 2022 21:36:54 +0300 Subject: [PATCH] measure instrumentation --- rainbowadn/instrument/_measure.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 rainbowadn/instrument/_measure.py diff --git a/rainbowadn/instrument/_measure.py b/rainbowadn/instrument/_measure.py new file mode 100644 index 0000000..a7b6901 --- /dev/null +++ b/rainbowadn/instrument/_measure.py @@ -0,0 +1,17 @@ +import time + +from .instrumentation import Instrumentation + +__all__ = ('Measure',) + + +class Measure(Instrumentation): + def __init__(self, target, methodname: str): + super().__init__(target, methodname) + self.log: list[float] = [] + + async def instrument(self, method, *args, **kwargs): + start = time.time() + result = await method(*args, **kwargs) + self.log.append(time.time() - start) + return result