美文网首页
51.Golang FlameGraph(火焰图)

51.Golang FlameGraph(火焰图)

作者: 一枼落知天下 | 来源:发表于2019-11-10 12:59 被阅读0次

    1.安装组件

    1. 安装go-torch
      go get github.com/uber/go-torch
    2. 安装 FlameGraph
      cd $WORK_PATH && git clone https://gitee.com/mirrors/FlameGraph.git
      export PATH=$PATH:$WORK_PATH/FlameGraph
    3. 安装graphviz
      yum install graphviz(CentOS, Redhat)

    2.代码修改

    package main
    
    import (
        "net/http"
        "net/http/pprof"
    )
    
    func main() {
        // 主函数中添加
        go func() {
            http.HandleFunc("/debug/pprof/block", pprof.Index)
            http.HandleFunc("/debug/pprof/goroutine", pprof.Index)
            http.HandleFunc("/debug/pprof/heap", pprof.Index)
            http.HandleFunc("/debug/pprof/threadcreate", pprof.Index)
    
            http.ListenAndServe("0.0.0.0:8888", nil)
        }()
    
        var finishWaiter chan int
        <-finishWaiter
    }
    

    3.查看结果

    运行上述程序后,使用如下命令生成CPU火焰图:
    go-torch -u http://localhost:8888/debug/pprof/ -p > profile-local.svg

    相关文章

      网友评论

          本文标题:51.Golang FlameGraph(火焰图)

          本文链接:https://www.haomeiwen.com/subject/wkfabctx.html