Advertisement

golang pprof 调试 cpu heap gc escape

阅读量:

golang 的服务调优大体需要从cpu, heap,gc入手。
cpu分析是从抽样程序里各个模块的运行效率,单位是ms
heap分析是分析抽样程序各个模块的内存损耗, 单位是 MB
gc分析是记录gc时的一些样本状态,比如gc的次数,gc时对象数量,gc后对象数量,堆大小等

代码

复制代码
    type JR struct {
    	Name string          `json:"name"`
    	Data json.RawMessage `json:"data"`
    }
    
    func main() {
    	var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`")
    	var memprofile = flag.String("memprofile", "", "write memory profile to `file`")
    	flag.Parse()
    	if *cpuprofile != "" {
    		f, err := os.Create(*cpuprofile)
    		if err != nil {
    			log.Fatal("could not create C

全部评论 (0)

还没有任何评论哟~