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
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | Context carrying profiling labels or an execution trace task. |
| f | func(key, value string) bool | Visitor 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)}