Standard library / runtime/pprof

pprof.ForLabels()

Visit context labels in unspecified order; returning false stops traversal. Expected stdout: '1\n'.

Formal Syntax & Structure

go syntaxgo
func ForLabels(ctx context.Context, f func(key, value string) bool)

Parameters & Attributes

NameTypeDescription
ctxcontext.ContextContext carrying profiling labels or an execution trace task.
ffunc(key, value string) boolVisitor returning false to stop iteration; order is unspecified.

Working Example

Example Snippetgo
package main
import (  "context"  "fmt"  "runtime/pprof")
func main() {  c := pprof.WithLabels(context.Background(), pprof.Labels("a", "1", "b", "2"))  n := 0  pprof.ForLabels(c, func(k, v string) bool { n++; return false })  fmt.Println(n)}
Go Reference