5454
5555# globals used for tracking how many allocs we're missing
5656# 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 )
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 )
6060
6161function _prof_expr (expr, opts)
6262 quote
@@ -76,8 +76,8 @@ A sample rate of 1.0 will record everything; 0.0 will record nothing.
7676function start (; sample_rate:: Real )
7777 ccall (:jl_start_alloc_profile , Cvoid, (Cdouble,), Float64 (sample_rate))
7878
79- g_sample_rate [] = sample_rate
80- g_gc_num_before [] = Base. gc_num ()
79+ _g_sample_rate [] = sample_rate
80+ _g_gc_num_before [] = Base. gc_num ()
8181end
8282
8383"""
@@ -92,10 +92,10 @@ function stop()
9292 # the memory profiler to see, based on how many allocs
9393 # actually happened.
9494 gc_num_after = Base. gc_num ()
95- gc_diff = Base. GC_Diff (gc_num_after, g_gc_num_before [])
95+ gc_diff = Base. GC_Diff (gc_num_after, _g_gc_num_before [])
9696 alloc_count = Base. gc_alloc_count (gc_diff)
97- expected_samples = alloc_count * g_sample_rate []
98- g_expected_sampled_allocs [] += expected_samples
97+ expected_samples = alloc_count * _g_sample_rate []
98+ _g_expected_sampled_allocs [] += expected_samples
9999end
100100
101101"""
@@ -106,7 +106,7 @@ Clear all previously profiled allocation information from memory.
106106function clear ()
107107 ccall (:jl_free_alloc_profile , Cvoid, ())
108108
109- g_expected_sampled_allocs [] = 0
109+ _g_expected_sampled_allocs [] = 0
110110end
111111
112112"""
@@ -120,12 +120,12 @@ function fetch()
120120 decoded_results = decode (raw_results)
121121
122122 @show (length (decoded_results. allocs))
123- @show (g_expected_sampled_allocs [])
123+ @show (_g_expected_sampled_allocs [])
124124
125- missed_allocs = g_expected_sampled_allocs [] - length (decoded_results. allocs)
126- missed_percentage = round (Int, missed_allocs / g_expected_sampled_allocs [] * 100 )
125+ missed_allocs = _g_expected_sampled_allocs [] - length (decoded_results. allocs)
126+ missed_percentage = round (Int, missed_allocs / _g_expected_sampled_allocs [] * 100 )
127127 @warn (" The allocation profiler is not fully implemented, and missed $(missed_percentage) % " *
128- " ($(round (Int, missed_allocs)) / $(round (Int, g_expected_sampled_allocs [])) ) " *
128+ " ($(round (Int, missed_allocs)) / $(round (Int, _g_expected_sampled_allocs [])) ) " *
129129 " of allocs in the last run. " *
130130 " For more info see https://github.com/JuliaLang/julia/issues/43688" )
131131 return decoded_results
0 commit comments