32 lines
845 B
Python
32 lines
845 B
Python
import time
|
|
|
|
from .instrumentation import *
|
|
|
|
__all__ = ('Concurrency',)
|
|
|
|
|
|
class Concurrency(Instrumentation):
|
|
start = time.time()
|
|
|
|
def __init__(self, target, methodname: str):
|
|
assert isinstance(methodname, str)
|
|
super().__init__(target, methodname)
|
|
self.concurrency = 0
|
|
self.log: list[tuple[float, int]] = []
|
|
|
|
def time(self) -> float:
|
|
return time.time() - self.start
|
|
|
|
def point(self) -> tuple[float, int]:
|
|
return self.time(), self.concurrency
|
|
|
|
async def instrument(self, method, *args, **kwargs):
|
|
self.log.append(self.point())
|
|
self.concurrency += 1
|
|
self.log.append(self.point())
|
|
result = await method(*args, **kwargs)
|
|
self.log.append(self.point())
|
|
self.concurrency -= 1
|
|
self.log.append(self.point())
|
|
return result
|