This is a creation in Article, where the information may have evolved or changed.
original articles, reproduced please specify the Source: Server non-amateur research http://blog.csdn.net/erlib author Sunface
This article will continue to summarize some of the methods of memory, GC metrics
The first is through
Stats:= &Runtime.Memstats{}Runtime.Readmemstats(Stats)
This is to get a stat that contains information about memory and garbage collection: GC Time distribution SLICE,GC Total time, GC number, etc.
typeGarbage struct{aint }func Notify(F*Garbage) {Stats:= &Runtime.Memstats{}Runtime.Readmemstats(Stats)FMT.Println("Last GC was:",Stats.LASTGC)
GoProducefinalizedgarbage()}funcProducefinalizedgarbage() {x:= &Garbage{}Runtime.Setfinalizer(x,Notify)}Func main() {GoProducefinalizedgarbage() for {Runtime.GC() Time.Sleep( - * Time.Second) //Give GC time to run }}
(not to be continued)