Fix oomprofile heap snapshots with Go 1.27

This commit is contained in:
世界
2026-11-27 19:43:34 +08:00
parent 4840891bbc
commit 89d4eea09c
3 changed files with 38 additions and 14 deletions
@@ -18,17 +18,7 @@ type stackRecord struct {
Stack []uintptr
}
type memProfileRecord struct {
AllocBytes, FreeBytes int64
AllocObjects, FreeObjects int64
Stack []uintptr
}
func (r *memProfileRecord) InUseBytes() int64 {
return r.AllocBytes - r.FreeBytes
}
func (r *memProfileRecord) InUseObjects() int64 {
func (r *memProfileRecord) inUseObjects() int64 {
return r.AllocObjects - r.FreeObjects
}
@@ -336,12 +326,12 @@ func writeHeapProto(w io.Writer, profile []memProfileRecord, rate int64, default
hideRuntime = false
}
values[0], values[1] = scaleHeapSample(record.AllocObjects, record.AllocBytes, rate)
values[2], values[3] = scaleHeapSample(record.InUseObjects(), record.InUseBytes(), rate)
values[0], values[1] = scaleHeapSample(record.AllocObjects, record.allocBytes(), rate)
values[2], values[3] = scaleHeapSample(record.inUseObjects(), record.inUseBytes(), rate)
var blockSize int64
if record.AllocObjects > 0 {
blockSize = record.AllocBytes / record.AllocObjects
blockSize = record.allocBytes() / record.AllocObjects
}
builder.pbSample(values, locs, func() {
if blockSize != 0 {
@@ -0,0 +1,17 @@
//go:build (darwin || linux || windows) && !go1.27
package oomprofile
type memProfileRecord struct {
AllocBytes, FreeBytes int64
AllocObjects, FreeObjects int64
Stack []uintptr
}
func (r *memProfileRecord) allocBytes() int64 {
return r.AllocBytes
}
func (r *memProfileRecord) inUseBytes() int64 {
return r.AllocBytes - r.FreeBytes
}
@@ -0,0 +1,17 @@
//go:build (darwin || linux || windows) && go1.27
package oomprofile
type memProfileRecord struct {
ObjectSize int64
AllocObjects, FreeObjects int64
Stack []uintptr
}
func (r *memProfileRecord) allocBytes() int64 {
return r.AllocObjects * r.ObjectSize
}
func (r *memProfileRecord) inUseBytes() int64 {
return r.inUseObjects() * r.ObjectSize
}