From 77a8653b98a8edd723a50a577ff3f78c8e96a994 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Thu, 3 Feb 2022 18:24:20 -0500 Subject: [PATCH 1/8] try to make compatible with DD --- src/PProf.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PProf.jl b/src/PProf.jl index 03b5b15..56947c9 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") @@ -163,7 +163,7 @@ function pprof(data::Union{Nothing, Vector{UInt}} = nothing, # End of sample value = [ 1, # events - length(location_id), # stack_depth + 60000000 # CPU ns ] push!(samples, Sample(;location_id, value)) location_id = Vector{eltype(data)}() From 285a9634b695fdf3df0cd495c15fdb648589492a Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Fri, 21 Oct 2022 00:41:48 -0400 Subject: [PATCH 2/8] guard lines from being -1 --- src/PProf.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PProf.jl b/src/PProf.jl index 56947c9..8e56ce1 100644 --- a/src/PProf.jl +++ b/src/PProf.jl @@ -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 From 5795cd4d7a68ff4e2bcf66d3d10af27a3f2a0dc2 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Fri, 21 Oct 2022 01:09:31 -0400 Subject: [PATCH 3/8] allocs: guard against -1 --- src/Allocs.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Allocs.jl b/src/Allocs.jl index c8e0f17..ace96c6 100644 --- a/src/Allocs.jl +++ b/src/Allocs.jl @@ -75,7 +75,7 @@ function pprof(alloc_profile::Profile.Allocs.AllocResults = Profile.Allocs.fetch ValueType!("allocs", "count"), # Mandatory ValueType!("size", "bytes") ] - period_type = ValueType!("heap", "bytes") + period_type = ValueType!("size", "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 From 75cf270931784c70648f90cfe9970e9009b98058 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Fri, 21 Oct 2022 02:27:31 -0400 Subject: [PATCH 4/8] update period --- src/Allocs.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Allocs.jl b/src/Allocs.jl index ace96c6..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!("size", "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) From fbb81b54adcf4f3f349509ba3d885bbedf8e5ad5 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Tue, 25 Oct 2022 04:48:53 +0200 Subject: [PATCH 5/8] add (bogus) CPU time sample time to flamegraph profile --- src/flamegraphs.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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)) From aa0f960c1692c35559ed936251f648e66dc06616 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Fri, 28 Oct 2022 01:35:08 +0200 Subject: [PATCH 6/8] add module name --- src/PProf.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PProf.jl b/src/PProf.jl index 8e56ce1..773c506 100644 --- a/src/PProf.jl +++ b/src/PProf.jl @@ -217,7 +217,8 @@ 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)) + 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 From 785f7c1f5274bd866a9c5de71057a539ba898991 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Fri, 28 Oct 2022 11:29:36 +0200 Subject: [PATCH 7/8] comment --- src/PProf.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PProf.jl b/src/PProf.jl index 773c506..d351f9d 100644 --- a/src/PProf.jl +++ b/src/PProf.jl @@ -218,6 +218,7 @@ function pprof(data::Union{Nothing, Vector{UInt}} = nothing, io = IOBuffer() Base.show_tuple_as_call(io, meth.name, linfo.specTypes) 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 From 0ece3ea9a6d79f8a549467916e3198d2b57cfaaa Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Fri, 28 Oct 2022 12:16:45 +0200 Subject: [PATCH 8/8] use existing sampling_delay_ns variable --- src/PProf.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PProf.jl b/src/PProf.jl index d351f9d..4822394 100644 --- a/src/PProf.jl +++ b/src/PProf.jl @@ -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 - 60000000 # CPU ns + sampling_delay # CPU ns ] push!(samples, Sample(;location_id, value)) location_id = Vector{eltype(data)}()