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

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

  •  
  •   nomansky · Oct 23, 2020 · 2935 views
    This topic created in 2218 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
    JeromeCui
    Oct 23, 2020
    1
    我就会一招:打印日志
    nomansky
    nomansky
    OP
    Oct 23, 2020
    2
    @JeromeCui 我也想,没办法打印...
    lcode
    lcode
    Oct 23, 2020
    3
    测试环境模拟一下
    不能复现的 bug 就不是 bug (
    zunceng
    zunceng
    Oct 23, 2020❤️1
    4
    http 框架里面集成一个 pprof 中间件 做好了以后一行代码就好了 如果是 gin 直接用下面的
    https://github.com/gin-contrib/pprof
    monsterxx03
    monsterxx03
    Oct 23, 2020
    5
    https://github.com/monsterxx03/gospy

    可以不改代码打印正在跑的 goroutine, 不过好像并不能帮你调试某个函数慢的问题
    polythene
    polythene
    Oct 23, 2020
    6
    Linux 下的 perf 能直接读取 Go 进程的符号值
    TypeErrorNone
    TypeErrorNone
    Oct 23, 2020
    7
    @zunceng 如果有几十个容器,怎么搞呢
    kiddingU
    kiddingU
    Oct 23, 2020
    9
    opentracing 可以定位到是链路中哪个函数慢,然后再去优化
    Lonenso
    Lonenso
    Oct 23, 2020 via Android
    10
    Leigg
    Leigg
    Oct 23, 2020 via Android
    11
    你不能确定函数范围?没上链路追踪就自己挨个打日志
    zunceng
    zunceng
    Oct 23, 2020
    12
    @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   ·   Privacy   ·   Solana   ·   1737 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 16:17 · PVG 00:17 · LAX 08:17 · JFK 11:17
    ♥ Do have faith in what you're doing.