From 2bf807683f41853463d2dd29fb9ab0b9370e7a6d Mon Sep 17 00:00:00 2001 From: d-netto Date: Fri, 28 Jun 2024 11:53:01 -0300 Subject: [PATCH 1/2] stream and then tar heap snapshot --- src/ProfileEndpoints.jl | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) 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 From 6b36a358d3d23f3078641b5a047d0e538d0af8f0 Mon Sep 17 00:00:00 2001 From: d-netto Date: Fri, 19 Jul 2024 11:05:05 -0300 Subject: [PATCH 2/2] suggestion from Nathan's review: test for .tar extension --- test/runtests.jl | 4 ++++ 1 file changed, 4 insertions(+) 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