Skip to content

Commit

Permalink
show count of hidden C snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Aug 3, 2021
1 parent 48b934e commit af1e549
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/signals-mach.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ void *mach_profile_listener(void *arg)
break;
}

jl_ptls_t ptls = jl_all_tls_states[i];
host_thread_state_t state;
jl_thread_suspend_and_get_state2(i, &state);
unw_context_t *uc = (unw_context_t*)&state;
Expand Down Expand Up @@ -589,6 +588,8 @@ 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;

Expand Down
1 change: 0 additions & 1 deletion src/signals-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,6 @@ static void *signal_listener(void *arg)
for (int idx = jl_n_threads; idx-- > 0; ) {
// Stop the threads in the random round-robin order.
int i = profile_round_robin_thread_order[idx];

// notify thread to stop
jl_thread_suspend_and_get_state(i, &signal_context);

Expand Down
23 changes: 16 additions & 7 deletions stdlib/Profile/src/Profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function print(io::IO,
else
if !in(groupby, [:thread, :task, [:task, :thread], [:thread, :task]])
error(ArgumentError("Unrecognized groupby option: $groupby. Options are :none, :task, :thread, [:task, :thread], or [:thread, :task]"))
elseif in(groupby, [:thread, [:task, :thread], [:thread, :task]])
elseif Sys.iswindows() && in(groupby, [:thread, [:task, :thread], [:thread, :task]])
@warn "Profiling on windows is limited to the main thread. Other threads will not show in the report"
end
any_nosamples = false
Expand Down Expand Up @@ -847,7 +847,8 @@ function tree!(root::StackFrameTree{T}, all::Vector{UInt64}, lidict::Union{LineI
nothing
end
cleanup!(root)
return root
hidden_count = length(root.down) > 0 ? root.count - mapreduce(x -> x.count, +, values(root.down)) : 0
return root, hidden_count
end

function maxstats(root::StackFrameTree)
Expand Down Expand Up @@ -918,24 +919,32 @@ end
function tree(io::IO, data::Vector{UInt64}, lidict::Union{LineInfoFlatDict, LineInfoDict}, cols::Int, fmt::ProfileFormat,
threads::Union{Int,AbstractVector{Int}}, tasks::Union{UInt,AbstractVector{UInt}}, header::Bool, minwarn::Bool)
if fmt.combine
root = tree!(StackFrameTree{StackFrame}(), data, lidict, fmt.C, fmt.recur, threads, tasks)
root, hidden_count = tree!(StackFrameTree{StackFrame}(), data, lidict, fmt.C, fmt.recur, threads, tasks)
else
root = tree!(StackFrameTree{UInt64}(), data, lidict, fmt.C, fmt.recur, threads, tasks)
root, hidden_count = tree!(StackFrameTree{UInt64}(), data, lidict, fmt.C, fmt.recur, threads, tasks)
end
if isempty(root.down)
if minwarn
Base.print(io, "Total snapshots: ")
printstyled(io, "0\n", color=Base.warn_color())
printstyled(io, "$(root.count - hidden_count)", color=Base.warn_color())
if hidden_count > 0
println(io, " [$(hidden_count) from C hidden]")
else
println(io)
end
else
warning_empty()
end
return true
end
idlecount = print_tree(io, root, cols, fmt, header)
Base.print(io, "Total snapshots: ", root.count)
Base.print(io, "Total snapshots: ", root.count - hidden_count)
if hidden_count > 0
Base.print(io, " [$(hidden_count) from C hidden]")
end
if idlecount > 0
ending = length(threads) > 1 && length(tasks) > 1 ? " across threads $(threads). Use the `groupby` kwarg to separate threads and/or tasks" : ""
Base.println(" (", round(Int, (idlecount / root.count) * 100), "% idle$ending)")
Base.println(" (", round(Int, (idlecount / (root.count - hidden_count)) * 100), "% idle$ending)")
else
Base.println()
end
Expand Down

0 comments on commit af1e549

Please sign in to comment.