Standard library / runtime

runtime.SetMutexProfileFraction()

Configure contention sampling. Negative queries, zero disables, positive samples approximately one in rate events. Restore the original setting. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func SetMutexProfileFraction(rate int) int

Parameters & Attributes

NameTypeDescription
rateintOn average one in rate contention events; 0 disables, negative queries.

Return Value

int

Previous mutex sampling fraction.

Working Example

Example Snippetgo
package main
import (  "fmt"  "runtime")
func main() {  old := runtime.SetMutexProfileFraction(1)  defer runtime.SetMutexProfileFraction(old)  fmt.Println(runtime.SetMutexProfileFraction(-1) == 1)}
Go Reference