runtime: make MemStats available to leaking collector
Этот коммит содержится в:
родитель
ee94f92ede
коммит
b56baa7aad
4 изменённых файлов: 45 добавлений и 24 удалений
|
@ -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)
|
|
||||||
}
|
|
||||||
|
|
25
src/runtime/mstats_conservative.go
Обычный файл
25
src/runtime/mstats_conservative.go
Обычный файл
|
@ -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
src/runtime/mstats_leaking.go
Обычный файл
18
src/runtime/mstats_leaking.go
Обычный файл
|
@ -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)
|
||||||
|
}
|
Загрузка…
Создание таблицы
Сослаться в новой задаче