Standard library / runtime

runtime.StartTrace()

Low-level trace startup; prefer runtime/trace.Start. A reader goroutine must drain the trace while StopTrace runs. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func StartTrace() error

Return Value

error

Error if tracing is already enabled, otherwise nil.

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