runtime: add MemStats.TotalAlloc

This commit is contained in:
Damian Gryski
2022-08-09 14:03:19 -07:00
committed by Ron Evans
parent b56baa7aad
commit a87e5cdbf0
5 changed files with 17 additions and 1 deletions
+4
View File
@@ -16,6 +16,9 @@ const gcAsserts = false // perform sanity checks
// Ever-incrementing pointer: no memory is freed.
var heapptr = heapStart
// Total amount allocated for runtime.MemStats
var gcTotalAlloc uint64
// Inlining alloc() speeds things up slightly but bloats the executable by 50%,
// see https://github.com/tinygo-org/tinygo/issues/2674. So don't.
//
@@ -26,6 +29,7 @@ func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer {
// systems).
size = align(size)
addr := heapptr
gcTotalAlloc += uint64(size)
heapptr += size
for heapptr >= heapEnd {
// Try to increase the heap and check again.