1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
# This file is a part of Julia. License is MIT: https://julialang.org/license
using Test, Profile, Serialization
function busywait(t, n_tries)
iter = 0
while iter < n_tries && Profile.len_data() == 0
iter += 1
tend = time() + t
while time() < tend end
end
end
Profile.clear()
@profile busywait(1, 20)
let r = Profile.retrieve()
mktemp() do path, io
serialize(io, r)
close(io)
open(path) do io
@test isa(deserialize(io), Tuple{Vector{UInt},Dict{UInt64,Vector{Base.StackTraces.StackFrame}}})
end
end
end
let iobuf = IOBuffer()
Profile.print(iobuf, format=:tree, C=true)
str = String(take!(iobuf))
@test !isempty(str)
truncate(iobuf, 0)
Profile.print(iobuf, format=:tree, maxdepth=2)
str = String(take!(iobuf))
@test !isempty(str)
truncate(iobuf, 0)
Profile.print(iobuf, format=:flat, C=true)
str = String(take!(iobuf))
@test !isempty(str)
truncate(iobuf, 0)
Profile.print(iobuf)
@test !isempty(String(take!(iobuf)))
truncate(iobuf, 0)
Profile.print(iobuf, format=:flat, sortedby=:count)
@test !isempty(String(take!(iobuf)))
Profile.clear()
@test isempty(Profile.fetch())
@test Profile.callers("\\") !== nothing
@test Profile.callers(\) !== nothing
end
# issue #13229
module I13229
using Test, Profile
global z = 0
@timed @profile for i = 1:5
function f(x)
return x + i
end
global z = f(i)
end
@test z == 10
end
|