Skip to content
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

alloc profiler: adjust warnings in docs; remove logged warning from implementation #44077

Merged
merged 4 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions doc/src/manual/profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,12 @@ Passing `sample_rate=1.0` will make it record everything (which is slow);
!!! note

The current implementation of the Allocations Profiler _does not
capture all allocations._ You can read more about the missing allocations
and the plan to improve this, here: https://github.com/JuliaLang/julia/issues/43688.
Calling `Profile.Allocs.fetch()` will print a log line reporting the percentage
of missed allocations, so you can understand the accuracy of your profile.
capture types for all allocations._ Allocations for which the profiler
could not capture the type are represented as having type
`Profile.Allocs.UnknownType`.

You can read more about the missing types and the plan to improve this, here:
https://github.com/JuliaLang/julia/issues/43688.

## External Profiling

Expand Down
8 changes: 8 additions & 0 deletions stdlib/Profile/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ Profile.clear_malloc_data

## Memory profiling

Note: The current implementation of the Allocations Profiler _does not
capture types for all allocations._ Allocations for which the profiler
could not capture the type are represented as having type
`Profile.Allocs.UnknownType`.

You can read more about the missing types and the plan to improve this, here:
https://github.com/JuliaLang/julia/issues/43688.

NHDaly marked this conversation as resolved.
Show resolved Hide resolved
```@docs
Profile.Allocs.@profile
```
Expand Down
40 changes: 1 addition & 39 deletions stdlib/Profile/src/Allocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ macro profile(ex)
_prof_expr(ex, :(sample_rate=0.0001))
end

# globals used for tracking how many allocs we're missing
# vs the alloc counters used by @time
const _g_gc_num_before = Ref{Base.GC_Num}()
const _g_sample_rate = Ref{Real}()
const _g_expected_sampled_allocs = Ref{Float64}(0)
NHDaly marked this conversation as resolved.
Show resolved Hide resolved

function _prof_expr(expr, opts)
quote
$start(; $(esc(opts)))
Expand All @@ -77,9 +71,6 @@ A sample rate of 1.0 will record everything; 0.0 will record nothing.
"""
function start(; sample_rate::Real)
ccall(:jl_start_alloc_profile, Cvoid, (Cdouble,), Float64(sample_rate))

_g_sample_rate[] = sample_rate
_g_gc_num_before[] = Base.gc_num()
end

"""
Expand All @@ -89,15 +80,6 @@ Stop recording allocations.
"""
function stop()
ccall(:jl_stop_alloc_profile, Cvoid, ())

# increment a counter of how many allocs we would expect
# the memory profiler to see, based on how many allocs
# actually happened.
gc_num_after = Base.gc_num()
gc_diff = Base.GC_Diff(gc_num_after, _g_gc_num_before[])
alloc_count = Base.gc_alloc_count(gc_diff)
expected_samples = alloc_count * _g_sample_rate[]
_g_expected_sampled_allocs[] += expected_samples
end

"""
Expand All @@ -107,8 +89,6 @@ Clear all previously profiled allocation information from memory.
"""
function clear()
ccall(:jl_free_alloc_profile, Cvoid, ())

_g_expected_sampled_allocs[] = 0
return nothing
end

Expand All @@ -120,25 +100,7 @@ objects which can be analyzed.
"""
function fetch()
raw_results = ccall(:jl_fetch_alloc_profile, RawResults, ())
decoded_results = decode(raw_results)

# avoid divide-by-0 errors
if _g_expected_sampled_allocs[] > 0
missed_allocs = max(0, _g_expected_sampled_allocs[] - length(decoded_results.allocs))
missed_percentage = max(0, round(Int, missed_allocs / _g_expected_sampled_allocs[] * 100))
if missed_percentage > 0
@warn("The allocation profiler is not fully implemented, and missed approximately" *
" $(missed_percentage)% (estimated $(round(Int, missed_allocs)) / $(round(Int,
_g_expected_sampled_allocs[]))) " *
"of sampled allocs in the last run. " *
"For more info see https://github.com/JuliaLang/julia/issues/43688")
else
@warn("The allocation profiler is not fully implemented, and may have missed" *
" some of the allocs. " *
"For more info see https://github.com/JuliaLang/julia/issues/43688")
end
end
return decoded_results
return decode(raw_results)
end

# decoded results
Expand Down