项目概况

class/classloader相关

2026-01-292 min read后端技术
Arthas

一、启动Arthas

text
1curl -O https://arthas.aliyun.com/arthas-boot.jar 2java -jar arthas-boot.jar

启动命令 java -jar arthas-boot.jar

二、选择进程

直接选择我们要监控的进程,输入3进入

text
1[INFO] Attach process 28667 success. 2[INFO] arthas-client connect 127.0.0.1 3658 3 ,---. ,------. ,--------.,--. ,--. ,---. ,---. 4 / O | .--. ''--. .--'| '--' | / O ' .-' 5| .-. || '--'.' | | | .--. || .-. |`. `-. 6| | | || | | | | | | || | | |.-' | 7`--' `--'`--' '--' `--' `--' `--'`--' `--'`-----' 8 9wiki https://arthas.aliyun.com/doc 10tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html 11version 3.5.6 12main_class com.example.demo.DemoApplication 13pid 28667 14time 2022-03-13 21:31:04

提示已经连接上进程。

三、基础信息查询命令

3.1 dashboard 看板命令

输入 dashboard

会定时将应用信息输出到控制台上。

3.2 jad 反向编译

jad com.example.demo.DemoApplication

3.3 watch 监控指令

这个命令是比较常用的命令,可以用来分析系统性能。

java
1package com.example.demo; 2 3import org.springframework.web.bind.annotation.GetMapping; 4import org.springframework.web.bind.annotation.ResponseBody; 5import org.springframework.web.bind.annotation.RestController; 6@RestController 7public class WebController { 8 9 @GetMapping("/get") 10 @ResponseBody 11 public String get(String name) { 12 return name; 13 } 14}

监控这个类 watch com.example.demo.WebController get returnObj

参数名含义
returnObj返回值
params入参
target方法调用方

watch com.example.demo.WebController get {params,returnObj,target}

text
1[arthas@32818]$ watch com.example.demo.WebController get returnObj 2Press Q or Ctrl+C to abort. 3Affect(class count: 1 , method count: 1) cost in 120 ms, listenerId: 1 4method=com.example.demo.WebController.get location=AtExit 5ts=2022-03-13 21:41:56; [cost=1.317166ms] result=@String[123] 6method=com.example.demo.WebController.get location=AtExit 7ts=2022-03-13 21:42:03; [cost=0.051875ms] result=@String[测试]

四、退出

输入 q