GOMAXPROCS
old := runtime.GOMAXPROCS(4)
runtime.GOMAXPROCS(runtime.NumCPU())
runtimeHooks into the Go runtime: GOMAXPROCS, goroutine count, GC triggering, caller info, finalizers.
old := runtime.GOMAXPROCS(4)
runtime.GOMAXPROCS(runtime.NumCPU())
fmt.Println("goroutines:", runtime.NumGoroutine())
runtime.Gosched() // yield to scheduler
runtime.Goexit() // terminate current goroutine (deferred funcs still run)
runtime.GC() // blocking full GC
debug.SetGCPercent(200) // tune GC trigger (debug package)
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Println(m.HeapAlloc, m.NumGC)
pc, file, line, ok := runtime.Caller(1)
if ok {
fn := runtime.FuncForPC(pc)
fmt.Printf("%s at %s:%d\n", fn.Name(), file, line)
}
runtime.SetFinalizer(obj, func(o *T) { o.Close() })
runtime.AddCleanup(obj, func(h *Handle) { h.Free() }, handle)
fmt.Println(runtime.GOOS, runtime.GOARCH, runtime.Version())