Standard library / runtime

runtime.ThreadCreateProfile()

Copy stack records from the thread creation profile; this is not a count of currently live threads. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func ThreadCreateProfile(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.ThreadCreateProfile(nil)  records := make([]runtime.StackRecord, n+64)  n, ok := runtime.ThreadCreateProfile(records)  fmt.Println(ok && n >= 0 && n <= len(records))}
Go Reference