diff options
| author | David Finkel <davidf@vimeo.com> | 2025-05-23 16:04:08 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-11-24 20:07:56 -0800 |
| commit | 6851795fb6cda61e2c8396c36da187a2bd87b29e (patch) | |
| tree | 26c06ff565a5e5910dfce7b28f180023b8699feb /src/internal/runtime | |
| parent | 0921e1db83d3e67032999b5a2f54f5ede8ba39b5 (diff) | |
| download | go-6851795fb6cda61e2c8396c36da187a2bd87b29e.tar.xz | |
runtime: add GODEBUG=tracebacklabels=1 to include pprof labels in tracebacks
Copy LabelSet to an internal package as label.Set, and include (escaped)
labels within goroutine stack dumps.
Labels are added to the goroutine header as quoted key:value pairs, so
the line may get long if there are a lot of labels.
To handle escaping, we add a printescaped function to the
runtime and hook it up to the print function in the compiler with a new
runtime.quoted type that's a sibling to runtime.hex. (in fact, we
leverage some of the machinery from printhex to generate escape
sequences).
The escaping can be improved for printable runes outside basic ASCII
(particularly for languages using non-latin stripts). Additionally,
invalid UTF-8 can be improved.
So we can experiment with the output format make this opt-in via a
a new tracebacklabels GODEBUG var.
Updates #23458
Updates #76349
Change-Id: I08e78a40c55839a809236fff593ef2090c13c036
Reviewed-on: https://go-review.googlesource.com/c/go/+/694119
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/internal/runtime')
| -rw-r--r-- | src/internal/runtime/pprof/label/labelset.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/internal/runtime/pprof/label/labelset.go b/src/internal/runtime/pprof/label/labelset.go new file mode 100644 index 0000000000..d3046d407c --- /dev/null +++ b/src/internal/runtime/pprof/label/labelset.go @@ -0,0 +1,25 @@ +// Copyright 2025 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 label provides common declarations used by both the [runtime] and [runtime/pprof] packages. +// The [Set] type is used for goroutine labels, and is duplicated as +// [runtime/pprof.LabelSet]. The type is duplicated due to go.dev/issue/65437 +// preventing the use of a type-alias in an existing public interface. +package label + +// Label is a key/value pair of strings. +type Label struct { + Key string + Value string +} + +// Set is a set of labels. +type Set struct { + List []Label +} + +// NewSet constructs a LabelSet that wraps the provided labels. +func NewSet(list []Label) Set { + return Set{List: list} +} |
