diff options
Diffstat (limited to 'src/pkg/runtime/mem.go')
-rw-r--r-- | src/pkg/runtime/mem.go | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/pkg/runtime/mem.go b/src/pkg/runtime/mem.go index 93d155a7f..76680086c 100644 --- a/src/pkg/runtime/mem.go +++ b/src/pkg/runtime/mem.go @@ -6,9 +6,9 @@ package runtime import "unsafe" -type MemStatsType struct { +// A MemStats records statistics about the memory allocator. +type MemStats struct { // General statistics. - // Not locked during update; approximate. Alloc uint64 // bytes allocated and still in use TotalAlloc uint64 // bytes allocated (even if freed) Sys uint64 // bytes obtained from system (should be sum of XxxSys below) @@ -17,11 +17,12 @@ type MemStatsType struct { Frees uint64 // number of frees // Main allocation heap statistics. - HeapAlloc uint64 // bytes allocated and still in use - HeapSys uint64 // bytes obtained from system - HeapIdle uint64 // bytes in idle spans - HeapInuse uint64 // bytes in non-idle span - HeapObjects uint64 // total number of allocated objects + HeapAlloc uint64 // bytes allocated and still in use + HeapSys uint64 // bytes obtained from system + HeapIdle uint64 // bytes in idle spans + HeapInuse uint64 // bytes in non-idle span + HeapReleased uint64 // bytes released to the OS + HeapObjects uint64 // total number of allocated objects // Low-level fixed-size structure allocator statistics. // Inuse is bytes used now. @@ -35,7 +36,8 @@ type MemStatsType struct { BuckHashSys uint64 // profiling bucket hash table // Garbage collector statistics. - NextGC uint64 + NextGC uint64 // next run in HeapAlloc time (bytes) + LastGC uint64 // last run in absolute time (ns) PauseTotalNs uint64 PauseNs [256]uint64 // most recent GC pause times NumGC uint32 @@ -43,7 +45,6 @@ type MemStatsType struct { DebugGC bool // Per-size allocation statistics. - // Not locked during update; approximate. // 61 is NumSizeClasses in the C code. BySize [61]struct { Size uint32 @@ -54,21 +55,17 @@ type MemStatsType struct { var sizeof_C_MStats uintptr // filled in by malloc.goc +var memStats MemStats + func init() { - if sizeof_C_MStats != unsafe.Sizeof(MemStats) { - println(sizeof_C_MStats, unsafe.Sizeof(MemStats)) + if sizeof_C_MStats != unsafe.Sizeof(memStats) { + println(sizeof_C_MStats, unsafe.Sizeof(memStats)) panic("MStats vs MemStatsType size mismatch") } } -// MemStats holds statistics about the memory system. -// The statistics may be out of date, as the information is -// updated lazily from per-thread caches. -// Use UpdateMemStats to bring the statistics up to date. -var MemStats MemStatsType - -// UpdateMemStats brings MemStats up to date. -func UpdateMemStats() +// ReadMemStats populates m with memory allocator statistics. +func ReadMemStats(m *MemStats) // GC runs a garbage collection. func GC() |