// Copyright 2016 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package pprofimport ()type label struct { key string value string}// LabelSet is a set of labels.typeLabelSetstruct { list []label}// labelContextKey is the type of contextKeys used for profiler labels.type labelContextKey struct{}func labelValue( context.Context) labelMap { , := .Value(labelContextKey{}).(*labelMap)if == nil {returnlabelMap(nil) }return *}// labelMap is the representation of the label set held in the context type.// This is an initial implementation, but it will be replaced with something// that admits incremental immutable modification more efficiently.type labelMap map[string]string// String satisfies Stringer and returns key, value pairs in a consistent// order.func ( *labelMap) () string {if == nil {return"" } := make([]string, 0, len(*))for , := range * { = append(, fmt.Sprintf("%q:%q", , )) }slices.Sort()return"{" + strings.Join(, ", ") + "}"}// WithLabels returns a new [context.Context] with the given labels added.// A label overwrites a prior label with the same key.func ( context.Context, LabelSet) context.Context { := labelValue() := make(labelMap, len())// TODO(matloob): replace the map implementation with something // more efficient so creating a child context WithLabels doesn't need // to clone the map.for , := range { [] = }for , := range .list { [.key] = .value }returncontext.WithValue(, labelContextKey{}, &)}// Labels takes an even number of strings representing key-value pairs// and makes a [LabelSet] containing them.// A label overwrites a prior label with the same key.// Currently only the CPU and goroutine profiles utilize any labels// information.// See https://golang.org/issue/23458 for details.func ( ...string) LabelSet {iflen()%2 != 0 {panic("uneven number of arguments to pprof.Labels") } := make([]label, 0, len()/2)for := 0; +1 < len(); += 2 { = append(, label{key: [], value: [+1]}) }returnLabelSet{list: }}// Label returns the value of the label with the given key on ctx, and a boolean indicating// whether that label exists.func ( context.Context, string) (string, bool) { := labelValue() , := []return , }// ForLabels invokes f with each label set on the context.// The function f should return true to continue iteration or false to stop iteration early.func ( context.Context, func(, string) bool) { := labelValue()for , := range {if !(, ) {break } }}
The pages are generated with Goldsv0.7.0-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.