Skip to content
Merged
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
66 changes: 54 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
# PerformanceProfilingHttpEndpoints

Provides HTTP endpoints (and an optional an HTTP server) that wrap the profiling
Provides HTTP endpoints (and an optional HTTP server) that wrap the profiling
functionality exposed from existing Julia packages, to allow introspecting a live-running
julia process to interrogate its performance characteristics.
Julia process to interrogate its performance characteristics.

Currently provides:
- `/profile` endpoint, with default query params:
- `/profile?n=1e8&delay=0.01&duration=10&pprof=true`
- `/allocs_profile` endpoint, with default query params:
- `/allocs_profile?sample_rate=0.0001&duration=10`
- `/heap_snapshot` endpoint, with default query params:
- `/heap_snapshot?all_one=false`
## Endpoints

**CPU Profile**

## Example
- `/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`

**Allocation Profile**

- `/allocs_profile` endpoint to record an allocations profile for a given duration using `Profile.Allocs.@profile`.
- Default query params: `/allocs_profile?sample_rate=0.0001&duration=10`
- `/allocs_profile_start` to start the allocation profiler (without specifying a duration to run for).
- Default query params: `/allocs_profile_start?sample_rate=0.0001`
- `/allocs_profile_stop` to stop the allocation profiler and return the profile.
- Takes no query params.

**Heap Snapshot**

- `/heap_snapshot` endpoint to take a heap snapshot with `Profile.take_heap_snapshot`.
- Default query params: `/heap_snapshot?all_one=false`

## Examples

Start the server on your production process
```julia
Expand All @@ -27,9 +43,11 @@ Task (runnable) @0x0000000113c8d660
julia> for _ in 1:100 peakflops() end # run stuff to profile (locks up the REPL)
```

Then collect a profile:
### CPU Profile

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

And view it in PProf:
Expand All @@ -38,3 +56,27 @@ julia> using PProf

julia> PProf.refresh(file="./prof1.pb.gz")
```

### Allocation Profile

Collect an allocation profile (requires Julia v1.8+):
```bash
$ curl '127.0.0.1:16825/allocs_profile?sample_rate=0.0001&duration=3' --output allocs_prof1.pb.gz
```

And view it in PProf:
```julia
julia> using PProf

julia> PProf.refresh(file="./allocs_prof1.pb.gz")
```

### Heap Snapshot

Take a heap snapshot (requires Julia v1.9+):
```bash
$ curl '127.0.0.1:16825/heap_snapshot?all_one=false' --output prof1.heapsnapshot
```

And upload it in the [Chrome DevTools snapshot viewer](https://developer.chrome.com/docs/devtools/memory-problems/heap-snapshots/#view_snapshots) to explore the heap.
In Chrome `View > Developer > Developer Tools`, select the `Memory` tab, and press the `Load` button to upload the file.