Skip to content

Commit

Permalink
Thread and task specific profiling
Browse files Browse the repository at this point in the history
- Adds thread and task ids to profile samples
- Implements thread and task selection for Profile.print()
- Implements thread and task groupby options for Profile.print()
- Add include_meta to Profile.fetch() which defaults to false to ensure backwards compat with external profiling tooling
  • Loading branch information
IanButterworth committed Aug 8, 2021
1 parent 0e8bb95 commit 96c7cb3
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 42 deletions.
6 changes: 5 additions & 1 deletion contrib/generate_precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ Profile = get(Base.loaded_modules,
nothing)
if Profile !== nothing
hardcoded_precompile_statements *= """
precompile(Tuple{typeof(Profile.tree!), Profile.StackFrameTree{UInt64}, Vector{UInt64}, Dict{UInt64, Vector{Base.StackTraces.StackFrame}}, Bool, Symbol})
precompile(Tuple{typeof(Profile.tree!), Profile.StackFrameTree{UInt64}, Vector{UInt64}, Dict{UInt64, Vector{Base.StackTraces.StackFrame}}, Bool, Symbol, Int, UInt})
precompile(Tuple{typeof(Profile.tree!), Profile.StackFrameTree{UInt64}, Vector{UInt64}, Dict{UInt64, Vector{Base.StackTraces.StackFrame}}, Bool, Symbol, Int, UnitRange{UInt}})
precompile(Tuple{typeof(Profile.tree!), Profile.StackFrameTree{UInt64}, Vector{UInt64}, Dict{UInt64, Vector{Base.StackTraces.StackFrame}}, Bool, Symbol, UnitRange{Int}, UInt})
precompile(Tuple{typeof(Profile.tree!), Profile.StackFrameTree{UInt64}, Vector{UInt64}, Dict{UInt64, Vector{Base.StackTraces.StackFrame}}, Bool, Symbol, UnitRange{Int}, UnitRange{UInt}})
precompile(Tuple{typeof(Profile.tree!), Profile.StackFrameTree{UInt64}, Vector{UInt64}, Dict{UInt64, Vector{Base.StackTraces.StackFrame}}, Bool, Symbol, Vector{Int}, Vector{UInt}})
"""
end

Expand Down
7 changes: 7 additions & 0 deletions src/signals-mach.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,13 @@ void *mach_profile_listener(void *arg)
#else
bt_size_cur += rec_backtrace_ctx((jl_bt_element_t*)bt_data_prof + bt_size_cur, bt_size_max - bt_size_cur - 1, uc, NULL);
#endif
jl_ptls_t ptls = jl_all_tls_states[i];

// store threadid but add 1 as 0 is preserved to indicate end of block
bt_data_prof[bt_size_cur++].uintptr = ptls->tid + 1;

// store task id
bt_data_prof[bt_size_cur++].uintptr = ptls->current_task;

// Mark the end of this block with 0
bt_data_prof[bt_size_cur++].uintptr = 0;
Expand Down
8 changes: 8 additions & 0 deletions src/signals-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,14 @@ static void *signal_listener(void *arg)
}
jl_set_safe_restore(old_buf);

jl_ptls_t ptls = jl_all_tls_states[i];

// store threadid but add 1 as 0 is preserved to indicate end of block
bt_data_prof[bt_size_cur++].uintptr = ptls->tid + 1;

// store task id
bt_data_prof[bt_size_cur++].uintptr = ptls->current_task;

// Mark the end of this block with 0
bt_data_prof[bt_size_cur++].uintptr = 0;
}
Expand Down
9 changes: 9 additions & 0 deletions src/signals-win.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ static DWORD WINAPI profile_bt( LPVOID lparam )
// Get backtrace data
bt_size_cur += rec_backtrace_ctx((jl_bt_element_t*)bt_data_prof + bt_size_cur,
bt_size_max - bt_size_cur - 1, &ctxThread, NULL);

jl_ptls_t ptls = jl_all_tls_states[0]; // given only profiling hMainThread

// store threadid but add 1 as 0 is preserved to indicate end of block
bt_data_prof[bt_size_cur++].uintptr = ptls->tid + 1;

// store task id
bt_data_prof[bt_size_cur++].uintptr = ptls->current_task;

// Mark the end of this block with 0
bt_data_prof[bt_size_cur++].uintptr = 0;
}
Expand Down
Loading

0 comments on commit 96c7cb3

Please sign in to comment.