zoukankan      html  css  js  c++  java
  • pprof命令总结

    启用pprof分析

    import (
        "net/http"
        _ "net/http/pprof"
    )
    
    func pprof() error {
        if err := http.ListenAndServe("0.0.0.0:8080", nil); err != nil {
            return err
        }
        return nil
    }
    
    func main() {
        go pprof()
        // order codes
    }
    

    获取诊断报告进行分析

    直接访问 localhost:8080/debug/pprof 可以看到能获取到的诊断报告

    诊断报告类型 备注
    allocs 内存分配采样
    block 导致阻塞的的同步语句堆栈信息, 但需要使用runtime.SetBlockProfileRate(1)开启
    cmdline 进程启动的命令行参数
    goroutine 当前所有goroutine的堆栈信息
    heap 当前活动的对象内存分配采样
    mutex 持有锁的堆栈信息
    profile cpu的占用信息
    threadcreate 导致操作系统创建新增的线程的堆栈信息
    trace 当前程序执行的trace

    分析CPU占用

    go tool pprof --http=0.0.0.0:8081 --seconds=10 localhost:8080/debug/pprof/profile
    

    分析内存占用

    go tool pprof --http=0.0.0.0:8081 localhost:8080/debug/pprof/heap
    
    go tool pprof --http=0.0.0.0:8081 localhost:8080/debug/pprof/allocs
    

    查看trace信息

    wget -O trace.out localhost:8080/debug/pprof/trace
    
    go tool trace --http=:8081 trace.out
    
  • 相关阅读:
    熟悉常用的Linux操作
    Python基础综合练习
    简易c语言文法
    词法分析程序
    组合数据类型综合练习
    综合练习:词频统计
    词法分析程序2
    我对编译原理的理解
    【分享】博客美化(6)为你的博文自动添加目录
    python爬虫的基本思路
  • 原文地址:https://www.cnblogs.com/Me1onRind/p/14645281.html
Copyright © 2011-2022 走看看