From 201f4de1fdc6b6095eb3ed32c429b60d5f837e67 Mon Sep 17 00:00:00 2001 From: N5N3 <2642243996@qq.com> Date: Fri, 4 Feb 2022 16:15:51 +0800 Subject: [PATCH] Revert "Profile: multithread getdict! (redo of #43805) (#43816)" This reverts commit e6fa3ec44e065b8589feb09cba82938fe36aa86d. --- stdlib/Profile/src/Profile.jl | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/stdlib/Profile/src/Profile.jl b/stdlib/Profile/src/Profile.jl index 3d550f85db9d87..f969df5ed040e9 100644 --- a/stdlib/Profile/src/Profile.jl +++ b/stdlib/Profile/src/Profile.jl @@ -349,34 +349,19 @@ function getdict(data::Vector{UInt}) end function getdict!(dict::LineInfoDict, data::Vector{UInt}) - # we don't want metadata here as we're just looking up ips - unique_ips = unique(has_meta(data) ? strip_meta(data) : data) - n_unique_ips = length(unique_ips) - n_unique_ips == 0 && return dict - iplookups = similar(unique_ips, Vector{StackFrame}) - @sync for indexes_part in Iterators.partition(eachindex(unique_ips), div(n_unique_ips, Threads.nthreads(), RoundUp)) - Threads.@spawn begin - for i in indexes_part - iplookups[i] = _lookup_corrected(unique_ips[i]) - end - end - end - for i in eachindex(unique_ips) - dict[unique_ips[i]] = iplookups[i] + for ip in data + # Lookup is expensive, so do it only once per ip. + haskey(dict, UInt64(ip)) && continue + st = lookup(convert(Ptr{Cvoid}, ip)) + # To correct line numbers for moving code, put it in the form expected by + # Base.update_stackframes_callback[] + stn = map(x->(x, 1), st) + try Base.invokelatest(Base.update_stackframes_callback[], stn) catch end + dict[UInt64(ip)] = map(first, stn) end return dict end -function _lookup_corrected(ip::UInt) - st = lookup(convert(Ptr{Cvoid}, ip)) - # To correct line numbers for moving code, put it in the form expected by - # Base.update_stackframes_callback[] - stn = map(x->(x, 1), st) - # Note: Base.update_stackframes_callback[] should be data-race free - try Base.invokelatest(Base.update_stackframes_callback[], stn) catch end - return map(first, stn) -end - """ flatten(btdata::Vector, lidict::LineInfoDict) -> (newdata::Vector{UInt64}, newdict::LineInfoFlatDict)