pfitzseb / ProfileCanvas.jl

MIT License
87 stars 6 forks source link

Inaccurate allocation size? #30

Closed charleskawczynski closed 1 year ago

charleskawczynski commented 1 year ago

I'm not sure if this is an issue with Profile.Allocs, ProfileCanvas.jl, or my interpretation/understanding, but:

import ProfileCanvas
import Profile

function foo!(x)
    s = 0.0
    y = []
    for i in x
        s += i - sin(1)
        push!(y, s)
    end
    return nothing
end

function workload(x)
    for i in 1:1
        foo!(x)
    end
    return nothing
end

x = rand(1)
workload(x) # compile
p_allocated = @allocated workload(x)
@show p_allocated # 144 bytes

Profile.Allocs.clear()
Profile.Allocs.@profile sample_rate = 1 workload(x)
results = Profile.Allocs.fetch()
display(ProfileCanvas.view_allocs(results))

Switching over to size in this flame graph shows 3 blocks

pfitzseb commented 1 year ago

I can repro this, but it isn't an issue with ProfileCanvas:

julia> @show p_allocated # 144 bytes
p_allocated = 144
144

julia> Profile.Allocs.clear()

julia> Profile.Allocs.@profile sample_rate = 1 workload(x)

julia> results = Profile.Allocs.fetch()
Profile.Allocs.AllocResults(Profile.Allocs.Alloc[Profile.Allocs.Alloc(Vector{Any}, Base.StackTraces.StackFrame[maybe_record_alloc_to_profile at gc-alloc-profiler.h:42 [inlined], ...], 40), Profile.Allocs.Alloc(Profile.Allocs.BufferType, Base.StackTraces.StackFrame[maybe_record_alloc_to_profile at gc-alloc-profiler.h:42 [inlined], ...], 64), Profile.Allocs.Alloc(Profile.Allocs.UnknownType, Base.StackTraces.StackFrame[maybe_record_alloc_to_profile at gc-alloc-profiler.h:42 [inlined], ...], 16)])

julia> sum(a -> a.size, results.allocs)
120

Please open an issue against base :)