The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
nomansky

运行中的 go 进程中某个函数偶尔出现执行慢的情况,怎么跟踪堆栈调用?

  •  
  •   nomansky · Oct 23, 2020 · 2553 views
    This topic created in 2056 days ago, the information mentioned may be changed or developed.
    一个在 production 环境运行的进程,不可能修改代码,日志记录的也不详细,不定时出现某个函数执行慢的情况,gops,pprof 等都需要在代码中实现 agent 才能 profiling 和 tracing 。有没有大佬了解有什么工具可以不需要 agent 跟踪正在运行的程序的堆栈调用?
    12 replies    2020-10-23 13:17:16 +08:00
    JeromeCui
        1
    JeromeCui  
       Oct 23, 2020
    我就会一招:打印日志
    nomansky
        2
    nomansky  
    OP
       Oct 23, 2020
    @JeromeCui 我也想,没办法打印...
    lcode
        3
    lcode  
       Oct 23, 2020
    测试环境模拟一下
    不能复现的 bug 就不是 bug (
    zunceng
        4
    zunceng  
       Oct 23, 2020   ❤️ 1
    http 框架里面集成一个 pprof 中间件 做好了以后一行代码就好了 如果是 gin 直接用下面的
    https://github.com/gin-contrib/pprof
    monsterxx03
        5
    monsterxx03  
       Oct 23, 2020
    https://github.com/monsterxx03/gospy

    可以不改代码打印正在跑的 goroutine, 不过好像并不能帮你调试某个函数慢的问题
    polythene
        6
    polythene  
       Oct 23, 2020
    Linux 下的 perf 能直接读取 Go 进程的符号值
    TypeErrorNone
        7
    TypeErrorNone  
       Oct 23, 2020
    @zunceng 如果有几十个容器,怎么搞呢
    kiddingU
        9
    kiddingU  
       Oct 23, 2020
    opentracing 可以定位到是链路中哪个函数慢,然后再去优化
    Lonenso
        10
    Lonenso  
       Oct 23, 2020 via Android
    Leigg
        11
    Leigg  
       Oct 23, 2020 via Android
    你不能确定函数范围?没上链路追踪就自己挨个打日志
    zunceng
        12
    zunceng  
       Oct 23, 2020
    @TypeErrorNone 一般来说不会把这个接口暴露出去 想个办法内部访问
    如果程序部署在 k8s
    kubectl run my-shell --rm -i --tty --image golang -- sh
    > go tools pprof http://${pod_name}/debug/pprof/heap
    在生产创建 pod 的权限非常高 对权限管控有要求的企业 可以把这一套做成一个线上的调试工具 web 方式提供给内部人员使用
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5499 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 75ms · UTC 01:21 · PVG 09:21 · LAX 18:21 · JFK 21:21
    ♥ Do have faith in what you're doing.