Skip to content

profiling

profile_julia_calls(*, n=10 ** 7, delay=0.0005, mincount=5)

Profiles Julia-side execution during the wrapped block, including calls made into Julia from Python (e.g. FinchJLKernel.__call__). Prints a flat, count-sorted profile on exit.

Example

with profile_julia_calls(): ft.compute(expr)

Source code in src/finch/compile_jl/profiling.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@contextmanager
def profile_julia_calls(
    *, n: int = 10**7, delay: float = 0.0005, mincount: int = 5
) -> Generator[None, None, None]:
    """
    Profiles Julia-side execution during the wrapped block, including calls
    made into Julia from Python (e.g. `FinchJLKernel.__call__`). Prints a
    flat, count-sorted profile on exit.

    Example:
        with profile_julia_calls():
            ft.compute(expr)
    """
    jl.seval("using Profile")
    jl.seval("Profile.clear()")
    jl.seval(f"Profile.init(n={n}, delay={delay})")
    jl.seval("ccall(:jl_profile_start_timer, Cint, ())")
    try:
        yield
    finally:
        jl.seval("ccall(:jl_profile_stop_timer, Cvoid, ())")
        jl.seval("Profile.print(format=:tree)")