Skip to content

Commit aa71d23

Browse files
authored
Merge pull request #6 from vilterp/nhd-alloc-profile-performance
Alloc profile performance improvements
2 parents 3718e2e + cae4480 commit aa71d23

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/gc-alloc-profiler.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@ CombinedResults g_combined_results; // will live forever
5353
// === stack stuff ===
5454

5555
RawBacktrace get_raw_backtrace() {
56-
jl_bt_element_t *bt_data = (jl_bt_element_t*) malloc(JL_MAX_BT_SIZE);
56+
static jl_bt_element_t static_bt_data[JL_MAX_BT_SIZE];
5757

5858
// TODO: tune the number of frames that are skipped
59-
size_t bt_size = rec_backtrace(bt_data, JL_MAX_BT_SIZE, 1);
59+
size_t bt_size = rec_backtrace(static_bt_data, JL_MAX_BT_SIZE, 1);
60+
61+
size_t bt_bytes = bt_size * sizeof(jl_bt_element_t);
62+
jl_bt_element_t *bt_data = (jl_bt_element_t*) malloc(bt_bytes);
63+
memcpy(bt_data, static_bt_data, bt_bytes);
6064

6165
return RawBacktrace{
6266
bt_data,

stdlib/AllocProfile/src/AllocProfile.jl

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,36 +100,29 @@ end
100100

101101
function decode(raw_results::RawAllocResults)::AllocResults
102102
cache = BacktraceCache()
103+
@info "ALLOCS"
103104
allocs = [
104105
decode_alloc(cache, unsafe_load(raw_results.allocs, i))
105106
for i in 1:raw_results.num_allocs
106107
]
107108

109+
@info "FREES"
108110
frees = Dict{Type,UInt}()
109111
for i in 1:raw_results.num_frees
110112
free = unsafe_load(raw_results.frees, i)
111113
type = load_type(free.type)
112114
frees[type] = free.count
113115
end
114-
116+
115117
return AllocResults(
116118
allocs,
117119
frees
118120
)
119121
end
120122

121-
const f = Ref{IOStream}()
122-
123-
function __init__()
124-
f[] = open("debug.log", "w")
125-
end
126-
127123
function load_backtrace(trace::RawBacktrace)::Vector{Ptr{Cvoid}}
128-
println(f[], "load_backtrace: trace.data: $(trace.data)")
129-
println(f[], "load_backtrace: trace.size: $(trace.size)")
130124
out = Vector{Ptr{Cvoid}}()
131125
for i in 1:trace.size
132-
println(f[], " $i")
133126
push!(out, unsafe_load(trace.data, i))
134127
end
135128

@@ -158,4 +151,18 @@ function stacktrace_memoized(
158151
return stack
159152
end
160153

154+
# Precompile once for the package cache,
155+
precompile(start, ())
156+
precompile(stop, ())
157+
158+
function __init__()
159+
# And once when loading the package, to get the full machine code precompiled.
160+
# TOOD: Although actually, we probably don't need this since this package will be
161+
# precompiled into the sysimg, so the top-level statements will be enough to get the
162+
# machine code codegen precompiled as well. :)
163+
# We can delete this function once we make this package a stdlib.
164+
precompile(start, ())
165+
precompile(stop, ())
166+
end
167+
161168
end

0 commit comments

Comments
 (0)