Skip to content

Commit

Permalink
add a branch in the debug super-endpoint to remove profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
d-netto committed Jun 7, 2024
1 parent ffd6913 commit a001953
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/ProfileEndpoints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ function handle_task_backtraces(stage_path = nothing)
else
backtrace_file = tempname(stage_path; cleanup=false)
end
backtrace_file *= ".task_backtraces"
open(backtrace_file, "w") do io
redirect_stderr(io) do
ccall(:jl_print_task_backtraces, Cvoid, ())
Expand All @@ -315,6 +316,26 @@ function handle_task_backtraces(stage_path = nothing)
return HTTP.Response(200, backtrace_file)
end

###
### Profile removal
###

function has_profile_extension(file)
return endswith(file, ".profile") || endswith(file, ".pb.gz") || endswith(file, ".task_backtraces")
end

function handle_profile_removal(stage_path = nothing)
if stage_path !== nothing
# Remove all files in the stage path
for file in readdir(stage_path)
if isfile(joinpath(stage_path, file)) && has_profile_extension(file)
rm(joinpath(stage_path, file))
end
end
end
return HTTP.Response(200, "All profiles removed")
end

###
### Debug super-endpoint
###
Expand Down Expand Up @@ -358,6 +379,8 @@ function debug_profile_endpoint_with_stage_path(stage_path = nothing)
)
elseif profile_type == "task_backtraces"
return handle_task_backtraces(stage_path)
elseif profile_type == "remove_all_profiles"
return handle_profile_removal(stage_path)
else
return HTTP.Response(400, "Unknown profile_type: $profile_type")
end
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ const url = "http://127.0.0.1:$port"
@test isfile(fname)
end
end

@testset "Debug endpoint profile removal" begin
headers = ["Content-Type" => "application/json"]
payload = JSON3.write(Dict("profile_type" => "remove_all_profiles"))
req = HTTP.post("$url/debug_engine", headers, payload)
@test req.status == 200
end
end

@testset "Heap snapshot $query" for query in ("", "?all_one=true")
Expand Down

0 comments on commit a001953

Please sign in to comment.