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

stream and then tar heap snapshot #48

Merged
merged 2 commits into from
Jul 19, 2024
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
23 changes: 19 additions & 4 deletions src/ProfileEndpoints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,27 @@ function handle_heap_snapshot(all_one, stage_path = nothing)
else
file_path = joinpath(stage_path, "$(getpid())_$(time_ns()).heapsnapshot")
end
@info "Taking heap snapshot from ProfileEndpoints" all_one file_path
file_path = Profile.take_heap_snapshot(file_path, all_one)
@info "Taking heap snapshot from ProfileEndpoints" all_one
local output_file
@static if isdefined(Profile, :HeapSnapshot) && isdefined(Profile.HeapSnapshot, :assemble_snapshot) && Sys.isunix()
Profile.take_heap_snapshot(file_path, all_one; streaming=true)
# Streaming version of `take_heap_snapshot` returns a bunch of files
# that need to be later assembled...
nodes_file = "$file_path.nodes"
edges_file = "$file_path.edges"
strings_file = "$file_path.strings"
metadata_json_file = "$file_path.metadata.json"
# Tar all of the files together
output_file = "$file_path.tar"
run(`tar -cf $output_file $nodes_file $edges_file $strings_file $metadata_json_file`)
else
Profile.take_heap_snapshot(file_path, all_one)
output_file = file_path
end
if stage_path === nothing
return _http_create_response_with_profile_inlined(read(file_path))
return _http_create_response_with_profile_inlined(read(output_file))
else
return _http_create_response_with_profile_as_file(file_path)
return _http_create_response_with_profile_as_file(output_file)
end
end

Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ const url = "http://127.0.0.1:$port"
req = HTTP.post("$url/debug_engine", headers, payload)
@test req.status == 200
fname = read(IOBuffer(req.body), String)
@static if isdefined(Profile, :HeapSnapshot) && isdefined(Profile.HeapSnapshot, :assemble_snapshot) && Sys.isunix()
# test whether the returned file has a tar extension
@test occursin(".tar", fname)
end
@info "filename: $fname"
@test isfile(fname)
end
Expand Down
Loading