This commit is contained in:
AF 2022-11-04 09:01:04 +00:00
parent bb8da9d2b6
commit 7d99e7a94f

50
v6d2ctx/pain.py Normal file
View File

@ -0,0 +1,50 @@
import os
import time
from rainbowadn.instrument import Instrumentation
class ALog(Instrumentation):
start = time.time()
def time(self):
return time.time() - self.start
async def instrument(self, method, *args, **kwargs):
key = os.urandom(4).hex()
print(f'[{self.time(): 11.3f}] +{key} +A"{self.methodname}"')
try:
result = await method(*args, **kwargs)
except BaseException:
print(f'[{self.time(): 11.3f}] !{key} !A"{self.methodname}"')
raise
else:
print(f'[{self.time(): 11.3f}] -{key} -A"{self.methodname}"')
return result
class SLog(Instrumentation):
def time(self):
return time.time() - ALog.start
def instrument(self, method, *args, **kwargs):
key = os.urandom(4).hex()
print(f'[{self.time(): 11.3f}] +{key} +S"{self.methodname}"')
try:
result = method(*args, **kwargs)
except BaseException:
print(f'[{self.time(): 11.3f}] !{key} !S"{self.methodname}"')
raise
else:
print(f'[{self.time(): 11.3f}] -{key} -S"{self.methodname}"')
return result
class FrameTrace(Instrumentation):
async def instrument(self, method, *args, **kwargs):
import inspect
frame = inspect.currentframe()
while frame is not None:
print(frame.f_code.co_filename, frame.f_lineno)
frame = frame.f_back
return await method(*args, **kwargs)