【Arthas】Arthas 导出堆栈信息

x33g5p2x  于2022-04-06 转载在 其他  
字(1.1k)|赞(0)|评价(0)|浏览(257)

1.概述

转载:Arthas 导出堆栈信息

2. 开篇

arthas提供heapdump命令导出栈信息, 类似jmap命令的heap dump功能。

3.原理介绍

通过通过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);
    }

3.案例

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]$

相关文章