Standard library / runtime

runtime.GoroutineProfile()

Copy stack records of current goroutines. The goroutine count can change while allocating the destination. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func GoroutineProfile(p []StackRecord) (n int, ok bool)

Parameters & Attributes

NameTypeDescription
p[]StackRecordDestination slice of profile records; if too small, allocate using the returned count and retry.

Return Value

(n int, ok bool)

Number of required records and whether the supplied slice was large enough to copy them.

Working Example

Example Snippetgo
package main
import (  "fmt"  "runtime")
func main() {  n, _ := runtime.GoroutineProfile(nil)  records := make([]runtime.StackRecord, n+64)  n, ok := runtime.GoroutineProfile(records)  fmt.Println(ok && n >= 0 && n <= len(records))}
Go Reference