From 2375ef8df69e906c26cd99ef8675b80ba61c5188 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Fri, 12 Aug 2022 14:29:56 -0400 Subject: [PATCH] [release-branch.go1.19] cmd: vendor github.com/google/pprof to fix mangled type parameter symbol names Updates github.com/google/pprof to bring in the commit from https://github.com/google/pprof/pull/717 which fixes mangled symbol names for type parameters. For #54105 Fixes #54420 Change-Id: I01af9f780aba3338b960a03b30906a23642e4448 Reviewed-on: https://go-review.googlesource.com/c/go/+/420234 TryBot-Result: Gopher Robot Reviewed-by: Dmitri Shuralyov Reviewed-by: Dmitri Shuralyov Run-TryBot: Emmanuel Odeke Reviewed-by: Than McIntosh (cherry picked from commit cd9cd925bb9ed79975f2531a6b84f69905e4fc31) Reviewed-on: https://go-review.googlesource.com/c/go/+/423356 Run-TryBot: Michael Pratt Reviewed-by: Emmanuel Odeke --- src/cmd/go.mod | 2 +- src/cmd/go.sum | 4 +- .../google/pprof/internal/driver/settings.go | 8 ++- .../google/pprof/internal/graph/dotgraph.go | 3 + .../pprof/internal/symbolizer/symbolizer.go | 61 ++++++++++++------- src/cmd/vendor/modules.txt | 2 +- 6 files changed, 50 insertions(+), 30 deletions(-) diff --git a/src/cmd/go.mod b/src/cmd/go.mod index 8230a3e453170..b8f367d02e03b 100644 --- a/src/cmd/go.mod +++ b/src/cmd/go.mod @@ -3,7 +3,7 @@ module cmd go 1.19 require ( - github.com/google/pprof v0.0.0-20220517023622-154dc81eb7b0 + github.com/google/pprof v0.0.0-20220729232143-a41b82acbcb1 golang.org/x/arch v0.0.0-20220412001346-fc48f9fe4c15 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 diff --git a/src/cmd/go.sum b/src/cmd/go.sum index 435c3cce3bf51..99c41d94fb529 100644 --- a/src/cmd/go.sum +++ b/src/cmd/go.sum @@ -1,5 +1,5 @@ -github.com/google/pprof v0.0.0-20220517023622-154dc81eb7b0 h1:XgEFTOJTsN3Li0Txfhn2UzsysGJfXIDe7wE07uY7ZfI= -github.com/google/pprof v0.0.0-20220517023622-154dc81eb7b0/go.mod h1:gSuNB+gJaOiQKLEZ+q+PK9Mq3SOzhRcw2GsGS/FhYDk= +github.com/google/pprof v0.0.0-20220729232143-a41b82acbcb1 h1:8pyqKJvrJqUYaKS851Ule26pwWvey6IDMiczaBLDKLQ= +github.com/google/pprof v0.0.0-20220729232143-a41b82acbcb1/go.mod h1:gSuNB+gJaOiQKLEZ+q+PK9Mq3SOzhRcw2GsGS/FhYDk= github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2 h1:rcanfLhLDA8nozr/K289V1zcntHr3V+SHlXwzz1ZI2g= github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= golang.org/x/arch v0.0.0-20220412001346-fc48f9fe4c15 h1:GVfVkciLYxn5mY5EncwAe0SXUn9Rm81rRkZ0TTmn/cU= diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/settings.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/settings.go index f72314b1857dd..1e9154c5f5336 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/settings.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/settings.go @@ -79,7 +79,7 @@ type configMenuEntry struct { } // configMenu returns a list of items to add to a menu in the web UI. -func configMenu(fname string, url url.URL) []configMenuEntry { +func configMenu(fname string, u url.URL) []configMenuEntry { // Start with system configs. configs := []namedConfig{{Name: "Default", config: defaultConfig()}} if settings, err := readSettings(fname); err == nil { @@ -91,13 +91,15 @@ func configMenu(fname string, url url.URL) []configMenuEntry { result := make([]configMenuEntry, len(configs)) lastMatch := -1 for i, cfg := range configs { - dst, changed := cfg.config.makeURL(url) + dst, changed := cfg.config.makeURL(u) if !changed { lastMatch = i } + // Use a relative URL to work in presence of stripping/redirects in webui.go. + rel := &url.URL{RawQuery: dst.RawQuery, ForceQuery: true} result[i] = configMenuEntry{ Name: cfg.Name, - URL: dst.String(), + URL: rel.String(), UserConfig: (i != 0), } } diff --git a/src/cmd/vendor/github.com/google/pprof/internal/graph/dotgraph.go b/src/cmd/vendor/github.com/google/pprof/internal/graph/dotgraph.go index 9ff4c95adbe32..09d40fd2c9901 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/graph/dotgraph.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/graph/dotgraph.go @@ -385,6 +385,9 @@ func multilinePrintableName(info *NodeInfo) string { infoCopy := *info infoCopy.Name = escapeForDot(ShortenFunctionName(infoCopy.Name)) infoCopy.Name = strings.Replace(infoCopy.Name, "::", `\n`, -1) + // Go type parameters are reported as "[...]" by Go pprof profiles. + // Keep this ellipsis rather than replacing with newlines below. + infoCopy.Name = strings.Replace(infoCopy.Name, "[...]", "[…]", -1) infoCopy.Name = strings.Replace(infoCopy.Name, ".", `\n`, -1) if infoCopy.File != "" { infoCopy.File = filepath.Base(infoCopy.File) diff --git a/src/cmd/vendor/github.com/google/pprof/internal/symbolizer/symbolizer.go b/src/cmd/vendor/github.com/google/pprof/internal/symbolizer/symbolizer.go index cbb0ed4d1b0bb..d243b800a92fc 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/symbolizer/symbolizer.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/symbolizer/symbolizer.go @@ -205,49 +205,64 @@ func Demangle(prof *profile.Profile, force bool, demanglerMode string) { } } - var options []demangle.Option + options := demanglerModeToOptions(demanglerMode) + for _, fn := range prof.Function { + demangleSingleFunction(fn, options) + } +} + +func demanglerModeToOptions(demanglerMode string) []demangle.Option { switch demanglerMode { case "": // demangled, simplified: no parameters, no templates, no return type - options = []demangle.Option{demangle.NoParams, demangle.NoTemplateParams} + return []demangle.Option{demangle.NoParams, demangle.NoTemplateParams} case "templates": // demangled, simplified: no parameters, no return type - options = []demangle.Option{demangle.NoParams} + return []demangle.Option{demangle.NoParams} case "full": - options = []demangle.Option{demangle.NoClones} + return []demangle.Option{demangle.NoClones} case "none": // no demangling - return + return []demangle.Option{} } + panic(fmt.Sprintf("unknown demanglerMode %s", demanglerMode)) +} + +func demangleSingleFunction(fn *profile.Function, options []demangle.Option) { + if fn.Name != "" && fn.SystemName != fn.Name { + return // Already demangled. + } // Copy the options because they may be updated by the call. o := make([]demangle.Option, len(options)) - for _, fn := range prof.Function { - if fn.Name != "" && fn.SystemName != fn.Name { - continue // Already demangled. - } - copy(o, options) - if demangled := demangle.Filter(fn.SystemName, o...); demangled != fn.SystemName { - fn.Name = demangled - continue - } - // Could not demangle. Apply heuristics in case the name is - // already demangled. - name := fn.SystemName - if looksLikeDemangledCPlusPlus(name) { - if demanglerMode == "" || demanglerMode == "templates" { + copy(o, options) + if demangled := demangle.Filter(fn.SystemName, o...); demangled != fn.SystemName { + fn.Name = demangled + return + } + // Could not demangle. Apply heuristics in case the name is + // already demangled. + name := fn.SystemName + if looksLikeDemangledCPlusPlus(name) { + for _, o := range options { + switch o { + case demangle.NoParams: name = removeMatching(name, '(', ')') - } - if demanglerMode == "" { + case demangle.NoTemplateParams: name = removeMatching(name, '<', '>') } } - fn.Name = name } + fn.Name = name } // looksLikeDemangledCPlusPlus is a heuristic to decide if a name is // the result of demangling C++. If so, further heuristics will be // applied to simplify the name. func looksLikeDemangledCPlusPlus(demangled string) bool { - if strings.Contains(demangled, ".<") { // Skip java names of the form "class." + // Skip java names of the form "class.". + if strings.Contains(demangled, ".<") { + return false + } + // Skip Go names of the form "foo.(*Bar[...]).Method". + if strings.Contains(demangled, "]).") { return false } return strings.ContainsAny(demangled, "<>[]") || strings.Contains(demangled, "::") diff --git a/src/cmd/vendor/modules.txt b/src/cmd/vendor/modules.txt index 4e4b5b63433a7..59d679c3b2d43 100644 --- a/src/cmd/vendor/modules.txt +++ b/src/cmd/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/google/pprof v0.0.0-20220517023622-154dc81eb7b0 +# github.com/google/pprof v0.0.0-20220729232143-a41b82acbcb1 ## explicit; go 1.17 github.com/google/pprof/driver github.com/google/pprof/internal/binutils