wrap.__non_nightly__ + instrumentation
This commit is contained in:
parent
c3d1876a7e
commit
d54a1e5744
@ -195,23 +195,25 @@ def nightly(decorated: TDecoratedNightly = None, prefix: str = '', stacklevel=2)
|
|||||||
if decorated is None:
|
if decorated is None:
|
||||||
NightlyWarning.enabled = False
|
NightlyWarning.enabled = False
|
||||||
return None # type: ignore
|
return None # type: ignore
|
||||||
|
|
||||||
if isinstance(decorated, type):
|
if isinstance(decorated, type):
|
||||||
|
prefix = f'{prefix}{decorated.__name__}.'
|
||||||
decorated.__init__ = nightly(
|
decorated.__init__ = nightly(
|
||||||
decorated.__init__, f'{decorated.__name__}.'
|
decorated.__init__, prefix
|
||||||
)
|
)
|
||||||
decorated.__init_subclass__ = nightly(
|
decorated.__init_subclass__ = nightly(
|
||||||
decorated.__init_subclass__, f'{decorated.__name__}.', stacklevel=3
|
decorated.__init_subclass__, prefix, stacklevel=3
|
||||||
)
|
)
|
||||||
return decorated # type: ignore
|
return decorated # type: ignore
|
||||||
|
|
||||||
assert callable(decorated)
|
assert callable(decorated)
|
||||||
|
|
||||||
message = f"{prefix}{decorated.__name__}"
|
message = f"{prefix}{decorated.__name__}"
|
||||||
|
|
||||||
@wraps(decorated)
|
@wraps(decorated)
|
||||||
def wrap(*args, **kwargs):
|
def wrap(*args, **kwargs):
|
||||||
if NightlyWarning.enabled:
|
if NightlyWarning.enabled:
|
||||||
warnings.warn(message, NightlyWarning, stacklevel=stacklevel)
|
warnings.warn(message, NightlyWarning, stacklevel=stacklevel)
|
||||||
return decorated(*args, **kwargs)
|
return wrap.__non_nightly__(*args, **kwargs)
|
||||||
|
|
||||||
if wrap.__doc__ is None or not wrap.__doc__:
|
if wrap.__doc__ is None or not wrap.__doc__:
|
||||||
wrap.__doc__ = '@nightly'
|
wrap.__doc__ = '@nightly'
|
||||||
@ -220,6 +222,8 @@ def nightly(decorated: TDecoratedNightly = None, prefix: str = '', stacklevel=2)
|
|||||||
else:
|
else:
|
||||||
wrap.__doc__ = '@nightly\n\n' + wrap.__doc__
|
wrap.__doc__ = '@nightly\n\n' + wrap.__doc__
|
||||||
|
|
||||||
|
wrap.__non_nightly__ = decorated
|
||||||
|
|
||||||
return wrap # type: ignore
|
return wrap # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
23
ptvp35/instrumentation.py
Normal file
23
ptvp35/instrumentation.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from rainbowadn.instrument import Instrumentation
|
||||||
|
from . import DbConnection
|
||||||
|
|
||||||
|
|
||||||
|
class InstrumentDiskWrites(Instrumentation):
|
||||||
|
def __init__(self, /):
|
||||||
|
super().__init__(DbConnection, '_write_to_disk_sync')
|
||||||
|
|
||||||
|
def on_write(self, line: str, /) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def instrument(self, method, db, line, /):
|
||||||
|
self.on_write(line)
|
||||||
|
return method(db, line)
|
||||||
|
|
||||||
|
|
||||||
|
class NightlyInstrumentation(Instrumentation):
|
||||||
|
def __init__(self, target, methodname: str):
|
||||||
|
method = getattr(target, methodname)
|
||||||
|
if hasattr(method, '__non_nightly__'):
|
||||||
|
target = method
|
||||||
|
methodname = '__non_nightly__'
|
||||||
|
super().__init__(target, methodname)
|
@ -5,26 +5,25 @@ import threading
|
|||||||
from contextlib import ExitStack
|
from contextlib import ExitStack
|
||||||
|
|
||||||
from ptvp35 import DbConnection, DbFactory, KVJson
|
from ptvp35 import DbConnection, DbFactory, KVJson
|
||||||
from rainbowadn.instrument import Instrumentation
|
from ptvp35.instrumentation import InstrumentDiskWrites, NightlyInstrumentation
|
||||||
|
|
||||||
|
|
||||||
async def aprint(*args, **kwargs):
|
async def aprint(*args, **kwargs):
|
||||||
print(*args, **kwargs)
|
print(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class LogWrites(Instrumentation):
|
class LogWrites(InstrumentDiskWrites):
|
||||||
def __init__(self):
|
def __init__(self, /):
|
||||||
super().__init__(DbConnection, '_write_to_disk_sync')
|
super().__init__()
|
||||||
self.loop = asyncio.get_running_loop()
|
self.loop = asyncio.get_running_loop()
|
||||||
|
|
||||||
def instrument(self, method, db, line, /):
|
def on_write(self, line: str, /) -> None:
|
||||||
asyncio.run_coroutine_threadsafe(
|
asyncio.run_coroutine_threadsafe(
|
||||||
aprint(f'{self.methodname}[{line}]'), self.loop
|
aprint(f'{self.methodname}[{line}]'), self.loop
|
||||||
).result()
|
).result()
|
||||||
return method(db, line)
|
|
||||||
|
|
||||||
|
|
||||||
class LogEE(Instrumentation):
|
class LogEE(NightlyInstrumentation):
|
||||||
def __init__(self, target, methodname: str):
|
def __init__(self, target, methodname: str):
|
||||||
super().__init__(target, methodname)
|
super().__init__(target, methodname)
|
||||||
self.loop = asyncio.get_running_loop()
|
self.loop = asyncio.get_running_loop()
|
||||||
@ -146,18 +145,27 @@ async def main():
|
|||||||
LogEE(__import__('ptvp35').Request, 'set_result').enter(es)
|
LogEE(__import__('ptvp35').Request, 'set_result').enter(es)
|
||||||
LogEE(__import__('ptvp35').Request, 'set_exception').enter(es)
|
LogEE(__import__('ptvp35').Request, 'set_exception').enter(es)
|
||||||
ALogEE(__import__('ptvp35').Request, 'wait').enter(es)
|
ALogEE(__import__('ptvp35').Request, 'wait').enter(es)
|
||||||
|
|
||||||
LogEE(__import__('ptvp35').LineRequest, '__init__').enter(es)
|
LogEE(__import__('ptvp35').LineRequest, '__init__').enter(es)
|
||||||
|
|
||||||
LogEE(__import__('ptvp35').KVFactory, 'run').enter(es)
|
LogEE(__import__('ptvp35').KVFactory, 'run').enter(es)
|
||||||
LogEE(__import__('ptvp35').KVFactory, 'request').enter(es)
|
LogEE(__import__('ptvp35').KVFactory, 'request').enter(es)
|
||||||
LogEE(__import__('ptvp35').KVFactory, 'free').enter(es)
|
LogEE(__import__('ptvp35').KVFactory, 'free').enter(es)
|
||||||
LogEE(__import__('ptvp35').KVFactory, 'io2db').enter(es)
|
LogEE(__import__('ptvp35').KVFactory, 'io2db').enter(es)
|
||||||
LogEE(__import__('ptvp35').KVFactory, 'db2io').enter(es)
|
LogEE(__import__('ptvp35').KVFactory, 'db2io').enter(es)
|
||||||
|
|
||||||
LogEE(__import__('ptvp35').KVRequest, '__init__').enter(es)
|
LogEE(__import__('ptvp35').KVRequest, '__init__').enter(es)
|
||||||
|
|
||||||
LogEE(__import__('ptvp35').KVJson, 'line').enter(es)
|
LogEE(__import__('ptvp35').KVJson, 'line').enter(es)
|
||||||
LogEE(__import__('ptvp35').KVJson, '_load_key').enter(es)
|
LogEE(__import__('ptvp35').KVJson, '_load_key').enter(es)
|
||||||
LogEE(__import__('ptvp35').KVJson, 'fromline').enter(es)
|
LogEE(__import__('ptvp35').KVJson, 'fromline').enter(es)
|
||||||
|
|
||||||
LogEE(__import__('ptvp35').TransactionRequest, '__init__').enter(es)
|
LogEE(__import__('ptvp35').TransactionRequest, '__init__').enter(es)
|
||||||
|
|
||||||
LogEE(__import__('ptvp35').DbParametres, '__init__').enter(es)
|
LogEE(__import__('ptvp35').DbParametres, '__init__').enter(es)
|
||||||
|
|
||||||
|
LogEE(__import__('ptvp35').VirtualConnection, 'transaction').enter(es)
|
||||||
|
|
||||||
LogEE(__import__('ptvp35').DbConnection, '__init__').enter(es)
|
LogEE(__import__('ptvp35').DbConnection, '__init__').enter(es)
|
||||||
LogEE(__import__('ptvp35').DbConnection, '_create_future').enter(es)
|
LogEE(__import__('ptvp35').DbConnection, '_create_future').enter(es)
|
||||||
LogEE(__import__('ptvp35').DbConnection, '_save_error_sync').enter(es)
|
LogEE(__import__('ptvp35').DbConnection, '_save_error_sync').enter(es)
|
||||||
@ -222,14 +230,32 @@ async def main():
|
|||||||
LogEE(__import__('ptvp35').DbConnection, 'submit_transaction').enter(es)
|
LogEE(__import__('ptvp35').DbConnection, 'submit_transaction').enter(es)
|
||||||
LogEE(__import__('ptvp35').DbConnection, 'submit_transaction_request').enter(es)
|
LogEE(__import__('ptvp35').DbConnection, 'submit_transaction_request').enter(es)
|
||||||
ALogEE(__import__('ptvp35').DbConnection, 'commit').enter(es)
|
ALogEE(__import__('ptvp35').DbConnection, 'commit').enter(es)
|
||||||
|
LogEE(__import__('ptvp35').DbConnection, 'loop').enter(es)
|
||||||
LogEE(__import__('ptvp35').DbConnection, 'transaction').enter(es)
|
LogEE(__import__('ptvp35').DbConnection, 'transaction').enter(es)
|
||||||
|
|
||||||
LogEE(__import__('ptvp35').DbFactory, '__init__').enter(es)
|
LogEE(__import__('ptvp35').DbFactory, '__init__').enter(es)
|
||||||
ALogEE(__import__('ptvp35').DbFactory, '__aenter__').enter(es)
|
ALogEE(__import__('ptvp35').DbFactory, '__aenter__').enter(es)
|
||||||
ALogEE(__import__('ptvp35').DbFactory, '__aexit__').enter(es)
|
ALogEE(__import__('ptvp35').DbFactory, '__aexit__').enter(es)
|
||||||
|
|
||||||
LogEE(__import__('ptvp35').Db, '__init__').enter(es)
|
LogEE(__import__('ptvp35').Db, '__init__').enter(es)
|
||||||
ALogEE(__import__('ptvp35').Db, '__aenter__').enter(es)
|
ALogEE(__import__('ptvp35').Db, '__aenter__').enter(es)
|
||||||
ALogEE(__import__('ptvp35').Db, '__aexit__').enter(es)
|
ALogEE(__import__('ptvp35').Db, '__aexit__').enter(es)
|
||||||
|
|
||||||
|
LogEE(__import__('ptvp35').FutureContext, '__init__').enter(es)
|
||||||
|
ALogEE(__import__('ptvp35').FutureContext, '__aenter__').enter(es)
|
||||||
|
ALogEE(__import__('ptvp35').FutureContext, '__aexit__').enter(es)
|
||||||
|
|
||||||
LogEE(__import__('ptvp35').TransactionView, '__init__').enter(es)
|
LogEE(__import__('ptvp35').TransactionView, '__init__').enter(es)
|
||||||
|
LogEE(__import__('ptvp35').TransactionView, 'future_context').enter(es)
|
||||||
|
LogEE(__import__('ptvp35').TransactionView, 'rollback').enter(es)
|
||||||
|
LogEE(__import__('ptvp35').TransactionView, 'illuminate').enter(es)
|
||||||
|
ALogEE(__import__('ptvp35').TransactionView, 'ailluminate').enter(es)
|
||||||
|
LogEE(__import__('ptvp35').TransactionView, 'fork').enter(es)
|
||||||
|
ALogEE(__import__('ptvp35').TransactionView, 'afork').enter(es)
|
||||||
|
LogEE(__import__('ptvp35').TransactionView, 'clear').enter(es)
|
||||||
|
ALogEE(__import__('ptvp35').TransactionView, 'aclear').enter(es)
|
||||||
|
LogEE(__import__('ptvp35').TransactionView, 'reset').enter(es)
|
||||||
|
ALogEE(__import__('ptvp35').TransactionView, 'areset').enter(es)
|
||||||
LogEE(__import__('ptvp35').TransactionView, 'get').enter(es)
|
LogEE(__import__('ptvp35').TransactionView, 'get').enter(es)
|
||||||
LogEE(__import__('ptvp35').TransactionView, 'set_nowait').enter(es)
|
LogEE(__import__('ptvp35').TransactionView, 'set_nowait').enter(es)
|
||||||
LogEE(__import__('ptvp35').TransactionView, '_delta').enter(es)
|
LogEE(__import__('ptvp35').TransactionView, '_delta').enter(es)
|
||||||
@ -238,6 +264,12 @@ async def main():
|
|||||||
LogEE(__import__('ptvp35').TransactionView, '_do_gather').enter(es)
|
LogEE(__import__('ptvp35').TransactionView, '_do_gather').enter(es)
|
||||||
LogEE(__import__('ptvp35').TransactionView, '_reduce_future').enter(es)
|
LogEE(__import__('ptvp35').TransactionView, '_reduce_future').enter(es)
|
||||||
LogEE(__import__('ptvp35').TransactionView, '_gather').enter(es)
|
LogEE(__import__('ptvp35').TransactionView, '_gather').enter(es)
|
||||||
|
ALogEE(__import__('ptvp35').TransactionView, 'commit_transaction').enter(es)
|
||||||
|
LogEE(__import__('ptvp35').TransactionView, 'submit_transaction').enter(es)
|
||||||
|
LogEE(__import__('ptvp35').TransactionView, 'submit_transaction_request').enter(es)
|
||||||
|
LogEE(__import__('ptvp35').TransactionView, 'loop').enter(es)
|
||||||
|
LogEE(__import__('ptvp35').TransactionView, 'transaction').enter(es)
|
||||||
|
|
||||||
LogEE(__import__('ptvp35').Transaction, '__init__').enter(es)
|
LogEE(__import__('ptvp35').Transaction, '__init__').enter(es)
|
||||||
ALogEE(__import__('ptvp35').Transaction, '__aenter__').enter(es)
|
ALogEE(__import__('ptvp35').Transaction, '__aenter__').enter(es)
|
||||||
ALogEE(__import__('ptvp35').Transaction, '__aexit__').enter(es)
|
ALogEE(__import__('ptvp35').Transaction, '__aexit__').enter(es)
|
||||||
|
Loading…
Reference in New Issue
Block a user