diff --git a/src/ProfileEndpoints.jl b/src/ProfileEndpoints.jl index 0d111be..91c9fff 100644 --- a/src/ProfileEndpoints.jl +++ b/src/ProfileEndpoints.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index a33e5b1..109e357 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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