Skip to content

Commit e9eb2be

Browse files
prattmicgopherbot
authored andcommitted
runtime/pprof: document block and mutex profiles
Amazingly, we seem to have nearly no in-tree documentation on the semantics of block and mutex profiles. Add brief summaries, including the new behavior from CL 506415 and CL 544195. For #14689. For #44920. For #57071. For #61015. Change-Id: I1a6edce7c434fcb43f17c83eb362b1f9d1a32df1 Reviewed-on: https://go-review.googlesource.com/c/go/+/547057 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Rhys Hiltner <[email protected]> Auto-Submit: Michael Pratt <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent 71fc9d4 commit e9eb2be

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/runtime/pprof/pprof.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,31 @@ import (
126126
// pprof display to -alloc_space, the total number of bytes allocated since
127127
// the program began (including garbage-collected bytes).
128128
//
129+
// The block profile tracks time spent blocked on synchronization primitives,
130+
// such as [sync.Mutex], [sync.RWMutex], [sync.WaitGroup], [sync.Cond], and
131+
// channel send/receive/select. Stack traces correspond to the location that
132+
// blocked (for example, [sync.Mutex.Lock]). Sample values correspond to
133+
// cumulative time spent blocked at that stack trace, subject to time-based
134+
// sampling specified by [runtime.SetBlockProfileRate].
135+
//
136+
// The mutex profile tracks contention on mutexes, such as [sync.Mutex],
137+
// [sync.RWMutex], and runtime-internal locks. Stack traces correspond to the
138+
// end of the critical section causing contention. For example, a lock held for
139+
// a long time while other goroutines are waiting to acquire the lock will
140+
// report contention when the lock is finally unlocked (that is, at
141+
// [sync.Mutex.Unlock]). Sample values correspond to the approximate cumulative
142+
// time other goroutines spent blocked waiting for the lock, subject to
143+
// event-based sampling specified by [runtime.SetMutexProfileFraction]. For
144+
// example, if a caller holds a lock for 1s while 5 other goroutines are
145+
// waiting for the entire second to acquire the lock, its unlock call stack
146+
// will report 5s of contention.
147+
//
148+
// In the mutex profile, runtime-internal locks are always reported at the
149+
// location "runtime._LostContendedRuntimeLock". More detailed stack traces for
150+
// runtime-internal locks can be obtained by setting
151+
// `GODEBUG=runtimecontentionstacks=1` (see package [runtime] docs for
152+
// caveats).
153+
//
129154
// The CPU profile is not available as a Profile. It has a special API,
130155
// the [StartCPUProfile] and [StopCPUProfile] functions, because it streams
131156
// output to a writer during profiling.

0 commit comments

Comments
 (0)