Skip to content

Commit ca47d76

Browse files
committed
runtime: improve SetBlockProfileRate documentation
The current description of the rate parameter is a bit cryptic and possibly not accurate. It's replaced with a more verbose and explicit description of the sampling process. Additionally a bias in the sampling for rate > 1 is pointed out. Partially fixes golang#14689.
1 parent 0f66fb7 commit ca47d76

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/runtime/mprof.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,13 @@ func mProf_Free(b *bucket, size uintptr) {
371371

372372
var blockprofilerate uint64 // in CPU ticks
373373

374-
// SetBlockProfileRate controls the fraction of goroutine blocking events
375-
// that are reported in the blocking profile. The profiler aims to sample
376-
// an average of one blocking event per rate nanoseconds spent blocked.
377-
//
378-
// To include every blocking event in the profile, pass rate = 1.
379-
// To turn off profiling entirely, pass rate <= 0.
374+
// SetBlockProfileRate controls the fraction of goroutine blocking events that
375+
// are reported in the blocking profile. A rate <= 0 (default) turns off block
376+
// profiling. If the rate is 1, every blocking event is captured. A rate > 1
377+
// specifies the sampling threshold in nanoseconds and captures every blocking
378+
// event with a duration >= rate as well as a duration/rate fraction of
379+
// randomly chosen events with a duration < rate. Block profiles are biased
380+
// towards events with a duration > rate as a result of this sampling.
380381
func SetBlockProfileRate(rate int) {
381382
var r int64
382383
if rate <= 0 {

0 commit comments

Comments
 (0)