go学习之runtime
来源:互联网 发布:落叶知多少是哪首诗 编辑:程序博客网 时间:2024/06/15 15:26
runtime包包含了一些对go的runtime系统相互作用的一系列操作,例如操作goroutines的函数。它还包括一些反射包用的低级类型信息(请查阅反射文档)。
1. Environment Variables
GOGC: 设置初始的垃圾回收百分比。默认值为GOGC=100;如果设置GOGC=off,则会完全关闭垃圾回收功能。runtime/debug package的SetGCPercent函数可以在运行时改变其值。
GOGCTRACE: 从垃圾回收处控制debug输出。
GOMAXPROCS : 控制同时运行用户态go程序的操作系统线程数。
GOTRACEBACK : 控制错误导致的输出数量。
GOARCH, GOOS, GOPATH, GOROOT: 386或amd64、linux或windows、开发目录、安装目录。
Index
- Constants
- Variables
- func BlockProfile(p []BlockProfileRecord) (n int, ok bool)
- func Breakpoint()
- func CPUProfile() []byte
- func Caller(skip int) (pc uintptr, file string, line int, ok bool)
- func Callers(skip int, pc []uintptr) int
- func GC()
- func GOMAXPROCS(n int) int
- func GOROOT() string
- func Goexit()
- func GoroutineProfile(p []StackRecord) (n int, ok bool)
- func Gosched()
- func LockOSThread()
- func MemProfile(p []MemProfileRecord, inuseZero bool) (n int, ok bool)
- func NumCPU() int
- func NumCgoCall() int64
- func NumGoroutine() int
- func ReadMemStats(m *MemStats)
- func SetBlockProfileRate(rate int)
- func SetCPUProfileRate(hz int)
- func SetFinalizer(x, f interface{})
- func Stack(buf []byte, all bool) int
- func ThreadCreateProfile(p []StackRecord) (n int, ok bool)
- func UnlockOSThread()
- func Version() string
- type BlockProfileRecord
- type Error
- type Func
- func FuncForPC(pc uintptr) *Func
- func (f *Func) Entry() uintptr
- func (f *Func) FileLine(pc uintptr) (file string, line int)
- func (f *Func) Name() string
- type MemProfileRecord
- func (r *MemProfileRecord) InUseBytes() int64
- func (r *MemProfileRecord) InUseObjects() int64
- func (r *MemProfileRecord) Stack() []uintptr
- type MemStats
- type StackRecord
- func (r *StackRecord) Stack() []uintptr
- type TypeAssertionError
- func (e *TypeAssertionError) Error() string
- func (*TypeAssertionError) RuntimeError()
Package Files
compiler.go debug.go error.go extern.go mem.go mgc0.go softfloat64.go type.go
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
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 }}
记录所统计的内存分配情况。 原作者地址:https://my.oschina.net/renguijiayi/blog/159236
阅读全文
0 0
- go学习之runtime
- Go语言学习之runtime包(The way to go)
- go学习(九)——Go tool pprof之runtime/pprof 的使用
- iOS学习之 - Runtime
- runtime系列学习之iOS runtime
- Go学习笔记2之初识Go
- 学习笔记之Runtime类
- OC学习Runtime之方法
- OC学习Runtime之补充
- golang学习之--Hello GO
- Go语言学习之数据类型
- GO语言学习之goroutine
- OC学习之Runtime之关联对象
- Runtime error go fuck yourself
- channel in Go's runtime
- channel in Go's runtime
- go runtime 的机制如何
- go语言部分runtime库函数
- Gosn Util
- [js点滴]JavaScript之cookie技术
- js页面加载触发的事件 document.write 和document.onload的区别
- 磁盘镜像工具Guymager
- Linux守护进程的深入理解
- go学习之runtime
- 刷清橙OJ--A1047.做明智的消费者
- String 类的equal 和 == 的区别?
- 静态成员
- Linux下修改PATH环境变量
- CSS 选择器 (1、2、3 )
- hash算法原理详解
- mysql 查询当天、本周,本月,上一个月的数据
- 击败Facebook Infer!360火线大起底