Skip to content
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
4 changes: 4 additions & 0 deletions src/julia/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def yes_no_etc(*etc):

threads: {int, 'auto'}
How many threads to use.

trace_compile: str
Trace precompile statements during execution to the given file.
"""


Expand Down Expand Up @@ -174,6 +177,7 @@ class JuliaOptions(object):
inline = Choices("inline", yes_no_etc())
check_bounds = Choices("check_bounds", yes_no_etc())
threads = IntEtc("threads", etc={"auto"})
trace_compile = String("trace_compile")

def __init__(self, **kwargs):
unsupported = []
Expand Down
31 changes: 31 additions & 0 deletions src/julia/tests/test_trace_compile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import re
from pathlib import Path

from .test_compatible_exe import runcode
from .utils import skip_in_windows


@skip_in_windows
def test_trace_file_created(tmpdir):
trace_compile_path = Path(tmpdir) / "trace_compile.jl"
runcode(
f"""
from julia.api import Julia
jl = Julia(trace_compile="{trace_compile_path}")

from julia import Main
Main.sin(2.0)
""".format(
str(trace_compile_path)
)
)
assert (trace_compile_path).exists()
assert len(trace_compile_path.read_text().strip()) > 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some compilation string that you know should be printed to this file? If so, could you test that it actually shows up there?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's a great idea! I added a check for the precompilation directive of the sin function we invoke to test precompilation.


# check whether the sin precompilation directive is included in the file
trace_compile_content = Path(trace_compile_path).read_text().strip()
lines = [x for x in trace_compile_content.split("\n") if len(x) > 0]
expected_precompile_line = (
r"precompile\(Tuple\{typeof\([A-Za-z]+\.sin\), Float64\}\)"
)
assert any([re.match(expected_precompile_line, x) is not None for x in lines])