block monitor
This commit is contained in:
parent
2f0ac33c02
commit
782a934af9
@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -48,3 +49,28 @@ class FrameTrace(Instrumentation):
|
|||||||
print(frame.f_code.co_filename, frame.f_lineno)
|
print(frame.f_code.co_filename, frame.f_lineno)
|
||||||
frame = frame.f_back
|
frame = frame.f_back
|
||||||
return await method(*args, **kwargs)
|
return await method(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class ABlockMonitor:
|
||||||
|
__task: asyncio.Future
|
||||||
|
__max: float
|
||||||
|
|
||||||
|
def __init__(self, threshold=0.0) -> None:
|
||||||
|
self.__max = threshold
|
||||||
|
|
||||||
|
async def _monitor(self):
|
||||||
|
while True:
|
||||||
|
delta = 10
|
||||||
|
t = time.time()
|
||||||
|
await asyncio.sleep(delta)
|
||||||
|
spent = time.time() - t
|
||||||
|
delay = spent - delta
|
||||||
|
if delay > self.__max:
|
||||||
|
self.__max = delay
|
||||||
|
print(f'block monitor reached new peak delay {delay:.3f}')
|
||||||
|
|
||||||
|
async def __aenter__(self):
|
||||||
|
self.__task = asyncio.get_running_loop().create_task(self._monitor())
|
||||||
|
|
||||||
|
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
self.__task.cancel()
|
||||||
|
Loading…
Reference in New Issue
Block a user