diff --git a/src/gc-alloc-profiler.cpp b/src/gc-alloc-profiler.cpp index 1497bc7ff3ed5..8d60124adcf9f 100644 --- a/src/gc-alloc-profiler.cpp +++ b/src/gc-alloc-profiler.cpp @@ -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, diff --git a/stdlib/AllocProfile/src/AllocProfile.jl b/stdlib/AllocProfile/src/AllocProfile.jl index 3a5e74eca8f8f..da31d99ee28d6 100644 --- a/stdlib/AllocProfile/src/AllocProfile.jl +++ b/stdlib/AllocProfile/src/AllocProfile.jl @@ -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 @@ -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