Standard library / runtime/trace

trace.Start()

Enable process-wide execution tracing and stream events to a writer. Only one trace can run at a time. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func Start(w io.Writer) error

Parameters & Attributes

NameTypeDescription
wio.WriterDestination writer; keep it open until profiling or tracing has stopped.

Return Value

error

Error if tracing cannot start; nil on success.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt"  "runtime/trace")
func main() {  var b bytes.Buffer  if err := trace.Start(&b); err != nil {    panic(err)  }  trace.Stop()  fmt.Println(b.Len() > 0)}
Go Reference