阿里云的Arthas(阿尔萨斯)是一个强大的Java诊断工具,它提供了许多方便的命令来帮助开发者在不重启应用的情况下进行问题定位和性能调试。以下是一些常用的Arthas命令:
1、asm: 查看类的字节码,例如 asm com.example.YourClass。
2、class: 查看类的详细信息,如类路径、加载器、接口、注解等,例如 class com.example.YourClass。
3、console: 打开一个新的命令行交互式控制台,可以在这里输入Arthas命令。
4、dashboard: 提供一个Web界面,展示应用程序的运行状态,包括JVM信息、线程、内存等,可以输入 dashboard 启动。
5、ddd: 分析类的依赖关系,例如 ddd com.example.YourClass。
6、echo: 打印字符串或表达式的值,例如 echo "Hello, Arthas!" 或 echo $System.getProperty('java.version')。
7、find: 根据正则表达式搜索类或方法,例如 find com.example.** --regex .*YourMethod.*。
8、gc: 强制执行一次垃圾回收,例如 gc。
9、jvm: 查看JVM相关信息,如版本、配置、JVM参数等,例如 jvm。
10、list: 列出指定类的所有方法,例如 list com.example.YourClass。
11、monitor: 监控方法的执行,例如 monitor com.example.YourClass YourMethod 'System.out.println(args[0])'。
12、notify: 当满足特定条件时触发通知,例如 notify com.example.YourClass YourMethod 'if (args[0] == "value") print("Matched!");'。
13、profile: 对方法进行性能分析,例如 profile com.example.YourClass YourMethod -f。
14、sc: 列出已经加载的类,例如 sc。
15、tdump: 输出线程堆栈信息,例如 tdump。
16、thread: 查看和管理线程,例如 thread列出所有线程,thread -s列出所有阻塞的线程。
17、trace: 跟踪方法的调用,例如 trace com.example.YourClass YourMethod 'print("Method called with args: " + Arrays.toString(args))'。
18、watch: 监控变量或表达式的变化,例如 watch com.example.YourClass setYourVariable 'System.out.println("YourVariable updated to: " + $1)'。
使用Arthas时,你可以通过--help选项获取命令的详细用法,例如 asm --help。此外,可以使用 exit 或 quit 命令退出Arthas控制台。
请注意,Arthas命令的更新和扩展是持续进行的,因此建议访问官方文档以获取最新的命令列表和详细信息: Arthas Tutorials (aliyun.com)
如果你有特定的需求,比如想要监视CPU使用率最高的线程,可以使用dashboard或top -p命令,而想要查看死锁情况,可以使用thread -l命令