Profile until buffer is full

function busy(n)
    a = 0.0
    for i = 1:n
        a += sin(i)
        a += cos(a)
    end
    a
end

import Profile
Profile.init(; n=5000, delay=0.001)
Profile.@profile busy(10^7)
Profile.fetch()

shows that the buffer got full during profiling.

Is there a way to run e.g. Profile.@profile busy(10^8) but only until the profile buffer is full?

I’ve added is_buffer_full().
https://github.com/JuliaLang/julia/blob/f806df603489cfca558f6284d52a38f523b81881/stdlib/Profile/src/Profile.jl#L356

However, as you can imagine, if you embed the check (inside the loop), it becomes noise.

I do not understand the purpose, but I think it is better to simply set a timeout.