Skip to content

Commit ba334f1

Browse files
authored
pprof allow to override sampling rate (#27)
Allow to set the `rate` to allow to override the default 100 Hz sampling rate: ``` curl --output sample.pprof -v "http://127.0.0.1:12345/debug/pprof/profile?seconds=10&rate=10" ```
1 parent 8b4023f commit ba334f1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Sources/ProfileRecorderServer/Server.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ public struct ProfileRecorderServer: Sendable {
498498
499499
How to use it?
500500
501-
1. Open https://profiler.firefox.com and drag /tmp/samples.svg onto it.
501+
1. Open https://profiler.firefox.com and drag /tmp/samples.perf onto it.
502502
2. Click "Show all tracks" in "tracks" menu on the top left
503503
3. Slightly further down, select the first thread (track), hold Shift and select the last thread.
504504
4. Open the "Flame Graph" tab
@@ -562,7 +562,8 @@ public struct ProfileRecorderServer: Sendable {
562562
decodedURI.queryParams["symbolizer"].flatMap { kind in
563563
ProfileRecorderSymbolizerKind(rawValue: kind ?? "n/a")
564564
} ?? (decodedURI.components.contains("symbolizer=fake") ? .fake : .native)
565-
let sampleRate = 100.clamping(to: 0...1000) // 100 Hz, seems to be Golang's default
565+
let sampleRate = (Int(decodedURI.queryParams["rate"].flatMap { $0 } ?? "not set") ?? 100)
566+
.clamping(to: 0...1000) // 100 Hz, seems to be Golang's default
566567
let numberOfSamples = seconds * sampleRate
567568
let timeIntervalBetweenSamplesMS = (1000 / sampleRate).clamping(to: 1...100_000)
568569

0 commit comments

Comments
 (0)