runtime: make MemStats available to leaking collector

This commit is contained in:
Damian Gryski
2022-08-09 14:01:43 -07:00
committed by Ron Evans
parent ee94f92ede
commit b56baa7aad
4 changed files with 45 additions and 24 deletions
+2
View File
@@ -13,6 +13,8 @@ import (
const gcAsserts = false // perform sanity checks
var gcTotalAlloc uint64 // for runtime.MemStats
func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer
func realloc(ptr unsafe.Pointer, size uintptr) unsafe.Pointer
-24
View File
@@ -1,6 +1,3 @@
//go:build gc.conservative
// +build gc.conservative
package runtime
// Memory statistics
@@ -47,24 +44,3 @@ type MemStats struct {
// GCSys is bytes of memory in garbage collection metadata.
GCSys uint64
}
// ReadMemStats populates m with memory statistics.
//
// The returned memory statistics are up to date as of the
// call to ReadMemStats. This would not do GC implicitly for you.
func ReadMemStats(m *MemStats) {
m.HeapIdle = 0
m.HeapInuse = 0
for block := gcBlock(0); block < endBlock; block++ {
bstate := block.state()
if bstate == blockStateFree {
m.HeapIdle += uint64(bytesPerBlock)
} else {
m.HeapInuse += uint64(bytesPerBlock)
}
}
m.HeapReleased = 0 // always 0, we don't currently release memory back to the OS.
m.HeapSys = m.HeapInuse + m.HeapIdle
m.GCSys = uint64(heapEnd - uintptr(metadataStart))
m.Sys = uint64(heapEnd - heapStart)
}
+25
View File
@@ -0,0 +1,25 @@
//go:build gc.conservative
// +build gc.conservative
package runtime
// ReadMemStats populates m with memory statistics.
//
// The returned memory statistics are up to date as of the
// call to ReadMemStats. This would not do GC implicitly for you.
func ReadMemStats(m *MemStats) {
m.HeapIdle = 0
m.HeapInuse = 0
for block := gcBlock(0); block < endBlock; block++ {
bstate := block.state()
if bstate == blockStateFree {
m.HeapIdle += uint64(bytesPerBlock)
} else {
m.HeapInuse += uint64(bytesPerBlock)
}
}
m.HeapReleased = 0 // always 0, we don't currently release memory back to the OS.
m.HeapSys = m.HeapInuse + m.HeapIdle
m.GCSys = uint64(heapEnd - uintptr(metadataStart))
m.Sys = uint64(heapEnd - heapStart)
}
+18
View File
@@ -0,0 +1,18 @@
//go:build gc.leaking
// +build gc.leaking
package runtime
// ReadMemStats populates m with memory statistics.
//
// The returned memory statistics are up to date as of the
// call to ReadMemStats. This would not do GC implicitly for you.
func ReadMemStats(m *MemStats) {
m.HeapIdle = 0
m.HeapInuse = uint64(heapptr - heapStart)
m.HeapReleased = 0 // always 0, we don't currently release memory back to the OS.
m.HeapSys = m.HeapInuse + m.HeapIdle
m.GCSys = 0
m.Sys = uint64(heapEnd - heapStart)
}