go package學習——runtime

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

Index

Package Files

compiler.go debug.go error.go extern.go mem.go mgc0.go softfloat64.go type.go spa

2. 基本函數 操作系統

func GC

func GC()
運行垃圾回收。

func NumCPU

func NumCPU() int
返回本地主機的邏輯CPU數量。

func GOMAXPROCS

func GOMAXPROCS(n int) int
設置能夠同時進行運算的CPU數量;若是n<1,則不改變當前設置;能夠經過上面的NumCPU函數得到參數n。

func Goexit

func Goexit()
終止調用它的goroutine;其它goroutine不受影響。

func Gosched

func Gosched()
調用此函數的goroutine會主動放棄處理器,讓其它goroutine使用此處理其,最初的goroutine排隊等待被執行。

func NumGoroutine

func NumGoroutine() int
返回當前存在的goroutine數量。

3. type Func 線程

type Func

type Func struct { // contains filtered or unexported fields }

func (*Func) Entry

func (f *Func) Entry() uintptr
返回函數的入口地址。

func (*Func) FileLine

func (f *Func) FileLine(pc uintptr) (file string, line int)
根據程序的入口地址pc,返回文件名及源代碼行數。

func (*Func) Name

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
    }
}
記錄所統計的內存分配狀況。
相關文章
相關標籤/搜索