arthas提供heapdump命令导出栈信息, 类似jmap命令的heap dump功能。
通过通过HotSpotDiagnosticMXBean的dumpHeap来导出栈参数。
public interface HotSpotDiagnosticMXBean extends PlatformManagedObject {
void dumpHeap(String var1, boolean var2) throws IOException;
List<VMOption> getDiagnosticOptions();
VMOption getVMOption(String var1);
void setVMOption(String var1, String var2);
}
源码分析
private static void run(CommandProcess process, String file, boolean live) throws IOException {
HotSpotDiagnosticMXBean hotSpotDiagnosticMXBean = ManagementFactory
.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
hotSpotDiagnosticMXBean.dumpHeap(file, live);
}
public class HotSpotDiagnosticMXBeanDemo {
public static void run(String file, boolean live) throws IOException {
HotSpotDiagnosticMXBean hotSpotDiagnosticMXBean = ManagementFactory
.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
hotSpotDiagnosticMXBean.dumpHeap(file, live);
}
}
@Test
public void mainTest() throws IOException {
HotSpotDiagnosticMXBeanDemo.run("/Users/lcc/temp/dump.hprof",true);
}
运行结果
[lcc@lcc ~/IdeaProjects/github]$ ll /Users/lcc/temp/
-rw------- 1 lcc staff 2984396 4 5 19:13 dump.hprof
[lcc@lcc ~/IdeaProjects/github]$
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/qq_21383435/article/details/123975109
内容来源于网络,如有侵权,请联系作者删除!