diff --git a/src/Allocs.jl b/src/Allocs.jl index c8e0f17..bac6a41 100644 --- a/src/Allocs.jl +++ b/src/Allocs.jl @@ -43,7 +43,7 @@ function pprof(alloc_profile::Profile.Allocs.AllocResults = Profile.Allocs.fetch # Allocs-specific arguments: frame_for_type::Bool = true, ) - period = UInt64(0x1) + period = sum(alloc.size for alloc in alloc_profile.allocs, init=0) @assert !isempty(basename(out)) "`out=` must specify a file path to write to. Got unexpected: '$out'" if !endswith(out, ".pb.gz") @@ -72,10 +72,10 @@ function pprof(alloc_profile::Profile.Allocs.AllocResults = Profile.Allocs.fetch samples = Vector{Sample}() sample_type = ValueType[ - ValueType!("allocs", "count"), # Mandatory - ValueType!("size", "bytes") + ValueType!("alloc_objects", "count"), # Mandatory + ValueType!("alloc_space", "bytes") ] - period_type = ValueType!("heap", "bytes") + period_type = ValueType!("alloc_space", "bytes") drop_frames = isnothing(drop_frames) ? 0 : enter!(drop_frames) keep_frames = isnothing(keep_frames) ? 0 : enter!(keep_frames) @@ -136,7 +136,7 @@ function pprof(alloc_profile::Profile.Allocs.AllocResults = Profile.Allocs.fetch push!( locations, - Location(;id = loc_id, line=[Line(function_id, line_number)]) + Location(;id = loc_id, line=[Line(function_id, line_number > 0 ? line_number : 1)]) ) return loc_id diff --git a/src/PProf.jl b/src/PProf.jl index 03b5b15..4822394 100644 --- a/src/PProf.jl +++ b/src/PProf.jl @@ -140,8 +140,8 @@ function pprof(data::Union{Nothing, Vector{UInt}} = nothing, samples = Vector{Sample}() sample_type = [ - ValueType!("events", "count"), # Mandatory - ValueType!("stack_depth", "count") + ValueType!("events", "count"), # Mandatory + ValueType!("cpu", "nanoseconds") ] period_type = ValueType!("cpu", "nanoseconds") @@ -150,7 +150,7 @@ function pprof(data::Union{Nothing, Vector{UInt}} = nothing, # start decoding backtraces location_id = Vector{eltype(data)}() lastwaszero = true - + for ip in data # ip == 0x0 is the sentinel value for finishing a backtrace, therefore finising a sample if ip == 0 @@ -163,7 +163,7 @@ function pprof(data::Union{Nothing, Vector{UInt}} = nothing, # End of sample value = [ 1, # events - length(location_id), # stack_depth + sampling_delay # CPU ns ] push!(samples, Sample(;location_id, value)) location_id = Vector{eltype(data)}() @@ -200,7 +200,8 @@ function pprof(data::Union{Nothing, Vector{UInt}} = nothing, # Use a unique function id for the frame: func_id = method_instance_id(frame) - push!(location.line, Line(function_id = func_id, line = frame.line)) + line_struct = Line(function_id = func_id, line = frame.line > 0 ? frame.line : 1) + push!(location.line, line_struct) # Known function func_id in seen_funcs && continue @@ -216,7 +217,9 @@ function pprof(data::Union{Nothing, Vector{UInt}} = nothing, file = string(meth.file) io = IOBuffer() Base.show_tuple_as_call(io, meth.name, linfo.specTypes) - full_name_with_args = _escape_name_for_pprof(String(take!(io))) + call_str = String(take!(io)) + # add module name as well + full_name_with_args = _escape_name_for_pprof("$(meth.module).$call_str") start_line = convert(Int64, meth.line) else # frame.linfo either nothing or CodeInfo, either way fallback diff --git a/src/flamegraphs.jl b/src/flamegraphs.jl index d4c04cc..29cde76 100644 --- a/src/flamegraphs.jl +++ b/src/flamegraphs.jl @@ -85,6 +85,7 @@ function pprof(fg::Node{NodeData}, sample_type = [ ValueType!("events", "count"), # Mandatory + ValueType!("cpu", "nanoseconds"), ] period_type = ValueType!("cpu", "nanoseconds") @@ -176,7 +177,8 @@ function pprof(fg::Node{NodeData}, end value = [ - length(span), # Number of samples in this frame. + 1, # Number of samples in this frame. + 60000000, # CPU ns (TODO: real number) ] push!(samples, Sample(;location_id, value))