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
+3
View File
@@ -55,6 +55,7 @@ var (
metadataStart unsafe.Pointer // pointer to the start of the heap metadata
nextAlloc gcBlock // the next block that should be tried by the allocator
endBlock gcBlock // the block just past the end of the available space
gcTotalAlloc uint64 // for runtime.MemStats
)
// zeroSizedAlloc is just a sentinel that gets returned when allocating 0 bytes.
@@ -266,6 +267,8 @@ func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer {
return unsafe.Pointer(&zeroSizedAlloc)
}
gcTotalAlloc += uint64(size)
neededBlocks := (size + (bytesPerBlock - 1)) / bytesPerBlock
// Continue looping until a run of free blocks has been found that fits the