-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add thread_ids::Vector
option to Profile.init()
#39746
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,30 +37,46 @@ end | |
#### | ||
|
||
""" | ||
init(; n::Integer, delay::Real)) | ||
init(; n::Integer, delay::Real, thread_ids::Vector{<:Integer})) | ||
|
||
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 | ||
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)`. | ||
independently using keywords or in the order `(n, delay)`. Finally, you can configure | ||
profiling to only profile individual threads by passing their thread ids in `thread_ids`. | ||
""" | ||
function init(; n::Union{Nothing,Integer} = nothing, delay::Union{Nothing,Real} = nothing) | ||
function init(; n::Union{Nothing,Integer} = nothing, delay::Union{Nothing,Real} = nothing, | ||
thread_ids::Vector{<:Integer} = Int[]) | ||
n_cur = ccall(:jl_profile_maxlen_data, Csize_t, ()) | ||
delay_cur = ccall(:jl_profile_delay_nsec, UInt64, ())/10^9 | ||
if n === nothing && delay === nothing | ||
_init_threadid_filter(thread_ids) | ||
return Int(n_cur), delay_cur | ||
end | ||
nnew = (n === nothing) ? n_cur : n | ||
delaynew = (delay === nothing) ? delay_cur : delay | ||
init(nnew, delaynew) | ||
init(nnew, delaynew, thread_ids) | ||
end | ||
|
||
function init(n::Integer, delay::Real) | ||
function init(n::Integer, delay::Real, thread_ids::Vector = Int[]) | ||
status = ccall(:jl_profile_init, Cint, (Csize_t, UInt64), n, round(UInt64,10^9*delay)) | ||
if status == -1 | ||
error("could not allocate space for ", n, " instruction pointers") | ||
end | ||
_init_threadid_filter(thread_ids) | ||
end | ||
function _init_threadid_filter(thread_ids::Vector) | ||
threadid_mask = UInt64(0) | ||
if !isempty(thread_ids) | ||
for tid in thread_ids | ||
if tid > 64 | ||
error("Cannot enable thread id > 64 via `Profile.init(thread_ids)`: $(tid).") | ||
end | ||
threadid_mask |= 0x1 << (tid-1) | ||
end | ||
ccall(:jl_profile_init_threadid_filter, Cvoid, (UInt64,), threadid_mask) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, we should move this outside the if block, so that we can reset the filter when passing an empty vector. |
||
end | ||
end | ||
|
||
# init with default values | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, now that I think about it, I guess thread_ids should be "sticky," too, like the other params? I was trying to be super safe here to make sure it's always reset back to normal to preserve backwards compatibility, but I think that is someone if using the girls, it would make more sense for it to work like the others.
I can change this in the morning. :)
Should this also get added to the return value? Would we want to return the mask or the array? If we want to return the array, I can either add a getter for the mask and reconstruct the vector from it, or we can store the vector as a global in Julia, in parallel with the mask. I think a getter for the mask makes more sense.