[go] cmd/link: don't disable memory profiling when pprof.WriteHeapProfile is used

0 views
Skip to first unread message

Cherry Mui (Gerrit)

unread,
Jul 3, 2024, 6:43:18 PM (2 days ago) Jul 3
to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Than McIntosh, Go LUCI, Austin Clements, golang-co...@googlegroups.com

Cherry Mui submitted the change

Change information

Commit message:
cmd/link: don't disable memory profiling when pprof.WriteHeapProfile is used

We have an optimization that if the memory profile is not consumed
anywhere, we set the memory profiling rate to 0 to disable the
"background" low-rate profiling. We detect whether the memory
profile is used by checking whether the runtime.MemProfile function
is reachable at link time. Previously, all APIs that access the
memory profile go through runtime.MemProfile. But the code was
refactored in CL 572396, and now the legacy entry point
WriteHeapProfile uses pprof_memProfileInternal without going
through runtime.MemProfile. In fact, even with the recommended
runtime/pprof.Profile API (pprof.Lookup or pprof.Profiles),
runtime.MemProfile is only (happen to be) reachable through
countHeap.

Change the linker to check runtime.memProfileInternal instead,
which is on all code paths that retrieve the memory profile. Add
a test case for WriteHeapProfile, so we cover all entry points.

Fixes #68136.
Change-Id: I075c8d45c95c81825a1822f032e23107aea4303c
Reviewed-by: Than McIntosh <th...@google.com>
Files:
  • M src/cmd/link/internal/ld/ld_test.go
  • M src/cmd/link/internal/ld/lib.go
  • M src/runtime/mprof.go
  • M src/runtime/pprof/pprof.go
Change size: S
Delta: 4 files changed, 41 insertions(+), 5 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +2 by Than McIntosh
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I075c8d45c95c81825a1822f032e23107aea4303c
Gerrit-Change-Number: 596538
Gerrit-PatchSet: 2
Gerrit-Owner: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: Austin Clements <aus...@google.com>
Gerrit-Reviewer: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: Than McIntosh <th...@google.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages