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

NameTypeDescription
ctxcontext.ContextContext carrying profiling labels or an execution trace task.
labelsLabelSetLabel set to associate with the context or operation.
ffunc(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) })}
Go Reference