Skip to content

runtime/pprof: better generic type information in pprof stack traces #68196

Open
@felixge

Description

@felixge

Proposal Details

tl;dr: Can we show something more descriptive than go.shape.*uint8 for generic methods invoked on a struct pointer Maybe go.shape.uintptr or the element type?


While profiling is primarily seen as a performance tool, we often see it used for understanding the control flow of Go applications at runtime. In particular, profiling can be very useful to reveal which concrete types are being invoked behind an interface or a generic function call.

In one particular case @g-talbot recently tried to figure out the concrete type parameter for a generic function call, and to our surprise we saw the type being called go.shape.*uint8 which was confusing since it doesn't correspond to any of the types satisfying the type constraints of the generic functions. We would have expected to see something more like *SomeStruct instead.

After a bit of digging, my colleague @nsrip-dd discovered that this output is probably intentional (source), but we're wondering if it could be made more user-friendly. Either by clarifying that the type is an unknown pointer type (go.shape.uintptr) or by showing the actual type.

Below is a minimal example that shows how to end up with a go.shape.*uint8 inside of a CPU profile:

package main

import "testing"

func BenchmarkContainer(b *testing.B) {
	d := &Container[*Node]{}
	for i := 0; i < b.N; i++ {
		d.Add(nil)
	}
}

type Container[T any] struct{}

//go:noinline to make this frame shows up in the cpu profile.
func (d *Container[T]) Add(a T) {}

type Node struct{}
$ go test -bench . -cpuprofile cpu.pprof
$ go tool pprof -http=: cpu.pprof.

image

We understand that the current displayed type probably makes a lot of sense from the compiler's perspective, but seeing a uint8 type as a placeholder for a pointer type on a 64 bit system was confusing to us.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.gabywins

    Type

    No type

    Projects

    • Status

      Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions