Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alloc profile performance improvements #6

Merged
merged 4 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/gc-alloc-profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ CombinedResults g_combined_results; // will live forever
// === stack stuff ===

RawBacktrace get_raw_backtrace() {
jl_bt_element_t *bt_data = (jl_bt_element_t*) malloc(JL_MAX_BT_SIZE);
static jl_bt_element_t static_bt_data[JL_MAX_BT_SIZE];

// TODO: tune the number of frames that are skipped
size_t bt_size = rec_backtrace(bt_data, JL_MAX_BT_SIZE, 1);
size_t bt_size = rec_backtrace(static_bt_data, JL_MAX_BT_SIZE, 1);

size_t bt_bytes = bt_size * sizeof(jl_bt_element_t);
jl_bt_element_t *bt_data = (jl_bt_element_t*) malloc(bt_bytes);
memcpy(bt_data, static_bt_data, bt_bytes);

return RawBacktrace{
bt_data,
Expand Down
27 changes: 17 additions & 10 deletions stdlib/AllocProfile/src/AllocProfile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,36 +100,29 @@ end

function decode(raw_results::RawAllocResults)::AllocResults
cache = BacktraceCache()
@info "ALLOCS"
allocs = [
decode_alloc(cache, unsafe_load(raw_results.allocs, i))
for i in 1:raw_results.num_allocs
]

@info "FREES"
frees = Dict{Type,UInt}()
for i in 1:raw_results.num_frees
free = unsafe_load(raw_results.frees, i)
type = load_type(free.type)
frees[type] = free.count
end

return AllocResults(
allocs,
frees
)
end

const f = Ref{IOStream}()

function __init__()
f[] = open("debug.log", "w")
end

function load_backtrace(trace::RawBacktrace)::Vector{Ptr{Cvoid}}
println(f[], "load_backtrace: trace.data: $(trace.data)")
println(f[], "load_backtrace: trace.size: $(trace.size)")
out = Vector{Ptr{Cvoid}}()
for i in 1:trace.size
println(f[], " $i")
push!(out, unsafe_load(trace.data, i))
end

Expand Down Expand Up @@ -158,4 +151,18 @@ function stacktrace_memoized(
return stack
end

# Precompile once for the package cache,
precompile(start, ())
precompile(stop, ())

function __init__()
# And once when loading the package, to get the full machine code precompiled.
# TOOD: Although actually, we probably don't need this since this package will be
# precompiled into the sysimg, so the top-level statements will be enough to get the
# machine code codegen precompiled as well. :)
# We can delete this function once we make this package a stdlib.
precompile(start, ())
precompile(stop, ())
end

end