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 profiler: fetch-based API #9

Merged
merged 1 commit into from
Jan 6, 2022
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
19 changes: 11 additions & 8 deletions src/gc-alloc-profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,17 @@ JL_DLLEXPORT void jl_start_alloc_profile(int skip_every) {

extern "C" { // Needed since the function doesn't take any arguments.

JL_DLLEXPORT struct RawAllocResults jl_stop_alloc_profile() {
JL_DLLEXPORT struct RawAllocResults jl_fetch_alloc_profile() {
// TODO: check that the results exist
return RawAllocResults{
g_combined_results.combined_allocs.data(),
g_combined_results.combined_allocs.size(),
g_combined_results.combined_frees.data(),
g_combined_results.combined_frees.size()
};
}

JL_DLLEXPORT void jl_stop_alloc_profile() {
g_alloc_profile_enabled = false;

// combine allocs
Expand All @@ -101,13 +111,6 @@ JL_DLLEXPORT struct RawAllocResults jl_stop_alloc_profile() {
});
}
}

return RawAllocResults{
g_combined_results.combined_allocs.data(),
g_combined_results.combined_allocs.size(),
g_combined_results.combined_frees.data(),
g_combined_results.combined_frees.size()
};
}

JL_DLLEXPORT void jl_free_alloc_profile() {
Expand Down
3 changes: 2 additions & 1 deletion src/gc-alloc-profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ struct RawAllocResults {
};

JL_DLLEXPORT void jl_start_alloc_profile(int skip_every);
JL_DLLEXPORT struct RawAllocResults jl_stop_alloc_profile(void);
JL_DLLEXPORT struct RawAllocResults jl_fetch_alloc_profile(void);
JL_DLLEXPORT void jl_stop_alloc_profile(void);
JL_DLLEXPORT void jl_free_alloc_profile(void);

void _record_allocated_value(jl_value_t *val, size_t size) JL_NOTSAFEPOINT;
Expand Down
15 changes: 9 additions & 6 deletions stdlib/Profile/src/Allocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ function _prof_expr(expr, opts)
quote
$start(; $(esc(opts)))
local res = $(esc(expr))
local profile = $stop()
$clear()
(res, profile)
$stop()
res
end
end

Expand All @@ -60,15 +59,19 @@ function start(; skip_every::Int)
end

function stop()
raw_results = ccall(:jl_stop_alloc_profile, RawAllocResults, ())
decoded_results = decode(raw_results)
return decoded_results
ccall(:jl_stop_alloc_profile, RawAllocResults, ())
end

function clear()
ccall(:jl_free_alloc_profile, Cvoid, ())
end

function fetch()
raw_results = ccall(:jl_fetch_alloc_profile, RawAllocResults, ())
decoded_results = decode(raw_results)
return decoded_results
end

# decoded results

struct Alloc
Expand Down