Commit 40a00e1158 for golang
commit 40a00e1158458045f75ee71a479db4347d51a0fc
Author: Felix Geisendörfer <felix.geisendoerfer@datadoghq.com>
Date: Thu Dec 3 18:02:14 2026 +0100
runtime, runtime/pprof, net/http/pprof: rename memory profile to procmem
Rename the new "memory" profile to "procmem" across runtime,
runtime/pprof, net/http/pprof, and internal/profilerecord:
- Rename profile registration, lookup, docs, and HTTP handler from
"memory" to "procmem".
- Rename GODEBUG=memoryprofile to GODEBUG=procmemprofile and the
corresponding runtime/linkname helpers.
- Rename internal symbols, error messages, test names, and virtual
frame filename "[memory profile]" to "[procmem profile]".
For #83336
Change-Id: I2a47c9b2c7f0d23ad449058dbbf8fae07834a252
Reviewed-on: https://go-review.googlesource.com/c/go/+/869981
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nick Ripley <nick.ripley@datadoghq.com>
diff --git a/src/internal/profilerecord/profilerecord.go b/src/internal/profilerecord/profilerecord.go
index 0c07e05609..6800b59790 100644
--- a/src/internal/profilerecord/profilerecord.go
+++ b/src/internal/profilerecord/profilerecord.go
@@ -23,7 +23,7 @@ type MemProfileRecord struct {
// FreedLastGC is the number of sampled objects from this allocation
// site that the most recently completed GC found unreachable and
- // freed while sweeping. The memory profile reports them as dead heap.
+ // freed while sweeping. The procmem profile reports them as dead heap.
FreedLastGC int64
Stack []uintptr
diff --git a/src/net/http/pprof/pprof.go b/src/net/http/pprof/pprof.go
index 44e837b76c..1142a7185c 100644
--- a/src/net/http/pprof/pprof.go
+++ b/src/net/http/pprof/pprof.go
@@ -33,7 +33,7 @@
// Parameters can be passed via GET query params:
//
// - debug=N (all profiles): response format: N = 0: binary (default), N > 0: plaintext
-// - gc=N (heap, memory profiles): N > 0: run a garbage collection cycle before profiling
+// - gc=N (heap, procmem profiles): N > 0: run a garbage collection cycle before profiling
// - seconds=N (allocs, block, goroutine, heap, mutex, threadcreate profiles): return a delta profile
// - seconds=N (cpu (profile), trace profiles): profile for the given duration
//
@@ -259,7 +259,7 @@ func (name handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
gc, _ := strconv.Atoi(r.FormValue("gc"))
- if (name == "heap" || name == "memory") && gc > 0 {
+ if (name == "heap" || name == "procmem") && gc > 0 {
runtime.GC()
}
debug, _ := strconv.Atoi(r.FormValue("debug"))
@@ -269,8 +269,8 @@ func (name handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, name))
}
- if string(name) == "memory" && debug > 0 {
- serveError(w, http.StatusBadRequest, "memory profile: only debug=0 is supported")
+ if string(name) == "procmem" && debug > 0 {
+ serveError(w, http.StatusBadRequest, "procmem profile: only debug=0 is supported")
return
}
p.WriteTo(w, debug)
@@ -370,8 +370,8 @@ var profileDescriptions = map[string]string{
"cmdline": "The command line invocation of the current program",
"goroutine": "Stack traces of all current goroutines. Use debug=2 as a query parameter to export in the same format as an unrecovered panic.",
"heap": "A sampling of memory allocations of live objects. You can specify the gc GET parameter to run GC before taking the heap sample.",
- "memory": "A breakdown of sampled process memory usage at the most recently completed garbage collection. You can specify the gc GET parameter to run GC before taking the memory sample.",
"mutex": "Stack traces of holders of contended mutexes",
+ "procmem": "A breakdown of sampled process memory usage at the most recently completed garbage collection. You can specify the gc GET parameter to run GC before taking the procmem sample.",
"profile": "CPU profile. You can specify the duration in the seconds GET parameter. After you get the profile file, use the go tool pprof command to investigate the profile.",
"symbol": "Maps given program counters to function names. Counters can be specified in a GET raw query or POST body, multiple counters are separated by '+'.",
"threadcreate": "Stack traces that led to the creation of new OS threads",
diff --git a/src/runtime/mcache.go b/src/runtime/mcache.go
index 7682bff913..d99a3d3ea7 100644
--- a/src/runtime/mcache.go
+++ b/src/runtime/mcache.go
@@ -348,7 +348,7 @@ func (c *mcache) releaseAll() {
// accounted for above are not included in the heap statistics snapshot
// the memory profiler collects during mark termination stop-the-world,
// so we collect them here.
- if memoryProfileEnabled() && allocBytes != 0 && c.flushGen.Load() != sg {
+ if procmemProfileEnabled() && allocBytes != 0 && c.flushGen.Load() != sg {
// If we see a stale mcache, it means mark termination is
// ongoing and we're past the stop-the-world where
// mProfMCacheAllocBytes was reset and the sweep generation was
diff --git a/src/runtime/mprof.go b/src/runtime/mprof.go
index d2a1d3bae8..bdd42a2fd8 100644
--- a/src/runtime/mprof.go
+++ b/src/runtime/mprof.go
@@ -406,7 +406,7 @@ func mProf_AdvanceCycle(heapStats *heapStatsDelta) {
// current cycle, which is now ready to publish, describes the previous
// mark termination.
mProfCycle.increment()
- if !memoryProfileEnabled() {
+ if !procmemProfileEnabled() {
return
}
memstats.heapStats.unsafeRead(heapStats)
@@ -435,7 +435,7 @@ func mProf_Publish() {
// with the heap profile into out. Heap-related fields of out are derived from
// the provided heapStats and mcacheStats collected during mark termination.
func captureMProfMetrics(out *profilerecord.MemProfileMetrics, heapStats *heapStatsDelta, mcacheStats uint64) {
- if !memoryProfileEnabled() {
+ if !procmemProfileEnabled() {
return
}
*out = profilerecord.MemProfileMetrics{}
@@ -973,12 +973,12 @@ var MemProfileRate int = 512 * 1024
// We check if the runtime.memProfileInternal symbol is present.
var disableMemoryProfiling bool
-// memoryProfileEnabled reports whether the runtime collects the RSS and
-// runtime metrics that the runtime/pprof memory profile reports. This work is
+// procmemProfileEnabled reports whether the runtime collects the RSS and
+// runtime metrics that the runtime/pprof procmem profile reports. This work is
// done during GC, so it is skipped if memory profiling is disabled by the linker
-// or by GODEBUG=memoryprofile=0.
-func memoryProfileEnabled() bool {
- return !disableMemoryProfiling && debug.memoryprofile != 0
+// or by GODEBUG=procmemprofile=0.
+func procmemProfileEnabled() bool {
+ return !disableMemoryProfiling && debug.procmemprofile != 0
}
// A MemProfileRecord describes the live objects allocated
@@ -1158,12 +1158,12 @@ func pprof_memProfileInternal(p []profilerecord.MemProfileRecord, inuseZero bool
}, metrics)
}
-// pprof_memoryProfileEnabled reports whether the runtime collects the
-// metrics needed by the runtime/pprof memory profile.
+// pprof_procmemProfileEnabled reports whether the runtime collects the
+// metrics needed by the runtime/pprof procmem profile.
//
-//go:linknamestd pprof_memoryProfileEnabled runtime/pprof.pprof_memoryProfileEnabled
-func pprof_memoryProfileEnabled() bool {
- return memoryProfileEnabled()
+//go:linknamestd pprof_procmemProfileEnabled runtime/pprof.pprof_procmemProfileEnabled
+func pprof_procmemProfileEnabled() bool {
+ return procmemProfileEnabled()
}
func iterate_memprof(fn func(*bucket, uintptr, *uintptr, uintptr, uintptr, uintptr)) {
diff --git a/src/runtime/pprof/memory.go b/src/runtime/pprof/memory.go
index 8443957cf8..fbd491c936 100644
--- a/src/runtime/pprof/memory.go
+++ b/src/runtime/pprof/memory.go
@@ -14,7 +14,7 @@ import (
"slices"
)
-// rssVirtualFrame is a virtual frame name used in the memory profile to represent
+// rssVirtualFrame is a virtual frame name used in the procmem profile to represent
// memory categories. The bracketed names cannot collide with real Go function names.
type rssVirtualFrame string
@@ -44,26 +44,26 @@ const (
rssFrameFreeHeap rssVirtualFrame = "[Free Heap]"
)
-var memoryProfile = &Profile{
- name: "memory",
- count: countMemory,
- write: writeMemory,
+var procmemProfile = &Profile{
+ name: "procmem",
+ count: countProcmem,
+ write: writeProcmem,
}
-func countMemory() int { return 0 }
+func countProcmem() int { return 0 }
-func writeMemory(w io.Writer, debug int) error {
+func writeProcmem(w io.Writer, debug int) error {
if debug != 0 {
- return fmt.Errorf("memory profile: only debug=0 is supported")
+ return fmt.Errorf("procmem profile: only debug=0 is supported")
}
- if !pprof_memoryProfileEnabled() {
- return errors.New("memory profile: disabled by GODEBUG=memoryprofile=0")
+ if !pprof_procmemProfileEnabled() {
+ return errors.New("procmem profile: disabled by GODEBUG=procmemprofile=0")
}
p, metrics := readMemProfileWithMetrics()
if err := validateRSSMetrics(&metrics); err != nil {
- return fmt.Errorf("memory profile: %w", err)
+ return fmt.Errorf("procmem profile: %w", err)
}
- return writeMemoryProto(w, p, int64(runtime.MemProfileRate), &metrics)
+ return writeProcmemProto(w, p, int64(runtime.MemProfileRate), &metrics)
}
func readMemProfileWithMetrics() ([]profilerecord.MemProfileRecord, profilerecord.MemProfileMetrics) {
@@ -96,7 +96,7 @@ func validateRSSMetrics(m *profilerecord.MemProfileMetrics) error {
return nil
}
-func writeMemoryProto(w io.Writer, p []profilerecord.MemProfileRecord, rate int64, m *profilerecord.MemProfileMetrics) error {
+func writeProcmemProto(w io.Writer, p []profilerecord.MemProfileRecord, rate int64, m *profilerecord.MemProfileMetrics) error {
b := newProfileBuilder(w)
b.pbValueType(tagProfile_PeriodType, "space", "bytes")
b.pb.int64Opt(tagProfile_Period, 1)
@@ -135,7 +135,7 @@ func writeMemoryProto(w io.Writer, p []profilerecord.MemProfileRecord, rate int6
b.pb.uint64Opt(tagFunction_ID, funcID)
b.pb.int64Opt(tagFunction_Name, b.stringIndex(name))
b.pb.int64Opt(tagFunction_SystemName, b.stringIndex(name))
- b.pb.int64Opt(tagFunction_Filename, b.stringIndex("[memory profile]"))
+ b.pb.int64Opt(tagFunction_Filename, b.stringIndex("[procmem profile]"))
b.pb.endMessage(tagProfile_Function, fStart)
locID := b.reserveLocID()
lStart := b.pb.startMessage()
diff --git a/src/runtime/pprof/memory_test.go b/src/runtime/pprof/memory_test.go
index ce5ce59f29..1cc2199396 100644
--- a/src/runtime/pprof/memory_test.go
+++ b/src/runtime/pprof/memory_test.go
@@ -19,30 +19,30 @@ import (
"testing"
)
-func TestMemoryProfileRSSUnsupported(t *testing.T) {
+func TestProcmemProfileRSSUnsupported(t *testing.T) {
if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
return
}
var buf bytes.Buffer
- if err := Lookup("memory").WriteTo(&buf, 0); err != nil {
- t.Fatalf("writing memory profile: %v", err)
+ if err := Lookup("procmem").WriteTo(&buf, 0); err != nil {
+ t.Fatalf("writing procmem profile: %v", err)
}
p, err := profile.Parse(&buf)
if err != nil {
- t.Fatalf("parsing memory profile: %v", err)
+ t.Fatalf("parsing procmem profile: %v", err)
}
if !slices.Contains(p.Comments, "RSS is unavailable on this system") {
- t.Error("memory profile does not report unavailable RSS")
+ t.Error("procmem profile does not report unavailable RSS")
}
}
-func TestMemoryProfileDisabled(t *testing.T) {
- if os.Getenv("GO_TEST_MEMORYPROFILE_DISABLED") == "" {
- // GODEBUG=memoryprofile is read at startup, so re-run this test
+func TestProcmemProfileDisabled(t *testing.T) {
+ if os.Getenv("GO_TEST_PROCMEMPROFILE_DISABLED") == "" {
+ // GODEBUG=procmemprofile is read at startup, so re-run this test
// in a subprocess with the setting applied.
cmd := testenv.CleanCmdEnv(testenv.Command(t, testenv.Executable(t),
"-test.run=^"+t.Name()+"$", "-test.v"))
- cmd.Env = append(cmd.Env, "GO_TEST_MEMORYPROFILE_DISABLED=1", "GODEBUG=memoryprofile=0")
+ cmd.Env = append(cmd.Env, "GO_TEST_PROCMEMPROFILE_DISABLED=1", "GODEBUG=procmemprofile=0")
out, err := cmd.CombinedOutput()
if err != nil || !bytes.Contains(out, []byte("--- PASS: "+t.Name())) {
t.Fatalf("subprocess failed: %v\n%s", err, out)
@@ -50,12 +50,12 @@ func TestMemoryProfileDisabled(t *testing.T) {
return
}
- err := Lookup("memory").WriteTo(io.Discard, 0)
- if err == nil || !strings.Contains(err.Error(), "memoryprofile=0") {
- t.Errorf("writing memory profile: got error %v, want error mentioning memoryprofile=0", err)
+ err := Lookup("procmem").WriteTo(io.Discard, 0)
+ if err == nil || !strings.Contains(err.Error(), "procmemprofile=0") {
+ t.Errorf("writing procmem profile: got error %v, want error mentioning procmemprofile=0", err)
}
- // The heap profile does not depend on the memory profile metrics.
+ // The heap profile does not depend on the procmem profile metrics.
var buf bytes.Buffer
if err := Lookup("heap").WriteTo(&buf, 0); err != nil {
t.Fatalf("writing heap profile: %v", err)
@@ -65,17 +65,17 @@ func TestMemoryProfileDisabled(t *testing.T) {
}
}
-func TestMemoryProfileStructure(t *testing.T) {
+func TestProcmemProfileStructure(t *testing.T) {
// Do a GC so we have heap metrics
runtime.GC()
var buf bytes.Buffer
- if err := Lookup("memory").WriteTo(&buf, 0); err != nil {
- t.Fatalf("writing memory profile: %v", err)
+ if err := Lookup("procmem").WriteTo(&buf, 0); err != nil {
+ t.Fatalf("writing procmem profile: %v", err)
}
p, err := profile.Parse(&buf)
if err != nil {
- t.Fatalf("parsing memory profile: %v", err)
+ t.Fatalf("parsing procmem profile: %v", err)
}
t.Logf("%v", p)
if len(p.SampleType) != 1 {
@@ -142,7 +142,7 @@ func TestMemoryProfileStructure(t *testing.T) {
}
}
if prefix == "" {
- t.Errorf("memory profile traceback %q does not start with an expected virtual memory prefix", traceback)
+ t.Errorf("procmem profile traceback %q does not start with an expected virtual memory prefix", traceback)
continue
}
seenPrefixes[prefix] = true
@@ -201,7 +201,7 @@ func allocateRSSProfileLatest() {
rssProfileCycleSink = make([]byte, rssProfileCycleAllocationSize)
}
-func TestMemoryProfileHeapSamples(t *testing.T) {
+func TestProcmemProfileHeapSamples(t *testing.T) {
// Disable automatic GC so reading a profile cannot change which GC it describes.
oldGCPercent := debug.SetGCPercent(-1)
defer debug.SetGCPercent(oldGCPercent)
@@ -214,7 +214,7 @@ func TestMemoryProfileHeapSamples(t *testing.T) {
live := allocateRSSProfileLive()
runtime.GC()
- // The memory profile should show the state of the heap as of the latest
+ // The procmem profile should show the state of the heap as of the latest
// complete garbage collection, so we shouldn't see these.
for range 3 {
allocateRSSProfileStale()
@@ -232,12 +232,12 @@ func TestMemoryProfileHeapSamples(t *testing.T) {
checkProfile := func(wantDead bool) {
t.Helper()
var buf bytes.Buffer
- if err := Lookup("memory").WriteTo(&buf, 0); err != nil {
- t.Fatalf("writing memory profile: %v", err)
+ if err := Lookup("procmem").WriteTo(&buf, 0); err != nil {
+ t.Fatalf("writing procmem profile: %v", err)
}
p, err := profile.Parse(&buf)
if err != nil {
- t.Fatalf("parsing memory profile: %v", err)
+ t.Fatalf("parsing procmem profile: %v", err)
}
t.Logf("%v", p)
@@ -286,7 +286,7 @@ func TestMemoryProfileHeapSamples(t *testing.T) {
runtime.KeepAlive(live)
}
-func TestMemoryProfileRuntimeLeafFrames(t *testing.T) {
+func TestProcmemProfileRuntimeLeafFrames(t *testing.T) {
oldGCPercent := debug.SetGCPercent(-1)
defer debug.SetGCPercent(oldGCPercent)
@@ -300,7 +300,7 @@ func TestMemoryProfileRuntimeLeafFrames(t *testing.T) {
runtime.GC()
var buf bytes.Buffer
- if err := Lookup("memory").WriteTo(&buf, 0); err != nil {
+ if err := Lookup("procmem").WriteTo(&buf, 0); err != nil {
t.Fatalf("writing profile: %v", err)
}
p, err := profile.Parse(&buf)
@@ -346,7 +346,7 @@ func rssSampleHasFrame(sample *profile.Sample, name string) bool {
return false
}
-func TestMemoryProfileNonGoBreakdown(t *testing.T) {
+func TestProcmemProfileNonGoBreakdown(t *testing.T) {
// Go memory is 100 bytes: 60 bytes of heap objects (40 live, 20 dead)
// and 40 bytes of other runtime memory.
goMetrics := profilerecord.MemProfileMetrics{
@@ -403,12 +403,12 @@ func TestMemoryProfileNonGoBreakdown(t *testing.T) {
m := goMetrics
m.RSS, m.RSSShared, m.RSSHasShared = tc.rss, tc.shared, tc.hasShared
var buf bytes.Buffer
- if err := writeMemoryProto(&buf, nil, 1, &m); err != nil {
- t.Fatalf("writing memory profile: %v", err)
+ if err := writeProcmemProto(&buf, nil, 1, &m); err != nil {
+ t.Fatalf("writing procmem profile: %v", err)
}
p, err := profile.Parse(&buf)
if err != nil {
- t.Fatalf("parsing memory profile: %v", err)
+ t.Fatalf("parsing procmem profile: %v", err)
}
got := make(map[string]int64)
for _, s := range p.Sample {
diff --git a/src/runtime/pprof/pprof.go b/src/runtime/pprof/pprof.go
index 71909f19e3..e510af657e 100644
--- a/src/runtime/pprof/pprof.go
+++ b/src/runtime/pprof/pprof.go
@@ -105,7 +105,7 @@ import (
//
// Each Profile has a unique name. A few profiles are predefined:
//
-// memory - a breakdown of process memory usage
+// procmem - a breakdown of process memory usage
// heap - a sampling of memory allocations of live objects
// allocs - a sampling of all past memory allocations
//
@@ -124,9 +124,9 @@ import (
// the [StartCPUProfile] and [StopCPUProfile] functions, because it streams
// output to a writer during profiling.
//
-// # Memory profile
+// # Procmem profile
//
-// The memory profile breaks down the process's resident set size (RSS) into Go
+// The procmem profile breaks down the process's resident set size (RSS) into Go
// and non-Go memory. Go memory is further split into the heap, stacks, and
// runtime metadata, using the runtime's memory metrics (see [runtime/metrics]).
// The heap includes sampled live objects, as well as dead objects the most
@@ -164,7 +164,7 @@ import (
// flags select which to display, defaulting to -inuse_space (live objects,
// scaled by size).
//
-// For most uses, prefer the memory profile, which includes the same live heap
+// For most uses, prefer the procmem profile, which includes the same live heap
// samples along with the rest of the process's memory usage.
//
// # Allocs profile
@@ -288,7 +288,7 @@ func lockProfiles() {
if profiles.m == nil {
// Initial built-in profiles.
profiles.m = map[string]*Profile{
- "memory": memoryProfile,
+ "procmem": procmemProfile,
"heap": heapProfile,
"allocs": allocsProfile,
"goroutine": goroutineProfile,
@@ -689,7 +689,7 @@ func writeHeapInternal(w io.Writer, debug int, defaultSampleType string) error {
}
// Profile grew; try again.
}
- _ = metrics // reserved for future use by the memory profile
+ _ = metrics // reserved for future use by the procmem profile
if debug == 0 {
return writeHeapProto(w, p, int64(runtime.MemProfileRate), defaultSampleType)
@@ -1076,8 +1076,8 @@ func pprof_cyclesPerSecond() int64
//go:linknamestd pprof_memProfileInternal
func pprof_memProfileInternal(p []profilerecord.MemProfileRecord, inuseZero bool, metrics *profilerecord.MemProfileMetrics) (n int, ok bool)
-//go:linknamestd pprof_memoryProfileEnabled
-func pprof_memoryProfileEnabled() bool
+//go:linknamestd pprof_procmemProfileEnabled
+func pprof_procmemProfileEnabled() bool
//go:linkname pprof_blockProfileInternal runtime.pprof_blockProfileInternal
func pprof_blockProfileInternal(p []profilerecord.BlockProfileRecord) (n int, ok bool)
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index 24a402be2e..522a0e8163 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -943,7 +943,7 @@ func schedinit() {
// mcommoninit runs before parsedebugvars, so init profstacks again.
mProfStackInit(gp.m)
defaultGOMAXPROCSInit()
- if memoryProfileEnabled() {
+ if procmemProfileEnabled() {
sysRSSInit()
}
diff --git a/src/runtime/runtime1.go b/src/runtime/runtime1.go
index 93eb698c4f..b59ffe6ff4 100644
--- a/src/runtime/runtime1.go
+++ b/src/runtime/runtime1.go
@@ -316,7 +316,6 @@ var debug struct {
gctrace int32
invalidptr int32
madvdontneed int32 // for Linux; issue 28466
- memoryprofile int32 // set to 0 to disable the memory profile's GC work
scavtrace int32
scheddetail int32
schedtrace int32
@@ -329,6 +328,7 @@ var debug struct {
tracefpunwindoff int32
traceadvanceperiod int32
traceCheckStackOwnership int32
+ procmemprofile int32 // set to 0 to disable the procmem profile's GC work
profstackdepth int32
dataindependenttiming int32
@@ -377,8 +377,8 @@ var dbgvars = []*dbgVar{
{name: "inittrace", value: &debug.inittrace},
{name: "invalidptr", value: &debug.invalidptr},
{name: "madvdontneed", value: &debug.madvdontneed},
- {name: "memoryprofile", value: &debug.memoryprofile, def: 1},
{name: "panicnil", atomic: &debug.panicnil},
+ {name: "procmemprofile", value: &debug.procmemprofile, def: 1},
{name: "profstackdepth", value: &debug.profstackdepth, def: 128},
{name: "sbrk", value: &debug.sbrk},
{name: "scavtrace", value: &debug.scavtrace},