Standard library / runtime

runtime.ReadTrace()

Read the next runtime-owned binary chunk. Copy it before the next read, call from only one goroutine at a time, and drain through nil. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func ReadTrace() []byte

Return Value

[]byte

Next runtime-owned trace chunk, or nil after draining a stopped trace.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt"  "runtime")
func main() {  if err := runtime.StartTrace(); err != nil {    panic(err)  }  done := make(chan int, 1)  go func() {    var b bytes.Buffer    for {      data := runtime.ReadTrace()      if data == nil {        break      }      b.Write(data)    }    done <- b.Len()  }()  runtime.Gosched()  runtime.StopTrace()  fmt.Println(<-done > 0)}
Go Reference