Skip to content

Commit 500288c

Browse files
Profile: make profile listener init a separate function (#55167)
I noticed this was an unrelated change in #55047 so I thought I'd separate it out
1 parent b451a1c commit 500288c

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

base/Base.jl

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,25 @@ function profile_printing_listener(cond::Base.AsyncCondition)
614614
nothing
615615
end
616616

617+
function start_profile_listener()
618+
cond = Base.AsyncCondition()
619+
Base.uv_unref(cond.handle)
620+
t = errormonitor(Threads.@spawn(profile_printing_listener(cond)))
621+
atexit() do
622+
# destroy this callback when exiting
623+
ccall(:jl_set_peek_cond, Cvoid, (Ptr{Cvoid},), C_NULL)
624+
# this will prompt any ongoing or pending event to flush also
625+
close(cond)
626+
# error-propagation is not needed, since the errormonitor will handle printing that better
627+
_wait(t)
628+
end
629+
finalizer(cond) do c
630+
# if something goes south, still make sure we aren't keeping a reference in C to this
631+
ccall(:jl_set_peek_cond, Cvoid, (Ptr{Cvoid},), C_NULL)
632+
end
633+
ccall(:jl_set_peek_cond, Cvoid, (Ptr{Cvoid},), cond.handle)
634+
end
635+
617636
function __init__()
618637
# Base library init
619638
global _atexit_hooks_finished = false
@@ -636,22 +655,7 @@ function __init__()
636655
# Profiling helper
637656
@static if !Sys.iswindows()
638657
# triggering a profile via signals is not implemented on windows
639-
cond = Base.AsyncCondition()
640-
Base.uv_unref(cond.handle)
641-
t = errormonitor(Threads.@spawn(profile_printing_listener(cond)))
642-
atexit() do
643-
# destroy this callback when exiting
644-
ccall(:jl_set_peek_cond, Cvoid, (Ptr{Cvoid},), C_NULL)
645-
# this will prompt any ongoing or pending event to flush also
646-
close(cond)
647-
# error-propagation is not needed, since the errormonitor will handle printing that better
648-
_wait(t)
649-
end
650-
finalizer(cond) do c
651-
# if something goes south, still make sure we aren't keeping a reference in C to this
652-
ccall(:jl_set_peek_cond, Cvoid, (Ptr{Cvoid},), C_NULL)
653-
end
654-
ccall(:jl_set_peek_cond, Cvoid, (Ptr{Cvoid},), cond.handle)
658+
start_profile_listener()
655659
end
656660
_require_world_age[] = get_world_counter()
657661
# Prevent spawned Julia process from getting stuck waiting on Tracy to connect.

0 commit comments

Comments
 (0)