]> Cypherpunks repositories - gostls13.git/commitdiff
runtime, runtime/pprof: record instantiated symbol name in CPU profile
authorCherry Mui <cherryyz@google.com>
Tue, 2 May 2023 21:15:10 +0000 (17:15 -0400)
committerCherry Mui <cherryyz@google.com>
Fri, 5 May 2023 19:53:39 +0000 (19:53 +0000)
For generic functions, the previous CL makes it record the full
instantiated symbol name in the runtime func table. This CL
changes the pprof package to use that name in CPU profile. This
way, it matches the symbol name the compiler sees, so it can apply
PGO.

TODO: add a test.

Fixes #58712.

Change-Id: If40db01cbef5f73c279adcc9c290a757ef6955b6
Reviewed-on: https://go-review.googlesource.com/c/go/+/491678
Reviewed-by: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>

src/runtime/pprof/proto.go
src/runtime/pprof/runtime.go
src/runtime/symtab.go

index f2ff3d2767d5382de93ff8071feffb0ab6e4b4c8..cdc4bd7c80d873e78ca04e995cdaae1557a1a0ce 100644 (file)
@@ -617,7 +617,7 @@ func (b *profileBuilder) emitLocation() uint64 {
                        b.funcs[frame.Function] = int(funcID)
                        newFuncs = append(newFuncs, newFunc{
                                id:        funcID,
-                               name:      frame.Function,
+                               name:      runtime_FrameSymbolName(&frame),
                                file:      frame.File,
                                startLine: int64(runtime_FrameStartLine(&frame)),
                        })
index 57e9ca480bbae6d04418429a14e12d881c666ff7..71f89ca68076ceb7465c8ebe8c905651ca0fd4ab 100644 (file)
@@ -11,8 +11,15 @@ import (
 )
 
 // runtime_FrameStartLine is defined in runtime/symtab.go.
+//
+//go:noescape
 func runtime_FrameStartLine(f *runtime.Frame) int
 
+// runtime_FrameSymbolName is defined in runtime/symtab.go.
+//
+//go:noescape
+func runtime_FrameSymbolName(f *runtime.Frame) string
+
 // runtime_expandFinalInlineFrame is defined in runtime/symtab.go.
 func runtime_expandFinalInlineFrame(stk []uintptr) []uintptr
 
index 15e5e1d4d60de1626281458e6d737b1a1ac53604..b47f2d839099fa780fa53621d35b5ac05df18500 100644 (file)
@@ -171,6 +171,20 @@ func runtime_FrameStartLine(f *Frame) int {
        return f.startLine
 }
 
+// runtime_FrameSymbolName returns the full symbol name of the function in a Frame.
+// For generic functions this differs from f.Function in that this doesn't replace
+// the shape name to "...".
+//
+//go:linkname runtime_FrameSymbolName runtime/pprof.runtime_FrameSymbolName
+func runtime_FrameSymbolName(f *Frame) string {
+       if !f.funcInfo.valid() {
+               return f.Function
+       }
+       u, uf := newInlineUnwinder(f.funcInfo, f.PC, nil)
+       sf := u.srcFunc(uf)
+       return sf.name()
+}
+
 // runtime_expandFinalInlineFrame expands the final pc in stk to include all
 // "callers" if pc is inline.
 //