From 28a3c7c66bf5989cd114e6bb2551ed646c67d10e Mon Sep 17 00:00:00 2001 From: Mohamed Koubaa Date: Tue, 14 May 2024 14:37:29 -0500 Subject: [PATCH] add trace options --- clr_loader/__init__.py | 25 ++++++++++++++++++++++++- clr_loader/ffi/mono.py | 3 +++ clr_loader/mono.py | 13 +++++++++++++ tests/test_common.py | 18 ++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/clr_loader/__init__.py b/clr_loader/__init__.py index aa604ad..0646fd0 100644 --- a/clr_loader/__init__.py +++ b/clr_loader/__init__.py @@ -32,7 +32,9 @@ def get_mono( jit_options: Optional[Sequence[str]] = None, assembly_dir: Optional[str] = None, config_dir: Optional[str] = None, - set_signal_chaining: bool = False + set_signal_chaining: bool = False, + trace_mask: Optional[str] = None, + trace_level: Optional[str] = None ) -> Runtime: """Get a Mono runtime instance @@ -65,6 +67,25 @@ def get_mono( - SIGQUIT - SIGUSR2 This currently only works on POSIX platforms + :param trace_mask: + The trace filter, ordinarily set by the MONO_LOG_MASK environment variable. + It can be set to one or more of the values, separated by comma. The default + if this parameter is not used is "all". Possible options are: + - all + - aot + - asm + - cfg + - dll + - gc + - io-layer + - io-selector + - security + - threadpool + - type + :param trace_level: + The trace level, ordinarily set by the MONO_LOG_LEVEL environment variable. + It can be set to one of "error", "critical", "warning", "message", "info", + or "debug". """ from .mono import Mono @@ -82,6 +103,8 @@ def get_mono( assembly_dir=assembly_dir, config_dir=config_dir, set_signal_chaining=set_signal_chaining, + trace_mask=trace_mask, + trace_level=trace_level ) return impl diff --git a/clr_loader/ffi/mono.py b/clr_loader/ffi/mono.py index c194393..a3249a1 100644 --- a/clr_loader/ffi/mono.py +++ b/clr_loader/ffi/mono.py @@ -44,5 +44,8 @@ void mono_set_signal_chaining(bool chain_signals); +void mono_trace_set_level_string(const char* value); +void mono_trace_set_mask_string(const char* value); + """ ) diff --git a/clr_loader/mono.py b/clr_loader/mono.py index 7c3f20d..0c35c7c 100644 --- a/clr_loader/mono.py +++ b/clr_loader/mono.py @@ -27,6 +27,8 @@ def __init__( assembly_dir: Optional[str] = None, config_dir: Optional[str] = None, set_signal_chaining: bool = False, + trace_mask: Optional[str] = None, + trace_level: Optional[str] = None ): self._assemblies: Dict[Path, Any] = {} @@ -39,6 +41,8 @@ def __init__( assembly_dir=assembly_dir, config_dir=config_dir, set_signal_chaining=set_signal_chaining, + trace_mask=trace_mask, + trace_level=trace_level, ) if domain is None: @@ -130,11 +134,20 @@ def initialize( assembly_dir: Optional[str] = None, config_dir: Optional[str] = None, set_signal_chaining: bool = False, + trace_mask: Optional[str] = None, + trace_level: Optional[str] = None ) -> str: global _MONO, _ROOT_DOMAIN if _MONO is None: _MONO = load_mono(libmono) + if trace_mask is not None: + _MONO.mono_trace_set_mask_string(trace_mask.encode("utf8")) + + if trace_level is not None: + _MONO.mono_trace_set_level_string(trace_level.encode("utf8")) + + if assembly_dir is not None and config_dir is not None: _MONO.mono_set_dirs(assembly_dir.encode("utf8"), config_dir.encode("utf8")) diff --git a/tests/test_common.py b/tests/test_common.py index 8a9e36d..7594c60 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -57,6 +57,24 @@ def test_mono_signal_chaining(example_netstandard: Path): run_tests(asm) +def test_mono_trace_mask(example_netstandard: Path): + from clr_loader import get_mono + + mono = get_mono(trace_mask="all") + asm = mono.get_assembly(example_netstandard / "example.dll") + + run_tests(asm) + + +def test_mono_trace_level(example_netstandard: Path): + from clr_loader import get_mono + + mono = get_mono(trace_level="message") + asm = mono.get_assembly(example_netstandard / "example.dll") + + run_tests(asm) + + def test_mono_set_dir(example_netstandard: Path): from clr_loader import get_mono