您现在的位置是:首页 > 文章详情

Arthas 发布 3.5.6 版本:应用排包瘦身不再烦恼

日期:2022-03-04点击:642

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

Arthas 最新发布了 3.5.6 版本:

  1. 支持统计ClassLoader实际使用URL和未使用的URL

  2. 增加memory命令

  3. 恢复对 enum 类增强支持,过滤掉的类在日志中打印具体原因。

classloader 命令支持统计实际使用URL和未使用的URL

随着应用越来越复杂,依赖的jar包越来越多,我们想对应用做瘦身,但会有很多顾虑。因为不清楚哪些jar包是没被使用的😂。

因此,Arthas在classloader命令里增加URL使用统计功能,方便排除未使用jar包。

使用--url-stat参数,则会打印出所有ClassLoader的Used URLsUnused URLs

 $ classloader --url-stat com.taobao.arthas.agent.ArthasClassloader@3c41660, hash:3c41660 Used URLs: file:/Users/admin/.arthas/lib/3.5.6/arthas/arthas-core.jar Unused URLs: sun.misc.Launcher$AppClassLoader@75b84c92, hash:75b84c92 Used URLs: file:/Users/admin/code/java/arthas/math-game/target/math-game.jar file:/Users/admin/.arthas/lib/3.5.6/arthas/arthas-agent.jar Unused URLs: sun.misc.Launcher$ExtClassLoader@7f31245a, hash:7f31245a Used URLs: file:/tmp/jdk1.8/Contents/Home/jre/lib/ext/sunec.jar file:/tmp/jdk1.8/Contents/Home/jre/lib/ext/sunjce_provider.jar file:/tmp/jdk1.8/Contents/Home/jre/lib/ext/localedata.jar Unused URLs: file:/tmp/jdk1.8/Contents/Home/jre/lib/ext/nashorn.jar file:/tmp/jdk1.8/Contents/Home/jre/lib/ext/cldrdata.jar ... 

注意,基于JVM目前已加载的所有类统计,不代表Unused URLs可以从应用中删掉。因为可能将来需要从Unused URLs里加载类,或者需要加载resources。

memory命令

  • https://arthas.aliyun.com/doc/memory.html

memory命令可以查看JVM内存信息。 因为之前使用dashboard命令查看内存信息时,因为窗口有限,输出可能被截断,因此提供单独的memory命令。

 $ memory Memory used total max usage heap 32M 256M 4096M 0.79% g1_eden_space 11M 68M -1 16.18% g1_old_gen 17M 184M 4096M 0.43% g1_survivor_space 4M 4M -1 100.00% nonheap 35M 39M -1 89.55% codeheap_'non-nmethods' 1M 2M 5M 20.53% metaspace 26M 27M -1 96.88% codeheap_'profiled_nmethods' 4M 4M 117M 3.57% compressed_class_space 2M 3M 1024M 0.29% codeheap_'non-profiled_nmethods' 685K 2496K 120032K 0.57% mapped 0K 0K - 0.00% direct 48M 48M - 100.00% 

恢复对 enum 类增强支持,过滤掉的类在日志中打印具体原因

当我们尝试watch java package里的类时:

 watch java.util.concurrent.TimeUnit convert 

~/logs/arthas/arthas.log里会打印具体原因:

 2022-03-01 22:31:55 [arthas-command-execute] INFO c.t.arthas.core.advisor.Enhancer -ignore class: java.util.concurrent.TimeUnit, reson: class loaded by Bootstrap Classloader, try to execute `options unsafe true` 

如果按提示执行options unsafe true,则可以成功watch。

总结

原文链接:https://www.oschina.net/news/184999
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章