V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
hengyunabc
V2EX  ›  推广

阿里巴巴 Arthas 3.1.5 版本支持火焰图,快速定位应用热点

  •  
  •   hengyunabc · 2019-11-27 11:28:02 +08:00 · 3050 次点击
    这是一个创建于 1583 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Arthas

    Arthas是 Alibaba 开源的 Java 诊断工具,深受开发者喜爱。

    Arthas 3.1.5 版本带来下面全新的特性:

    • 开箱即用的 Profiler/火焰图功能
    • grep 命令支持更丰富的选项
    • monitor/tt/trace 等命令提供更精确的时间统计
    • telnet/http 协议共用 3658 端口

    Profiler/Frame Graph/火焰图

    火焰图的威名相信大家都有所耳闻,但可能因为使用比较复杂,所以望而止步。

    在新版本的 Arthas 里集成了async-profiler,使用profiler命令就可以很方便地生成火焰图,并且可以在浏览器里直接查看。

    profiler 命令基本运行结构是 profiler action [actionArg]。下面介绍如何使用。

    启动 profiler

    $ profiler start
    Started [cpu] profiling
    

    默认情况下,生成的是 cpu 的火焰图,即 event 为cpu。可以用--event参数来指定。

    获取已采集的 sample 的数量

    $ profiler getSamples
    23
    

    查看 profiler 状态

    $ profiler status
    [cpu] profiling is running for 4 seconds
    

    可以查看当前 profiler 在采样哪种event和采样时间。

    生成 svg 格式结果

    $ profiler stop
    profiler output file: /tmp/demo/arthas-output/20191125-135546.svg
    OK
    

    默认情况下,生成的结果保存到应用的工作目录下的arthas-output目录里。

    通过浏览器查看 arthas-output 下面的 profiler 结果

    默认情况下,arthas 使用 3658 端口,则可以打开: http://localhost:3658/arthas-output/ 查看到arthas-output目录下面的 profiler 结果:

    点击可以查看具体的结果:

    如果是 chrome 浏览器,可能需要多次刷新。

    grep 命令支持更丰富的选项

    标准的 linux grep 命令支持丰富的选项,可以很方便地定位结果的上下文等。

    新版本的grep命令支持更多标准的选项,下面是一些例子:

    sysprop | grep java
    sysprop | grep java -n
    sysenv | grep -v JAVA
    sysenv | grep -e "(?i)(JAVA|sun)" -m 3  -C 2
    sysenv | grep JAVA -A2 -B3
    thread | grep -m 10 -e  "TIMED_WAITING|WAITING"
    

    感谢社区里 @qxo 的贡献。

    telnet/http 协议共用 3658 端口

    默认情况下,Arthas 的 Telnet 端口是 3658,HTTP 端口是 8563,这个常常让用户迷惑。在新版本里,在 3658 端口同时支持 Telnet/HTTP 协议。

    在浏览器里访问 http://localhost:3658/ 也可以访问到 Web Console 了。

    在后续的版本里,考虑默认只侦听 3658 端口,减少用户的配置项。

    monitor/tt/trace 等命令提供更精确的时间统计

    以前 Arthas 被诟病比较多的一个问题是,monitor/tt/trace 等命令时间统计误差大。因为以前只使用了一个 int 来保存时间,所以不精确。

    在新版本里,改用一个高效的 stack 来保存数据,时间的准确度大大提升,欢迎大家反馈效果。

    感谢社区里 @huangjIT 的贡献。

    总结

    总之,3.1.5版本的 Arthas 引入了开箱即用的 Profiler/火焰图功能,欢迎大家使用反馈。

    最后,Arthas 正在参加 2019 年度最受欢迎开源中国软件评选,急需大家宝贵的一票支持!!查看

    投票后可以到 issue 里抽奖两本图书,https://github.com/alibaba/arthas/issues/951:

    • 《 OpenShift 在企业中的实践-PasS DevOps 微服务》
    • 《协同-数字化时代组织效率的本质》
    7 条回复    2020-03-14 10:25:24 +08:00
    liprais
        1
    liprais  
       2019-11-27 11:29:04 +08:00   ❤️ 1
    @livid 疑似推广
    shintendo
        2
    shintendo  
       2019-11-27 11:34:59 +08:00
    阿……阿尔萨斯?
    Kymair
        3
    Kymair  
       2019-11-27 12:09:33 +08:00
    我是 Arthas 用户,非常棒的工具,好几次解决了线上的疑难杂症,🙏

    火焰图很好啊,过几天试试
    90928yao
        4
    90928yao  
       2019-11-27 14:54:36 +08:00
    Arthas 是我对我帮助最大的开源软件之一了(非五毛)
    DsuineGP
        5
    DsuineGP  
       2019-11-27 16:00:50 +08:00
    这玩意线上 debug 确实好用(五毛一条)
    lazyfighter
        6
    lazyfighter  
       2019-11-27 16:16:21 +08:00
    牛皮了
    kaiser1992
        7
    kaiser1992  
       2020-03-14 10:25:24 +08:00
    阿尔萨斯在线上用,如何解决对线上性能的影响?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   930 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:53 · PVG 04:53 · LAX 13:53 · JFK 16:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.