package runtime主要是与go的runtime系统进行互动操做,例如控制goroutine的函数等。它也包含reflect package所需的低等级信息。 linux
1. Environment Variables
GOGC: 设置初始的垃圾回收百分比。默认值为GOGC=100;若是设置GOGC=off,则会彻底关闭垃圾回收功能。runtime/debug package的SetGCPercent函数能够在运行时改变其值。 bootstrap
GOGCTRACE: 从垃圾回收处控制debug输出。 windows
GOMAXPROCS : 控制同时运行用户态go程序的操做系统线程数。 函数
GOTRACEBACK : 控制错误致使的输出数量。 ui
GOARCH, GOOS, GOPATH, GOROOT: 386或amd6四、linux或windows、开发目录、安装目录。 google
compiler.go debug.go error.go extern.go mem.go mgc0.go softfloat64.go type.go spa
2. 基本函数 操作系统
func GC()运行垃圾回收。
func NumCPU() int返回本地主机的逻辑CPU数量。
func GOMAXPROCS(n int) int设置能够同时进行运算的CPU数量;若是n<1,则不改变当前设置;能够经过上面的NumCPU函数得到参数n。
func Goexit()终止调用它的goroutine;其它goroutine不受影响。
func Gosched()调用此函数的goroutine会主动放弃处理器,让其它goroutine使用此处理其,最初的goroutine排队等待被执行。
func NumGoroutine() int返回当前存在的goroutine数量。
3. type Func 线程
type Func struct { // contains filtered or unexported fields }
func (f *Func) Entry() uintptr返回函数的入口地址。
func (f *Func) FileLine(pc uintptr) (file string, line int)根据程序的入口地址pc,返回文件名及源代码行数。
func (f *Func) Name() string返回函数名。
4. type MemStats
debug
type MemStats struct { // General statistics. 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) Lookups uint64 // number of pointer lookups Mallocs uint64 // number of mallocs 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 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. // 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 // Garbage collector statistics. NextGC uint64 // next run in HeapAlloc time (bytes) LastGC uint64 // last run in absolute time (ns) PauseTotalNs uint64 PauseNs [256]uint64 // circular buffer of recent GC pause times, most recent at [(NumGC+255)%256] 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 } }记录所统计的内存分配状况。