Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add trace options #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion clr_loader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions clr_loader/ffi/mono.py
Original file line number Diff line number Diff line change
Expand Up @@ -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);

"""
)
13 changes: 13 additions & 0 deletions clr_loader/mono.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}

Expand All @@ -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:
Expand Down Expand Up @@ -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"))

Expand Down
18 changes: 18 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading