src/pkg/runtime/mem.go - The Go Programming Language

Golang

Source file src/pkg/runtime/mem.go

     1	// Copyright 2009 The Go Authors. All rights reserved.
     2	// Use of this source code is governed by a BSD-style
     3	// license that can be found in the LICENSE file.
     4	
     5	package runtime
     6	
     7	import "unsafe"
     8	
     9	// A MemStats records statistics about the memory allocator.
    10	type MemStats struct {
    11		// General statistics.
    12		Alloc      uint64 // bytes allocated and still in use
    13		TotalAlloc uint64 // bytes allocated (even if freed)
    14		Sys        uint64 // bytes obtained from system (should be sum of XxxSys below)
    15		Lookups    uint64 // number of pointer lookups
    16		Mallocs    uint64 // number of mallocs
    17		Frees      uint64 // number of frees
    18	
    19		// Main allocation heap statistics.
    20		HeapAlloc    uint64 // bytes allocated and still in use
    21		HeapSys      uint64 // bytes obtained from system
    22		HeapIdle     uint64 // bytes in idle spans
    23		HeapInuse    uint64 // bytes in non-idle span
    24		HeapReleased uint64 // bytes released to the OS
    25		HeapObjects  uint64 // total number of allocated objects
    26	
    27		// Low-level fixed-size structure allocator statistics.
    28		//	Inuse is bytes used now.
    29		//	Sys is bytes obtained from system.
    30		StackInuse  uint64 // bootstrap stacks
    31		StackSys    uint64
    32		MSpanInuse  uint64 // mspan structures
    33		MSpanSys    uint64
    34		MCacheInuse uint64 // mcache structures
    35		MCacheSys   uint64
    36		BuckHashSys uint64 // profiling bucket hash table
    37	
    38		// Garbage collector statistics.
    39		NextGC       uint64 // next run in HeapAlloc time (bytes)
    40		LastGC       uint64 // last run in absolute time (ns)
    41		PauseTotalNs uint64
    42		PauseNs      [256]uint64 // most recent GC pause times
    43		NumGC        uint32
    44		EnableGC     bool
    45		DebugGC      bool
    46	
    47		// Per-size allocation statistics.
    48		// 61 is NumSizeClasses in the C code.
    49		BySize [61]struct {
    50			Size    uint32
    51			Mallocs uint64
    52			Frees   uint64
    53		}
    54	}
    55	
    56	var sizeof_C_MStats uintptr // filled in by malloc.goc
    57	
    58	var memStats MemStats
    59	
    60	func init() {
    61		if sizeof_C_MStats != unsafe.Sizeof(memStats) {
    62			println(sizeof_C_MStats, unsafe.Sizeof(memStats))
    63			panic("MStats vs MemStatsType size mismatch")
    64		}
    65	}
    66	
    67	// ReadMemStats populates m with memory allocator statistics.
    68	func ReadMemStats(m *MemStats)
    69	
    70	// GC runs a garbage collection.
    71	func GC()