mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-23 13:59:02 +00:00
runtime: make MemStats available to leaking collector
This commit is contained in:
@@ -13,6 +13,8 @@ import (
|
|||||||
|
|
||||||
const gcAsserts = false // perform sanity checks
|
const gcAsserts = false // perform sanity checks
|
||||||
|
|
||||||
|
var gcTotalAlloc uint64 // for runtime.MemStats
|
||||||
|
|
||||||
func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer
|
func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer
|
||||||
|
|
||||||
func realloc(ptr unsafe.Pointer, size uintptr) unsafe.Pointer
|
func realloc(ptr unsafe.Pointer, size uintptr) unsafe.Pointer
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
//go:build gc.conservative
|
|
||||||
// +build gc.conservative
|
|
||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
// Memory statistics
|
// Memory statistics
|
||||||
@@ -47,24 +44,3 @@ type MemStats struct {
|
|||||||
// GCSys is bytes of memory in garbage collection metadata.
|
// GCSys is bytes of memory in garbage collection metadata.
|
||||||
GCSys uint64
|
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)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
@@ -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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user