From bcc0a8b13bf789d10d01aa2f204f421e093374b3 Mon Sep 17 00:00:00 2001 From: Julian P Samaroo Date: Sun, 6 Feb 2022 15:47:11 -0600 Subject: [PATCH 1/3] Profile.Allocs: Add task and timestamp --- src/gc-alloc-profiler.cpp | 6 +++++- stdlib/Profile/src/Allocs.jl | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/gc-alloc-profiler.cpp b/src/gc-alloc-profiler.cpp index d1859aeae4be4..5cf3427ec3ec2 100644 --- a/src/gc-alloc-profiler.cpp +++ b/src/gc-alloc-profiler.cpp @@ -20,6 +20,8 @@ struct jl_raw_alloc_t { jl_datatype_t *type_address; jl_raw_backtrace_t backtrace; size_t size; + jl_task_t *task; + uint64_t timestamp; }; // == These structs define the global singleton profile buffer that will be used by @@ -133,7 +135,9 @@ void _maybe_record_alloc_to_profile(jl_value_t *val, size_t size) JL_NOTSAFEPOIN profile.allocs.emplace_back(jl_raw_alloc_t{ type, get_raw_backtrace(), - size + size, + jl_current_task, + cycleclock() }); } diff --git a/stdlib/Profile/src/Allocs.jl b/stdlib/Profile/src/Allocs.jl index fae6a686b824c..9cab99d21ede4 100644 --- a/stdlib/Profile/src/Allocs.jl +++ b/stdlib/Profile/src/Allocs.jl @@ -19,6 +19,8 @@ struct RawAlloc type::Ptr{Type} backtrace::RawBacktrace size::Csize_t + task::Task + timestamp::UInt64 end # matches jl_profile_allocs_raw_results_t on the C side @@ -147,6 +149,8 @@ struct Alloc type::Any stacktrace::StackTrace size::Int + task::Task + timestamp::UInt64 end struct AllocResults @@ -156,7 +160,7 @@ end # Without this, the Alloc's stacktrace prints for lines and lines and lines... function Base.show(io::IO, a::Alloc) stacktrace_sample = length(a.stacktrace) >= 1 ? "$(a.stacktrace[1]), ..." : "" - print(io, "$Alloc($(a.type), $StackFrame[$stacktrace_sample], $(a.size))") + print(io, "$Alloc($(a.type), $StackFrame[$stacktrace_sample], $(a.size), $(a.task), $(a.timestamp))") end const BacktraceCache = Dict{BTElement,Vector{StackFrame}} @@ -180,7 +184,9 @@ function decode_alloc(cache::BacktraceCache, raw_alloc::RawAlloc)::Alloc Alloc( load_type(raw_alloc.type), stacktrace_memoized(cache, load_backtrace(raw_alloc.backtrace)), - UInt(raw_alloc.size) + UInt(raw_alloc.size), + raw_alloc.task, + raw_alloc.timestamp ) end From a9d7428e2b0c4a5eb19c03ffeafa85ab43cd7a68 Mon Sep 17 00:00:00 2001 From: Julian P Samaroo Date: Sun, 6 Feb 2022 17:48:45 -0600 Subject: [PATCH 2/3] fixup! Profile.Allocs: Add task and timestamp --- stdlib/Profile/src/Allocs.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/Profile/src/Allocs.jl b/stdlib/Profile/src/Allocs.jl index 9cab99d21ede4..1e54ff2d77f13 100644 --- a/stdlib/Profile/src/Allocs.jl +++ b/stdlib/Profile/src/Allocs.jl @@ -19,7 +19,7 @@ struct RawAlloc type::Ptr{Type} backtrace::RawBacktrace size::Csize_t - task::Task + task::Ptr{Cvoid} timestamp::UInt64 end @@ -149,7 +149,7 @@ struct Alloc type::Any stacktrace::StackTrace size::Int - task::Task + task::Ptr{Cvoid} timestamp::UInt64 end From a5597d47ede1646ae4ebb3c98433758aa9de31e2 Mon Sep 17 00:00:00 2001 From: Julian P Samaroo Date: Sun, 6 Feb 2022 18:48:29 -0600 Subject: [PATCH 3/3] fixup! Profile.Allocs: Add task and timestamp --- stdlib/Profile/src/Allocs.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/Profile/src/Allocs.jl b/stdlib/Profile/src/Allocs.jl index 1e54ff2d77f13..2b903687c807b 100644 --- a/stdlib/Profile/src/Allocs.jl +++ b/stdlib/Profile/src/Allocs.jl @@ -160,7 +160,7 @@ end # Without this, the Alloc's stacktrace prints for lines and lines and lines... function Base.show(io::IO, a::Alloc) stacktrace_sample = length(a.stacktrace) >= 1 ? "$(a.stacktrace[1]), ..." : "" - print(io, "$Alloc($(a.type), $StackFrame[$stacktrace_sample], $(a.size), $(a.task), $(a.timestamp))") + print(io, "$Alloc($(a.type), $StackFrame[$stacktrace_sample], $(a.size))") end const BacktraceCache = Dict{BTElement,Vector{StackFrame}}