我想知道线上环境中某个类中的Map的某个固定key值对应的value,所以在线上生成了dump文件拿到MAT中解析
但是由于Map中包含了几万个Entry,在mat工具上没有办法根据key值直接定位,所以在想是否能使用代码解析hprof文件,从里面读取内容直接转换成能查看Map信息
百度过程中看到有人使用eclipse mat的api取读取hprof文件,我自己仿写了一下(我运行在linux环境)
import org.eclipse.mat.snapshot.ISnapshot;
import org.eclipse.mat.snapshot.SnapshotFactory;
import org.eclipse.mat.util.ConsoleProgressListener;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Objects;
public class DumpTest {
public static void main(String[] args) throws Exception {
String hprofFile = "/root/Downloads/javaDump.hprof";
ConsoleProgressListener listener = new ConsoleProgressListener(System.out);
ISnapshot snapshot = SnapshotFactory.openSnapshot(new File(hprofFile), listener);
snapshot.dispose();
System.out.println();
}
}
但是运行报错
Exception in thread "main" java.lang.ExceptionInInitializerError
at DumpTest.main(DumpTest.java:27)
Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.core.runtime.IExtensionRegistry.getExtensionPoint(String)" because the return value of "org.eclipse.core.runtime.Platform.getExtensionRegistry()" is null
at org.eclipse.mat.snapshot.SnapshotFactory.<clinit>(SnapshotFactory.java:88)
... 1 more
Process finished with exit code 1
是否有人尝试过使用eclipse.mat的api读取dump文件成功的?或者其他方式也可以