Skip to content

x/telemetry: gather program counters #73268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
adonovan opened this issue Apr 8, 2025 · 6 comments
Closed

x/telemetry: gather program counters #73268

adonovan opened this issue Apr 8, 2025 · 6 comments
Assignees
Labels
gopls Issues related to the Go language server, gopls. Proposal telemetry x/telemetry issues
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Apr 8, 2025

Background: Recently I have been spending a lot of time staring at disassembly of Go executables (specifically gopls) trying to figure out why a process crashed on a line of code that "can't go wrong" according to Go's type system. All we have to go on is the line number. From the line number and pclntab of the reconstructed executable it is possible to compute a set of candidate instructions, but it would be nice to know definitively which one was the culprit.

This information is available to the runtime crash monitor, but it discards it when constructing the names of the stack counters to avoid spurious variation. This was a mistake: we already have to deal with spurious variation in line number perturbation from one version to the next, which we achieve by using the "stacks" expression language to match only the significant portions of the text; the same solution will work even as the variance increases.

Proposal: We should change the format of stack counters to include the relative PC value of each frame. If we do this by appending a suffix to each line, none of our existing "stacks" expressions would need to change.

Example of current format:

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Reportf:+1
golang.org/x/tools/gopls/internal/cache.typeErrorsToDiagnostics.func1:+34
...

Example of proposed format:

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35 pc=+0x12
golang.org/x/tools/gopls/internal/util/bug.Reportf:+1 pc=+0x34
golang.org/x/tools/gopls/internal/cache.typeErrorsToDiagnostics.func1:+34 pc=+0x56
...

@golang/telemetry

@gopherbot gopherbot added the telemetry x/telemetry issues label Apr 8, 2025
@gopherbot gopherbot added this to the Unreleased milestone Apr 8, 2025
@adonovan adonovan removed this from Proposals Apr 8, 2025
@adonovan adonovan modified the milestones: Unreleased, gopls/v0.19.0 Apr 8, 2025
@adonovan adonovan added the gopls Issues related to the Go language server, gopls. label Apr 8, 2025
@gabyhelp gabyhelp added the Telemetry-Proposal Issues proposing new telemetry counters. label Apr 8, 2025
@findleyr findleyr added Proposal and removed Telemetry-Proposal Issues proposing new telemetry counters. labels Apr 9, 2025
@findleyr findleyr changed the title x/telemetry: gather program counters Proposal: x/telemetry: gather program counters Apr 9, 2025
@findleyr findleyr moved this to Incoming in Proposals Apr 9, 2025
@findleyr
Copy link
Member

findleyr commented Apr 9, 2025

Thanks, I think this makes sense and (since we have the binary version anyway) doesn't represent a significant change in the data collected by telemetry--just a refinement from line number to PC granularity.

I'm not sure if this will require a version bump in the telemetry file: my guess is not, as long as the new stack format can be parsed by the old upload logic. Needs investigation, but that is an implementation detail.

I've promoted this from a Telemetry-Proposal to an actual proposal, since it is proposing a new API rather than new counters.

@seankhliao seankhliao changed the title Proposal: x/telemetry: gather program counters proposal: x/telemetry: gather program counters Apr 9, 2025
@adonovan
Copy link
Member Author

adonovan commented Apr 9, 2025

I've promoted this from a Telemetry-Proposal to an actual proposal, since it is proposing a new API rather than new counters.

It's not an API, it's just a change to the encoding of stacks as counter names. The x/telemetry repo's README warns that it "is intended for use only in tools maintained by the Go team" and provides "no compatibility guarantees". So this doesn't need a proposal.

@adonovan adonovan removed this from Proposals Apr 9, 2025
@adonovan adonovan changed the title proposal: x/telemetry: gather program counters x/telemetry: gather program counters Apr 9, 2025
@adonovan adonovan self-assigned this Apr 9, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/664175 mentions this issue: internal/counter: record program counters in stack counter names

@adonovan
Copy link
Member Author

adonovan commented Apr 9, 2025

The format I used in the CL was: golang.org/x/tools/gopls/internal/util/bug.report:+35/+0x12a. The relative PC suffix /+0x12a is always present and gives the PC relative to the (post-inlining) function entry. No changes are needed to the stacks command.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/666416 mentions this issue: gopls: update x/telemetry

gopherbot pushed a commit to golang/tools that referenced this issue Apr 17, 2025
Updates golang/go#73268

Change-Id: I13168d1edae1358919e69c7ee965bafd4c6833d0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/666416
Auto-Submit: Alan Donovan <[email protected]>
Reviewed-by: Robert Findley <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Proposal telemetry x/telemetry issues
Projects
None yet
Development

No branches or pull requests

4 participants