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

rename /profile* to /cpu_profile* #49

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ Julia process to interrogate its performance characteristics.

**CPU Profile**

- `/profile` endpoint to record a CPU profile for a given duration using `Profile.@profile`.
- Default query params: `/profile?n=1e8&delay=0.01&duration=10&pprof=true`
- `/profile_start` to start the CPU profiler (without specifying a duration to run for).
- Default query params: `/profile_start?n=1e8&delay=0.01`
- `/profile_stop` to stop the CPU profiler and return the profile.
- Default query params: `/profile_stop?pprof=true`
- `/cpu_profile` endpoint to record a CPU profile for a given duration using `Profile.@profile`.
- Default query params: `/cpu_profile?n=1e8&delay=0.01&duration=10&pprof=true`
- `/cpu_profile_start` to start the CPU profiler (without specifying a duration to run for).
- Default query params: `/cpu_profile_start?n=1e8&delay=0.01`
- `/cpu_profile_stop` to stop the CPU profiler and return the profile.
- Default query params: `/cpu_profile_stop?pprof=true`

**Allocation Profile**

Expand Down Expand Up @@ -51,7 +51,7 @@ julia> for _ in 1:100 peakflops() end # run stuff to profile (locks up the REPL

Collect a CPU profile:
```bash
$ curl '127.0.0.1:16825/profile?delay=0.01&duration=3' --output prof1.pb.gz
$ curl '127.0.0.1:16825/cpu_profile?delay=0.01&duration=3' --output prof1.pb.gz
```

And view it in PProf:
Expand Down
10 changes: 5 additions & 5 deletions src/ProfileEndpoints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using Serialization: serialize
#----------------------------------------------------------
# Description
#
# It would be nice if visiting the `/profile` page from a web browser gives you a form where you can:
# It would be nice if visiting the `/cpu_profile` page from a web browser gives you a form where you can:
# - configure the Profiling parameters:
# - Set julia Profile configuration, either by:
# - Manually setting `n` and `delay`, for `Profile.init(n, delay)`, or
Expand Down Expand Up @@ -452,9 +452,9 @@ end

function register_endpoints(router; stage_path = nothing)
@info "Registering profiling endpoints"
HTTP.register!(router, "/profile", cpu_profile_endpoint)
HTTP.register!(router, "/profile_start", cpu_profile_start_endpoint)
HTTP.register!(router, "/profile_stop", cpu_profile_stop_endpoint)
HTTP.register!(router, "/cpu_profile", cpu_profile_endpoint)
HTTP.register!(router, "/cpu_profile_start", cpu_profile_start_endpoint)
HTTP.register!(router, "/cpu_profile_stop", cpu_profile_stop_endpoint)
HTTP.register!(router, "/heap_snapshot", heap_snapshot_endpoint)
HTTP.register!(router, "/allocs_profile", allocations_profile_endpoint)
HTTP.register!(router, "/allocs_profile_start", allocations_start_endpoint)
Expand All @@ -473,7 +473,7 @@ function serve_profiling_server(;addr="127.0.0.1", port=16825, verbose=false, st
return HTTP.serve!(router, addr, port; verbose=verbose, kw...)
end

# Precompile the endpoints as much as possible, so that your /profile attempt doesn't end
# Precompile the endpoints as much as possible, so that your /cpu_profile attempt doesn't end
# up profiling compilation!
@static if VERSION < v"1.9" # Before Julia 1.9, precompilation didn't stick if not in __init__
function __init__()
Expand Down
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const url = "http://127.0.0.1:$port"
@testset "profile endpoint" begin
done[] = false
t = workload()
req = HTTP.get("$url/profile?duration=3&pprof=false")
req = HTTP.get("$url/cpu_profile?duration=3&pprof=false")
@test req.status == 200
@test length(req.body) > 0

Expand All @@ -48,13 +48,13 @@ const url = "http://127.0.0.1:$port"
@testset "profile_start/stop endpoints" begin
done[] = false
t = workload()
req = HTTP.get("$url/profile_start")
req = HTTP.get("$url/cpu_profile_start")
@test req.status == 200
@test String(req.body) == "CPU profiling started."

sleep(3) # Allow workload to run a while before we stop profiling.

req = HTTP.get("$url/profile_stop?pprof=false")
req = HTTP.get("$url/cpu_profile_stop?pprof=false")
@test req.status == 200
data, lidict = deserialize(IOBuffer(req.body))
# Test that the profile seems like valid profile data
Expand All @@ -68,7 +68,7 @@ const url = "http://127.0.0.1:$port"
# We retrive data via PProf directly if `pprof=true`; make sure that path's tested.
# This second call to `profile_stop` should still return the profile, even though
# the profiler is already stopped, as it's `profile_start` that calls `clear()`.
req = HTTP.get("$url/profile_stop?pprof=true")
req = HTTP.get("$url/cpu_profile_stop?pprof=true")
@test req.status == 200
# Test that there's something here
# TODO: actually parse the profile
Expand Down Expand Up @@ -294,7 +294,7 @@ const url = "http://127.0.0.1:$port"
end

@testset "error handling" begin
let res = HTTP.get("$url/profile", status_exception=false)
let res = HTTP.get("$url/cpu_profile", status_exception=false)
@test 400 <= res.status < 500
@test res.status != 404
# Make sure we describe how to use the endpoint
Expand Down
Loading