@@ -44,6 +44,14 @@ julia> results = Profile.Allocs.fetch()
4444julia> last(sort(results.allocs, by=x->x.size))
4545Profile.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"""
4856macro profile (opts, ex)
4957 _prof_expr (ex, opts)
@@ -52,12 +60,6 @@ macro profile(ex)
5260 _prof_expr (ex, :(sample_rate= 0.0001 ))
5361end
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-
6163function _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"""
7880function 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 ()
8382end
8483
8584"""
@@ -89,15 +88,6 @@ Stop recording allocations.
8988"""
9089function 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
10191end
10292
10393"""
@@ -107,8 +97,6 @@ Clear all previously profiled allocation information from memory.
10797"""
10898function clear ()
10999 ccall (:jl_free_alloc_profile , Cvoid, ())
110-
111- _g_expected_sampled_allocs[] = 0
112100 return nothing
113101end
114102
@@ -120,25 +108,7 @@ objects which can be analyzed.
120108"""
121109function 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)
142112end
143113
144114# decoded results
0 commit comments