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

Profile: allocate buffer for n instruction pointers per thread #41821

Merged
Merged
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
14 changes: 10 additions & 4 deletions stdlib/Profile/src/Profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,32 @@ end
init(; n::Integer, delay::Real))
Configure the `delay` between backtraces (measured in seconds), and the number `n` of
instruction pointers that may be stored. Each instruction pointer corresponds to a single
instruction pointers that may be stored per thread. Each instruction pointer corresponds to a single
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Maybe add a !!! compat note?

Copy link
Member

Choose a reason for hiding this comment

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

+1 to a compat note

line of code; backtraces generally consist of a long list of instruction pointers. Current
settings can be obtained by calling this function with no arguments, and each can be set
independently using keywords or in the order `(n, delay)`.
!!! compat "Julia 1.8"
As of Julia 1.8, this function allocates space for `n` instruction pointers per thread being profiled.
Previously this was `n` total.
"""
function init(; n::Union{Nothing,Integer} = nothing, delay::Union{Nothing,Real} = nothing)
n_cur = ccall(:jl_profile_maxlen_data, Csize_t, ())
delay_cur = ccall(:jl_profile_delay_nsec, UInt64, ())/10^9
if n === nothing && delay === nothing
return Int(n_cur), delay_cur
end
nnew = (n === nothing) ? n_cur : n
nthreads = Sys.iswindows() ? 1 : Threads.nthreads() # windows only profiles the main thread
nnew = (n === nothing) ? n_cur : n * nthreads
Copy link
Sponsor Member Author

@IanButterworth IanButterworth Aug 17, 2021

Choose a reason for hiding this comment

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

There's also a bug here. This method passes to the method below, so this was multiplying by nthreads twice. I'm about to open a PR

delaynew = (delay === nothing) ? delay_cur : delay
init(nnew, delaynew)
end

function init(n::Integer, delay::Real)
status = ccall(:jl_profile_init, Cint, (Csize_t, UInt64), n, round(UInt64,10^9*delay))
nthreads = Sys.iswindows() ? 1 : Threads.nthreads() # windows only profiles the main thread
status = ccall(:jl_profile_init, Cint, (Csize_t, UInt64), n * nthreads, round(UInt64,10^9*delay))
if status == -1
error("could not allocate space for ", n, " instruction pointers")
error("could not allocate space for ", n, " instruction pointers per thread being profiled ($nthreads threads)")
end
end

Expand Down