Install
openclaw skills install java-perf-analyzerJava 应用性能分析与诊断工具。基于 Arthas + MCP 实现远程 JVM 分析。**触发条件**:用户描述 Java 应用性能问题或诊断需求,包括:(1) 直接描述问题现象(CPU飙高、内存泄漏/紧张、接口响应慢、线程阻塞/死锁、类加载异常)(2) 请求 JVM 分析、Arthas 排查、性能诊断 (3) 说"帮我排查 xxx 问题"或"分析下 xxx 性能"。触发后先了解问题现象,再针对性收集信息、执行分析。
openclaw skills install java-perf-analyzer基于 Arthas 的远程 JVM 性能分析工具,支持生产环境无侵入诊断。
触发后,先了解用户遇到的具体问题,不要急着问参数。
询问模板:
遇到什么问题?
- CPU 飙高?
- 内存紧张/泄漏?
- 接口响应慢?
- 线程阻塞/死锁?
- 类加载异常?
描述一下现象,我来针对性分析。
根据用户描述的问题,选择对应的分析方法:
| 问题类型 | 首选分析 | 需要额外信息 |
|---|---|---|
| CPU 飙高 | thread -n 5 找忙线程 | 无 |
| 内存紧张 | jvm + memory 查使用率 | 无 |
| 内存泄漏 | heapdump + 离线分析 | 可能需要转储路径 |
| 接口慢 | trace 方法耗时 | 需要源码定位方法 |
| 线程阻塞 | thread --state BLOCKED | 无 |
| 类加载问题 | sc + jad + classloader | 类名 |
执行分析前,检查 MEMORY.md 是否已有:
有配置 → 直接执行分析 无配置 → 询问缺少的信息(只问必要的)
只收集 当前分析需要的信息:
| 信息 | 何时需要 | 示例 |
|---|---|---|
| SSH 地址 | 无配置时 | trythis.cn |
| SSH 用户名 | 无配置时 | root |
| SSH 密码 | 无配置时 | (用户提供) |
| Java 进程名 | 无配置时 | chat-editor |
| 源码地址 | 分析慢接口时 | /root/workspace/project |
| 类名 | 分析类加载问题时 | UserService |
不要一次性问所有信息,按需询问。
首次使用:运行安装脚本
scripts/install-arthas.sh <ssh-host> <ssh-user> <ssh-password> <arthas-dir> <process-name>
已有配置:确认 SSH 隧道和 MCP 连接
# 检查隧道
ps aux | grep "ssh.*8563"
# 测试连接
mcporter call arthas jvm_info
根据 Phase 2 确定的策略,执行对应的分析命令。分析完成后:
根据用户描述的问题,选择合适的分析命令。
源码可用于:
示例:
# 先在源码中搜索
grep -r "class UserService" <源码路径>
# 找到类名后追踪
mcporter call arthas method_trace --args '{"classMethod":"com.xxx.UserService#getUser"}'
mcporter call arthas jvm_info
输出关键指标:
# 最忙的 N 个线程
mcporter call arthas thread_info --args '{"threadId":"-n 10"}'
# 按状态筛选
mcporter call arthas arthas_command command='thread --state BLOCKED'
# 线程详情
mcporter call arthas arthas_command command='thread <thread-id>'
# 内存概览
mcporter call arthas arthas_command command='memory'
# 堆转储(用于离线分析)
mcporter call arthas arthas_command command='heapdump /path/to/dump.hprof'
# 查看大对象
mcporter call arthas arthas_command command='vmtool --action getInstances --className java.lang.Object --limit 10'
# 追踪方法调用耗时
mcporter call arthas method_trace --args '{"classMethod":"com.example.UserService#getUser"}'
# 监控方法参数和返回值
mcporter call arthas watch_method --args '{"classMethod":"com.example.UserService#getUser"}'
# 高级追踪(带条件)
mcporter call arthas arthas_command command='trace com.example.Service#method "#cost > 100"'
# 搜索类
mcporter call arthas class_info --args '{"className":"*Service"}'
# 反编译类
mcporter call arthas decompile_class --args '{"className":"com.example.UserService"}'
# 查看类加载器
mcporter call arthas arthas_command command='classloader -t'
# 启动 30 秒采样
mcporter call arthas arthas_command command='profiler start --event cpu --duration 30'
# 停止并生成火焰图
mcporter call arthas arthas_command command='profiler stop --format html'
# 下载火焰图(SSH)
scp <ssh-user>@<ssh-host>:/path/to/arthas-output/*.html ./flamegraph.html
1. thread -n 5 → 找最忙线程
2. thread <id> → 查线程堆栈
3. trace <method> → 追踪热点方法
4. profiler start/stop → 生成火焰图
1. jvm → 查内存使用率
2. memory → 查各区域详情
3. heapdump → 堆转储离线分析
4. vmtool getInstances → 查大对象
1. trace <class>#<method> "#cost > 100" → 找慢方法
2. watch <class>#<method> "{params,returnObj,#cost}" → 看参数耗时
3. stack <class>#<method> → 查调用来源
1. sc -d <class> → 查类信息
2. jad <class> → 反编译看实际代码
3. classloader -t → 查加载器树
~/.openclaw/workspace/config/mcporter.json:
{
"mcpServers": {
"arthas": {
"command": "node",
"args": ["/root/.openclaw/workspace/arthas-mcp-stdio.js"]
}
}
}
MCP 脚本见 scripts/arthas-mcp-stdio.js。
见 references/arthas-commands.md。
⚠️ 生产环境慎用:
trace/watch 有性能开销,高峰期避免长时间追踪heapdump 会暂停应用,大堆可能卡住stop 停止追踪✅ 最佳实践:
-n 限制结果数量#cost > 100