Skip to content

Commit 28a3c7c

Browse files
author
Mohamed Koubaa
committed
add trace options
1 parent f2058b4 commit 28a3c7c

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

clr_loader/__init__.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ def get_mono(
3232
jit_options: Optional[Sequence[str]] = None,
3333
assembly_dir: Optional[str] = None,
3434
config_dir: Optional[str] = None,
35-
set_signal_chaining: bool = False
35+
set_signal_chaining: bool = False,
36+
trace_mask: Optional[str] = None,
37+
trace_level: Optional[str] = None
3638
) -> Runtime:
3739
"""Get a Mono runtime instance
3840
@@ -65,6 +67,25 @@ def get_mono(
6567
- SIGQUIT
6668
- SIGUSR2
6769
This currently only works on POSIX platforms
70+
:param trace_mask:
71+
The trace filter, ordinarily set by the MONO_LOG_MASK environment variable.
72+
It can be set to one or more of the values, separated by comma. The default
73+
if this parameter is not used is "all". Possible options are:
74+
- all
75+
- aot
76+
- asm
77+
- cfg
78+
- dll
79+
- gc
80+
- io-layer
81+
- io-selector
82+
- security
83+
- threadpool
84+
- type
85+
:param trace_level:
86+
The trace level, ordinarily set by the MONO_LOG_LEVEL environment variable.
87+
It can be set to one of "error", "critical", "warning", "message", "info",
88+
or "debug".
6889
"""
6990
from .mono import Mono
7091

@@ -82,6 +103,8 @@ def get_mono(
82103
assembly_dir=assembly_dir,
83104
config_dir=config_dir,
84105
set_signal_chaining=set_signal_chaining,
106+
trace_mask=trace_mask,
107+
trace_level=trace_level
85108
)
86109
return impl
87110

clr_loader/ffi/mono.py

+3
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,8 @@
4444
4545
void mono_set_signal_chaining(bool chain_signals);
4646
47+
void mono_trace_set_level_string(const char* value);
48+
void mono_trace_set_mask_string(const char* value);
49+
4750
"""
4851
)

clr_loader/mono.py

+13
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def __init__(
2727
assembly_dir: Optional[str] = None,
2828
config_dir: Optional[str] = None,
2929
set_signal_chaining: bool = False,
30+
trace_mask: Optional[str] = None,
31+
trace_level: Optional[str] = None
3032
):
3133
self._assemblies: Dict[Path, Any] = {}
3234

@@ -39,6 +41,8 @@ def __init__(
3941
assembly_dir=assembly_dir,
4042
config_dir=config_dir,
4143
set_signal_chaining=set_signal_chaining,
44+
trace_mask=trace_mask,
45+
trace_level=trace_level,
4246
)
4347

4448
if domain is None:
@@ -130,11 +134,20 @@ def initialize(
130134
assembly_dir: Optional[str] = None,
131135
config_dir: Optional[str] = None,
132136
set_signal_chaining: bool = False,
137+
trace_mask: Optional[str] = None,
138+
trace_level: Optional[str] = None
133139
) -> str:
134140
global _MONO, _ROOT_DOMAIN
135141
if _MONO is None:
136142
_MONO = load_mono(libmono)
137143

144+
if trace_mask is not None:
145+
_MONO.mono_trace_set_mask_string(trace_mask.encode("utf8"))
146+
147+
if trace_level is not None:
148+
_MONO.mono_trace_set_level_string(trace_level.encode("utf8"))
149+
150+
138151
if assembly_dir is not None and config_dir is not None:
139152
_MONO.mono_set_dirs(assembly_dir.encode("utf8"), config_dir.encode("utf8"))
140153

tests/test_common.py

+18
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ def test_mono_signal_chaining(example_netstandard: Path):
5757
run_tests(asm)
5858

5959

60+
def test_mono_trace_mask(example_netstandard: Path):
61+
from clr_loader import get_mono
62+
63+
mono = get_mono(trace_mask="all")
64+
asm = mono.get_assembly(example_netstandard / "example.dll")
65+
66+
run_tests(asm)
67+
68+
69+
def test_mono_trace_level(example_netstandard: Path):
70+
from clr_loader import get_mono
71+
72+
mono = get_mono(trace_level="message")
73+
asm = mono.get_assembly(example_netstandard / "example.dll")
74+
75+
run_tests(asm)
76+
77+
6078
def test_mono_set_dir(example_netstandard: Path):
6179
from clr_loader import get_mono
6280

0 commit comments

Comments
 (0)