2011-03-25 00:46:17 +01:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package runtime
|
|
|
|
|
|
|
|
import "unsafe"
|
|
|
|
|
2012-11-21 08:03:38 +01:00
|
|
|
// Note: the MemStats struct should be kept in sync with
|
|
|
|
// struct MStats in malloc.h
|
|
|
|
|
2012-02-09 09:19:58 +01:00
|
|
|
// A MemStats records statistics about the memory allocator.
|
|
|
|
type MemStats struct {
|
2011-03-25 00:46:17 +01:00
|
|
|
// General statistics.
|
|
|
|
Alloc uint64 // bytes allocated and still in use
|
|
|
|
TotalAlloc uint64 // bytes allocated (even if freed)
|
2013-11-06 20:49:01 +01:00
|
|
|
Sys uint64 // bytes obtained from system (sum of XxxSys below)
|
2011-03-25 00:46:17 +01:00
|
|
|
Lookups uint64 // number of pointer lookups
|
|
|
|
Mallocs uint64 // number of mallocs
|
|
|
|
Frees uint64 // number of frees
|
|
|
|
|
|
|
|
// Main allocation heap statistics.
|
2012-03-02 21:01:37 +01:00
|
|
|
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
|
2011-03-25 00:46:17 +01:00
|
|
|
|
|
|
|
// Low-level fixed-size structure allocator statistics.
|
|
|
|
// Inuse is bytes used now.
|
|
|
|
// Sys is bytes obtained from system.
|
|
|
|
StackInuse uint64 // bootstrap stacks
|
|
|
|
StackSys uint64
|
|
|
|
MSpanInuse uint64 // mspan structures
|
|
|
|
MSpanSys uint64
|
|
|
|
MCacheInuse uint64 // mcache structures
|
|
|
|
MCacheSys uint64
|
|
|
|
BuckHashSys uint64 // profiling bucket hash table
|
2013-11-06 20:49:01 +01:00
|
|
|
GCSys uint64 // GC metadata
|
|
|
|
OtherSys uint64 // other system allocations
|
2011-03-25 00:46:17 +01:00
|
|
|
|
|
|
|
// Garbage collector statistics.
|
2012-03-02 21:01:37 +01:00
|
|
|
NextGC uint64 // next run in HeapAlloc time (bytes)
|
|
|
|
LastGC uint64 // last run in absolute time (ns)
|
2011-03-25 00:46:17 +01:00
|
|
|
PauseTotalNs uint64
|
2012-11-21 08:03:38 +01:00
|
|
|
PauseNs [256]uint64 // circular buffer of recent GC pause times, most recent at [(NumGC+255)%256]
|
2011-03-25 00:46:17 +01:00
|
|
|
NumGC uint32
|
|
|
|
EnableGC bool
|
|
|
|
DebugGC bool
|
|
|
|
|
|
|
|
// Per-size allocation statistics.
|
|
|
|
// 61 is NumSizeClasses in the C code.
|
|
|
|
BySize [61]struct {
|
|
|
|
Size uint32
|
|
|
|
Mallocs uint64
|
|
|
|
Frees uint64
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-16 17:47:21 +02:00
|
|
|
var Sizeof_C_MStats uintptr // filled in by malloc.goc
|
2011-03-25 00:46:17 +01:00
|
|
|
|
|
|
|
func init() {
|
2014-06-07 00:37:27 +02:00
|
|
|
var memStats MemStats
|
|
|
|
if Sizeof_C_MStats != unsafe.Sizeof(memStats) {
|
|
|
|
println(Sizeof_C_MStats, unsafe.Sizeof(memStats))
|
2011-03-25 00:46:17 +01:00
|
|
|
panic("MStats vs MemStatsType size mismatch")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-09 09:19:58 +01:00
|
|
|
// ReadMemStats populates m with memory allocator statistics.
|
|
|
|
func ReadMemStats(m *MemStats)
|
2011-09-16 17:47:21 +02:00
|
|
|
|
2011-03-25 00:46:17 +01:00
|
|
|
// GC runs a garbage collection.
|
|
|
|
func GC()
|