当前位置:网站首页>阿里的arthas使用,入门报错:Unable to attach to 32-bit process running under WOW64
阿里的arthas使用,入门报错:Unable to attach to 32-bit process running under WOW64
2022-08-04 19:46:00 【爱的叹息】
学会 Arthas,让你 3 年经验掌握 5 年功力!
学会 Arthas,让你 3 年经验掌握 5 年功力! (qq.com)
简介
Arthas 是Alibaba开源的Java诊断工具,动态跟踪Java代码;实时监控JVM状态,可以在不中断程序执行的情况下轻松完成JVM相关问题排查工作 。支持JDK 6+,支持Linux/Mac/Windows。这个工具真的很好用,而且入门超简单,十分推荐。
使用场景
这个类从哪个 jar 包加载的?为什么会报各种类相关的 Exception?
我改的代码为什么没有执行到?难道是我没 commit?分支搞错了?
遇到问题无法在线上 debug,难道只能通过加日志再重新发布吗?
线上遇到某个用户的数据处理有问题,但线上同样无法 debug,线下无法重现!
是否有一个全局视角来查看系统的运行状况?
有什么办法可以监控到JVM的实时运行状态?接下来,围绕这6个问题,学习下Arthas的基本用法。

执行curl的时候会下载文件
在path中把JAVA_HOME变量放到最前面
保存环境变量配置后,重启cmd,执行java -version

启动 math-game
已经切换为64位jre了,然后在运行
curl -O https://arthas.aliyun.com/math-game.jar
java -jar math-game.jar 
启动 arthas
再起cmd,执行
curl -O https://arthas.aliyun.com/arthas-boot.jar
java -jar arthas-boot.jar 
选择刚才执行的math-game.jar,即4然后回车

如上表示连接成功
查看 dashboard
输入dashboard,按回车/enter,会展示当前进程的信息,按ctrl+c可以中断执行。
通过 thread 命令来获取到math-game进程的 Main Class
thread 1会打印线程 ID 1 的栈,通常是 main 函数的线程。

通过 jad 来反编译 Main Class
例如:
jad demo.MathGamedemo.MathGame是报名+类名
[[email protected]]$ jad demo.MathGame
ClassLoader:
[email protected]
[email protected]
Location:
/C:/Users/35725/math-game.jar
/*
* Decompiled with CFR.
*/
package demo;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
public class MathGame {
private static Random random = new Random();
private int illegalArgumentCount = 0;
public static void main(String[] args) throws InterruptedException {
MathGame game = new MathGame();
while (true) {
/*16*/ game.run();
/*17*/ TimeUnit.SECONDS.sleep(1L);
}
}
public void run() throws InterruptedException {
try {
/*23*/ int number = random.nextInt() / 10000;
/*24*/ List<Integer> primeFactors = this.primeFactors(number);
/*25*/ MathGame.print(number, primeFactors);
}
catch (Exception e) {
/*28*/ System.out.println(String.format("illegalArgumentCount:%3d, ", this.illegalArgumentCount) + e.getMessage());
}
}
public static void print(int number, List<Integer> primeFactors) {
StringBuffer sb = new StringBuffer(number + "=");
/*34*/ for (int factor : primeFactors) {
/*35*/ sb.append(factor).append('*');
}
/*37*/ if (sb.charAt(sb.length() - 1) == '*') {
/*38*/ sb.deleteCharAt(sb.length() - 1);
}
/*40*/ System.out.println(sb);
}
public List<Integer> primeFactors(int number) {
/*44*/ if (number < 2) {
/*45*/ ++this.illegalArgumentCount;
throw new IllegalArgumentException("number is: " + number + ", need >= 2");
}
ArrayList<Integer> result = new ArrayList<Integer>();
/*50*/ int i = 2;
/*51*/ while (i <= number) {
/*52*/ if (number % i == 0) {
/*53*/ result.add(i);
/*54*/ number /= i;
/*55*/ i = 2;
continue;
}
/*57*/ ++i;
}
/*61*/ return result;
}
}
Affect(row-cnt:1) cost in 392 ms.
[[email protected]]$watch
通过watch命令来查看demo.MathGame#primeFactors函数的返回值:
例如
watch demo.MathGame primeFactors returnObj 
退出 arthas
如果只是退出当前的连接,可以用quit或者exit命令。Attach 到目标进程上的 arthas 还会继续运行,端口会保持开放,下次连接时可以直接连接上。
如果想完全退出 arthas,可以执行stop命令。
更多的功能可以查看进阶使用。
边栏推荐
猜你喜欢
随机推荐
visual studio 与 visual studio code
seata源码解析:seata server各种消息处理流程
5 g NR notes
really time ntp service start command
JS new一个构造器发生了什么?从零手写一个new方法
c sqlite ... ...
awk 统计平均 最大 最小值
Query the published version records of the APP Store
[Awards for Essays] Autumn recruitment special training to create your exclusive product experience
Infrared image filtering
To -.-- -..- -
[Latest Information] 2 new regions will announce the registration time for the soft exam in the second half of 2022
Regular expression is incomplete
02 ts 变量定义,类型
如何给MySQL添加自定义语法 ?
元国度链游系统开发
T+Cloud:构建新型生意社交网络和营销关系的“智公司”
Zip4j使用
zynq records
Jmeter - Heap配置原因报错Invalid initial heap size: -Xms1024m -Xmx2048mError








