当前位置:网站首页>阿里的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命令。
更多的功能可以查看进阶使用。
边栏推荐
- 使用.NET简单实现一个Redis的高性能克隆版(二)
- 二叉树是否对称
- Polygon zkEVM 基本概念
- Query the published version records of the APP Store
- Highlights of some performance tests
- Order of lds links
- Switch node version and switch npm source tool
- June To -.-- -..- -
- getBoundingClientRect
- "WAIC 2022 · hackers marathon" two ants wealth competition invited you to fight!
猜你喜欢
随机推荐
Query the published version records of the APP Store
NLP技术为何在工业界这么卷?前沿案例解析来了
SAP UI5 确保控件 id 全局唯一的实现方法
Polygon zkEVM 基本概念
正则表达式未完
02 ts 变量定义,类型
Industrial CCD and CMOS camera
编译optimize源码实现过程
T+Cloud:构建新型生意社交网络和营销关系的“智公司”
String中的hashcode缓存以及HashMap中String作key的好处
SIGIR 2022 | 邻域建模Graph-Masked Transformer,显著提高CTR预测性能
奥拉时钟芯片生成配置文件脚本
Jmeter - Heap配置原因报错Invalid initial heap size: -Xms1024m -Xmx2048mError
QT 小知识随记
Internship: changed the requirements
用“绿色计算“技术推动算力可持续发展
"WAIC 2022 · hackers marathon" two ants wealth competition invited you to fight!
Aura clock chip generation configuration file script
Order of lds links
如何给MySQL添加自定义语法 ?









