Standard library / runtime/pprof
pprof.Do()
Run a callback with merged labels and set the current goroutine labels for its duration; restore the prior labels afterward. Expected stdout: 'parse\n'.
Formal Syntax & Structure
go syntaxgo
func Do(ctx context.Context, labels LabelSet, f func(context.Context))Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | Context carrying profiling labels or an execution trace task. |
| labels | LabelSet | Label set to associate with the context or operation. |
| f | func(context.Context) | Callback executed with the labeled context and matching goroutine labels. |
Working Example
Example Snippetgo
package main
import ( "context" "fmt" "runtime/pprof")
func main() { pprof.Do(context.Background(), pprof.Labels("phase", "parse"), func(c context.Context) { v, _ := pprof.Label(c, "phase"); fmt.Println(v) })}