Skip to content

Commit 76fa182

Browse files
authored
alloc profiler: adjust warnings in docs; remove logged warning from implementation (#44077)
* docs: update warning in the manual; add to reference * remove missed allocs warning from `fetch` since we think we've gotten all the allocs * remove tests of warning message, since it's no longer there
1 parent 6b16eba commit 76fa182

File tree

3 files changed

+15
-68
lines changed

3 files changed

+15
-68
lines changed

doc/src/manual/profile.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,12 @@ Passing `sample_rate=1.0` will make it record everything (which is slow);
356356
!!! note
357357

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

364366
## External Profiling
365367

stdlib/Profile/src/Allocs.jl

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ julia> results = Profile.Allocs.fetch()
4444
julia> last(sort(results.allocs, by=x->x.size))
4545
Profile.Allocs.Alloc(Vector{Any}, Base.StackTraces.StackFrame[_new_array_ at array.c:127, ...], 5576)
4646
```
47+
48+
Note: The current implementation of the Allocations Profiler _does not
49+
capture types for all allocations._ Allocations for which the profiler
50+
could not capture the type are represented as having type
51+
`Profile.Allocs.UnknownType`.
52+
53+
You can read more about the missing types and the plan to improve this, here:
54+
https://github.com/JuliaLang/julia/issues/43688.
4755
"""
4856
macro profile(opts, ex)
4957
_prof_expr(ex, opts)
@@ -52,12 +60,6 @@ macro profile(ex)
5260
_prof_expr(ex, :(sample_rate=0.0001))
5361
end
5462

55-
# globals used for tracking how many allocs we're missing
56-
# vs the alloc counters used by @time
57-
const _g_gc_num_before = Ref{Base.GC_Num}()
58-
const _g_sample_rate = Ref{Real}()
59-
const _g_expected_sampled_allocs = Ref{Float64}(0)
60-
6163
function _prof_expr(expr, opts)
6264
quote
6365
$start(; $(esc(opts)))
@@ -77,9 +79,6 @@ A sample rate of 1.0 will record everything; 0.0 will record nothing.
7779
"""
7880
function start(; sample_rate::Real)
7981
ccall(:jl_start_alloc_profile, Cvoid, (Cdouble,), Float64(sample_rate))
80-
81-
_g_sample_rate[] = sample_rate
82-
_g_gc_num_before[] = Base.gc_num()
8382
end
8483

8584
"""
@@ -89,15 +88,6 @@ Stop recording allocations.
8988
"""
9089
function stop()
9190
ccall(:jl_stop_alloc_profile, Cvoid, ())
92-
93-
# increment a counter of how many allocs we would expect
94-
# the memory profiler to see, based on how many allocs
95-
# actually happened.
96-
gc_num_after = Base.gc_num()
97-
gc_diff = Base.GC_Diff(gc_num_after, _g_gc_num_before[])
98-
alloc_count = Base.gc_alloc_count(gc_diff)
99-
expected_samples = alloc_count * _g_sample_rate[]
100-
_g_expected_sampled_allocs[] += expected_samples
10191
end
10292

10393
"""
@@ -107,8 +97,6 @@ Clear all previously profiled allocation information from memory.
10797
"""
10898
function clear()
10999
ccall(:jl_free_alloc_profile, Cvoid, ())
110-
111-
_g_expected_sampled_allocs[] = 0
112100
return nothing
113101
end
114102

@@ -120,25 +108,7 @@ objects which can be analyzed.
120108
"""
121109
function fetch()
122110
raw_results = ccall(:jl_fetch_alloc_profile, RawResults, ())
123-
decoded_results = decode(raw_results)
124-
125-
# avoid divide-by-0 errors
126-
if _g_expected_sampled_allocs[] > 0
127-
missed_allocs = max(0, _g_expected_sampled_allocs[] - length(decoded_results.allocs))
128-
missed_percentage = max(0, round(Int, missed_allocs / _g_expected_sampled_allocs[] * 100))
129-
if missed_percentage > 0
130-
@warn("The allocation profiler is not fully implemented, and missed approximately" *
131-
" $(missed_percentage)% (estimated $(round(Int, missed_allocs)) / $(round(Int,
132-
_g_expected_sampled_allocs[]))) " *
133-
"of sampled allocs in the last run. " *
134-
"For more info see https://github.com/JuliaLang/julia/issues/43688")
135-
else
136-
@warn("The allocation profiler is not fully implemented, and may have missed" *
137-
" some of the allocs. " *
138-
"For more info see https://github.com/JuliaLang/julia/issues/43688")
139-
end
140-
end
141-
return decoded_results
111+
return decode(raw_results)
142112
end
143113

144114
# decoded results

stdlib/Profile/test/allocs.jl

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -111,31 +111,6 @@ end
111111
Allocs.clear()
112112
end
113113

114-
@testset "alloc profiler warning message" begin
115-
@testset "no allocs" begin
116-
Profile.Allocs.clear()
117-
Profile.Allocs.fetch()
118-
end
119-
@testset "catches all allocations" begin
120-
foo() = []
121-
precompile(foo, ())
122-
Profile.Allocs.clear()
123-
Profile.Allocs.@profile sample_rate=1 foo()
124-
# Fake that we expected exactly 1 alloc, since we should have recorded >= 1
125-
Profile.Allocs._g_expected_sampled_allocs[] = 1
126-
@assert length(Profile.Allocs.fetch().allocs) >= 1
127-
end
128-
@testset "misses some allocations" begin
129-
foo() = []
130-
precompile(foo, ())
131-
Profile.Allocs.clear()
132-
Profile.Allocs.@profile sample_rate=1 foo()
133-
# Fake some allocs that we missed, to force the print statement
134-
Profile.Allocs._g_expected_sampled_allocs[] += 10
135-
@assert 1 <= length(Profile.Allocs.fetch().allocs) < 10
136-
end
137-
end
138-
139114
@testset "alloc profiler catches strings" begin
140115
Allocs.@profile sample_rate=1 "$(rand())"
141116

0 commit comments

Comments
 (0)