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) *RegionParameters & Attributes
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | Context carrying profiling labels or an execution trace task. |
| regionType | string | Low-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)}