Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion src/ReTestItems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,8 @@ function manage_worker(
# Handle the exception
if e isa TimeoutException
@debugv 1 "Test item $(repr(testitem.name)) timed out. Terminating worker $worker"
terminate!(worker)
trigger_profile(worker, :timeout)
Copy link
Collaborator

Choose a reason for hiding this comment

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

it would probably be nice to make it configurable whether or not the trigger_profile is run, and with that the amount of time to wait (currently you have it at 120) to do the profile printing.

terminate!(worker, :timeout)
wait(worker)
@error "$worker timed out running test item $(repr(testitem.name)) after $timeout seconds. \
Recording test error."
Expand Down
18 changes: 18 additions & 0 deletions src/workers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Workers
using Sockets, Serialization

export Worker, remote_eval, remote_fetch, terminate!, WorkerTerminatedException
export trigger_profile

function try_with_timeout(f, timeout)
cond = Threads.Condition()
Expand Down Expand Up @@ -105,6 +106,23 @@ function watch_and_terminate!(w::Worker, ev::Threads.Event)
true
end

# Send signal to the given `Worker` process to trigger a profile.
# Users can customise this profiling in the usual way, e.g. via
# `JULIA_PROFILE_PEEK_HEAP_SNAPSHOT`, `Profile.set_peek_duration`, `Profile.peek_report[]`
# See https://docs.julialang.org/en/v1/stdlib/Profile/#Triggered-During-Execution
function trigger_profile(w::Worker, from::Symbol=:manual)
if !Sys.iswindows()
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not windows? because there isn't a SIGINFO equivalent?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question! Looks like i did this because upstream Julia doesn't support this functionality on Windows... but idk why not

@debug "sending profile request to worker $(w.pid) from $from"
if Sys.islinux()
kill(w.process, 10) # SIGUSR1
elseif Sys.isbsd()
kill(w.process, 29) # SIGINFO
end
end
sleep(120) # Leave time for it to print the profile.
return nothing
end

# gracefully terminate a worker by sending a shutdown message
# and waiting for the other tasks to perform worker shutdown
function Base.close(w::Worker)
Expand Down