New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
为使用Alpine Linux作为Docker基础镜像的Java应用提供profiler命令支持 #2481
为使用Alpine Linux作为Docker基础镜像的Java应用提供profiler命令支持 #2481
Conversation
昆泰 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
这样子提交的 so 不可持续更新。 可以考虑先 fork 一个 async-profiler,然后利用 github action + qemu 编译不同平台的 so 。 可以参考: https://github.com/alibaba/arthas/blob/arthas-all-3.6.8/.github/workflows/build-vmtool.yaml#L55 |
1. 使用build-async-profiler.yml workflow 构建出的 async-profiler 2.10 版本动态链接库文件(.so)测试情况2.使用build-async-profiler.yml workflow 构建时的已知问题使用build-async-profiler.yml workflow 构建时,偶尔会遇到 invalid flag: --source 的错误:
Action: 实际上是 -source 7,async-profiler 的作者已经在近期的一个 commit 中改掉了。实际上遇到这个问题时,终止当前构建任务,重试即可。 3.使用build-async-profiler.yml workflow 构建出的 libasyncProfiler-xxx.so 使用时已知问题在 arthas 命令行执行 profiler start -d 60 命令时, 目标Java进程标准输出日志显示:
这是 async-profiler 2.7 版本引入的 change: - Do not accept unknown agent arguments Action: 需要 arthas 侧修改 framebuf 参数,让 libasyncProfiler-xxx.so 能识别出来,当前不影响 profiler 命令的使用,可稍后修改 arthas profiler 发出的命令进行优化。 |
* Support profiler command in Alpine Linux, support musl libc * Add pipeline for building Alpine Linux async-profiler dynamic link library files --------- Co-authored-by: 昆泰 <dongyun.tdy@alibaba-inc.com>
问题背景
在 arthas cli 命令行,可使用 profiler 命令支持生成应用热点的火焰图,背后使用了 async-profiler 提供支持。在 Linux 环境下,async-profiler 默认只对 x86-64、aarch64 这两种操作系统架构提供了 glibc 版的动态链接库文件:
但是在基于 musl libc 实现的 Alpine Linux 环境下,执行 profiler 命令会误加载到 libasyncProfiler-linux-x64.so 或者 libasyncProfiler-linux-arm64.so ,首先会提示缺少 libstdc++、libgcc 库文件,手工执行下面的命令安装后,再次执行 profiler 命令会造成应用 jvm 进程 crash :
hs_err_pid17.log
然后在 Alpine Linux 环境下查看基于 Alpine Linux 环境手工编译的 libasyncProfiler 和原始的基于 glibc + xxx Linux 环境编译的 libasyncProfiler,可以看到如下区别:
我提了一个 issue #741给 async-profiler ,async-profiler 的开发者建议我根据需要自行编译 libasyncProfiler
考虑到在 K8s 集群环境下,使用 Alpine Linux 作为 Java 应用基础镜像的用户比较多,所以这里考虑增加对 Alpine Linux x86-64 和 aarch64 这两种操作系统环境下使用 profiler 进行支持。
主要改动代码
基于 async-profiler 源码和Alpine Linux x86-64 和 aarch64 这两种操作系统的 docker 镜像构建环境打包 libasyncProfiler so
Note: 这里默认将 libstdc++ 和 libgcc 作为静态依赖打进 libasyncProfiler so 文件,使客户在 Alpine Linux 环境下为了使用 arthas 的 profiler 命令时,不再需要单独安装 libstdc++ 和 libgcc.
生成的两个 libasyncProfiler so 文件:
libasyncProfiler-linux-musl-amd64.so
libasyncProfiler-linux-musl-arm64.so
libasyncProfiler so 文件加载入口处代码:
core/src/main/java/com/taobao/arthas/core/command/monitor200/ProfilerCommand.java
测试情况