mirror of
https://github.com/clearml/clearml
synced 2025-03-03 10:42:00 +00:00
Add improved trace filtering capabilities
This commit is contained in:
parent
8e859503f6
commit
2065288a90
@ -117,7 +117,7 @@ def _traced_call_func(name, fnc):
|
|||||||
return _traced_call_int
|
return _traced_call_int
|
||||||
|
|
||||||
|
|
||||||
def _patch_module(module, prefix='', basepath=None, basemodule=None):
|
def _patch_module(module, prefix='', basepath=None, basemodule=None, exclude_prefixes=[], only_prefix=[]):
|
||||||
if isinstance(module, str):
|
if isinstance(module, str):
|
||||||
if basemodule is None:
|
if basemodule is None:
|
||||||
basemodule = module + '.'
|
basemodule = module + '.'
|
||||||
@ -152,6 +152,10 @@ def _patch_module(module, prefix='', basepath=None, basemodule=None):
|
|||||||
if prefix.startswith('trains.backend_api.services.'):
|
if prefix.startswith('trains.backend_api.services.'):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
for skip in exclude_prefixes:
|
||||||
|
if prefix.startswith(skip):
|
||||||
|
return
|
||||||
|
|
||||||
for fn in (m for m in dir(module) if not m.startswith('__')):
|
for fn in (m for m in dir(module) if not m.startswith('__')):
|
||||||
if fn in ('schema_property') or fn.startswith('_PostImportHookPatching__'):
|
if fn in ('schema_property') or fn.startswith('_PostImportHookPatching__'):
|
||||||
continue
|
continue
|
||||||
@ -161,11 +165,22 @@ def _patch_module(module, prefix='', basepath=None, basemodule=None):
|
|||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
if inspect.ismodule(fnc):
|
if inspect.ismodule(fnc):
|
||||||
_patch_module(fnc, prefix=prefix, basepath=basepath, basemodule=basemodule)
|
_patch_module(fnc, prefix=prefix, basepath=basepath, basemodule=basemodule,
|
||||||
|
exclude_prefixes=exclude_prefixes, only_prefix=only_prefix)
|
||||||
elif inspect.isclass(fnc):
|
elif inspect.isclass(fnc):
|
||||||
_patch_module(fnc, prefix=prefix, basepath=basepath, basemodule=basemodule)
|
_patch_module(fnc, prefix=prefix, basepath=basepath, basemodule=basemodule,
|
||||||
|
exclude_prefixes=exclude_prefixes, only_prefix=only_prefix)
|
||||||
elif inspect.isroutine(fnc):
|
elif inspect.isroutine(fnc):
|
||||||
pass # _log_stderr('Patching: {}'.format(prefix+fn))
|
|
||||||
|
if only_prefix and all(p not in (prefix+str(fn)) for p in only_prefix):
|
||||||
|
continue
|
||||||
|
|
||||||
|
for skip in exclude_prefixes:
|
||||||
|
if (prefix+str(fn)).startswith(skip):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# _log_stderr('Patching: {}'.format(prefix+fn))
|
||||||
|
|
||||||
if inspect.isclass(module):
|
if inspect.isclass(module):
|
||||||
# check if this is even in our module
|
# check if this is even in our module
|
||||||
if hasattr(fnc, '__module__') and fnc.__module__ != module.__module__:
|
if hasattr(fnc, '__module__') and fnc.__module__ != module.__module__:
|
||||||
@ -191,7 +206,7 @@ def _patch_module(module, prefix='', basepath=None, basemodule=None):
|
|||||||
setattr(module, fn, _traced_call_func(prefix + fn, fnc))
|
setattr(module, fn, _traced_call_func(prefix + fn, fnc))
|
||||||
|
|
||||||
|
|
||||||
def trace_trains(stream=None, level=1):
|
def trace_trains(stream=None, level=1, exclude_prefixes=[], only_prefix=[]):
|
||||||
"""
|
"""
|
||||||
DEBUG ONLY - Add full Trains package code trace
|
DEBUG ONLY - Add full Trains package code trace
|
||||||
Output trace to filename or stream, default is sys.stderr
|
Output trace to filename or stream, default is sys.stderr
|
||||||
@ -237,8 +252,7 @@ def trace_trains(stream=None, level=1):
|
|||||||
__stream_write('{:9}:{:5}:{:8}: {:14}\n'.format('seconds', 'pid', 'tid', 'self'))
|
__stream_write('{:9}:{:5}:{:8}: {:14}\n'.format('seconds', 'pid', 'tid', 'self'))
|
||||||
__stream_write('{:9}:{:5}:{:8}:{:15}\n'.format('-' * 9, '-' * 5, '-' * 8, '-' * 15))
|
__stream_write('{:9}:{:5}:{:8}:{:15}\n'.format('-' * 9, '-' * 5, '-' * 8, '-' * 15))
|
||||||
__trace_start = time.time()
|
__trace_start = time.time()
|
||||||
|
_patch_module('trains', exclude_prefixes=exclude_prefixes or [], only_prefix=only_prefix or [])
|
||||||
_patch_module('trains')
|
|
||||||
|
|
||||||
|
|
||||||
def trace_level(level=1):
|
def trace_level(level=1):
|
||||||
|
Loading…
Reference in New Issue
Block a user