Skip to content

runtime: add runtime/pprof goroutine labels to tracebacks #76349

@dfinkel

Description

@dfinkel

Proposal Details

Forking off #23458 and https://go.dev/cl/694119.

#23458 includes adding goroutine labels to traces of various kinds. One of them, is the runtime-generated traceback. This has turned into a more contentious subject than expected, so, I'm moving this to its own issue.

As the traceback format is not covered by the go 1 compatibility promise, both @adonovan and @prattmic have mentioned that they don't think adding these goroutine labels to the traceback out put needs a full proposal.

This issue proposes adding these goroutine labels, and provides space for discussion of different/improved formats for go 1.27+.

https://go.dev/cl/694119 has one format and is currently hidden behind GODEBUG=tracebacklabels=1.

The current version of https://go.dev/cl/694119 adds labels:{"foobar": "baz"} to the goroutine blocking-status at the top of the goroutine-level dump with some simple quoting for the key/value pairs. To avoid issues with unprintable, newlines, control characters, and higher unicode, everything outside the simple printable ASCII range is escaped.

The current escaping-scheme came out of discussions with @adonovan about the possibility of breaking tools parsing these dumps.

As an example, there's a goroutine dump from a current version (from a test):

 goroutine 8 [running labels:{"foobar": "baz"}]:
        runtime_test.TestTracebackGoroutineLabelsDisabledGODEBUG.func1(...)
                /home/davidf/src/golang/src/runtime/traceback_test.go:940
        runtime_test.TestTracebackGoroutineLabelsDisabledGODEBUG(0x1106b50406c8)
                /home/davidf/src/golang/src/runtime/traceback_test.go:952 +0x185
        testing.tRunner(0x1106b50406c8, 0x9cf9b0)
                /home/davidf/src/golang/src/testing/testing.go:2032 +0x102
        created by testing.(*T).Run in goroutine 1
                /home/davidf/src/golang/src/testing/testing.go:2102 +0x61a
        

Notably, unlike the tracebacks from the runtime package, the runtime/pprof package's debug=1 dumps have comment characters leading additional information lines. An alternative is to place these labels on another line like those, so it looks something like:

 goroutine 8 [running]:
#  labels:{"foobar": "baz"}
runtime_test.TestTracebackGoroutineLabelsDisabledGODEBUG.func1(...)
        /home/davidf/src/golang/src/runtime/traceback_test.go:940
<snip>

We could also split out the labels to be one per-line with some indenting:

 goroutine 8 [running]:
#  labels:
#   - "foobar": "baz"
#   - "quux": "bat"
runtime_test.TestTracebackGoroutineLabelsDisabledGODEBUG.func1(...)
        /home/davidf/src/golang/src/runtime/traceback_test.go:940
<snip>

My general preference would be to merge the existing https://go.dev/cl/694119 for go 1.26 and adjust for 1.27 (and only then switch the GODEBUG to default to 1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.Proposalcompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    In Progress

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions