Standard library / runtime/trace

trace.StartRegion()

Begin a region in the current goroutine, optionally attached to a task. End it on the same goroutine. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func StartRegion(ctx context.Context, regionType string) *Region

Parameters & Attributes

NameTypeDescription
ctxcontext.ContextContext carrying profiling labels or an execution trace task.
regionTypestringLow-cardinality name for the traced region type.

Return Value

*Region

Region handle to end on the same goroutine.

Working Example

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