当前位置:网站首页>阿里的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命令。
更多的功能可以查看进阶使用。
边栏推荐
- Chrome 开发者工具 performance 标签页的用法
- Aura clock chip generation configuration file script
- Yuanguo chain game system development
- Defaced Fingerprint Recovery and Identification
- The establishment of simple data cache layer
- Openharmony first experience (1)
- nr part calculation
- nr部分计算
- Go study notes (Part 1) Configuring the Go development environment
- SQL Server 遇到报错解决办法--更新中
猜你喜欢
随机推荐
Finished product upgrade program
用“绿色计算“技术推动算力可持续发展
JS手写JSON.stringify() (面试)
lds链接的 顺序问题
Dragoma(DMA)元宇宙系统开发
二叉树的前序遍历
In July 2022, domestic database memorabilia
MYSQL gets the table name and table comment of the database
visual studio 与 visual studio code
Yuanguo chain game system development
The book "The Essence of Alipay Experience Design", a record of knowledge related to testing
June To -.-- -..- -
zynq records
【着色器实现Glitch单项故障闪烁效果(与Television效果不同)_Shader效果第十四篇】
v-model的使用
T+Cloud: A "Smart Company" for Building New Business Social Networks and Marketing Relationships
蚂蚁集团时序数据库CeresDB正式开源
NLP技术为何在工业界这么卷?前沿案例解析来了
seata源码解析:seata server各种消息处理流程
使用 Chrome 开发者工具的 lighthouse 功能分析 web 应用的性能问题









