in analysis/heap-dump/impl/src/main/java/org/eclipse/jifa/hda/impl/HeapDumpAnalyzerImpl.java [1125:1212]
public LeakReport getLeakReport() {
return $(() -> {
AnalysisContext.LeakReportData data = context.leakReportData.get();
if (data == null) {
synchronized (context) {
data = context.leakReportData.get();
if (data == null) {
IResult result = queryByCommand(context, "leakhunter");
data = new AnalysisContext.LeakReportData();
data.result = result;
context.leakReportData = new SoftReference<>(data);
}
}
}
IResult result = data.result;
LeakReport report = new LeakReport();
if (result instanceof TextResult) {
report.setInfo(((TextResult) result).getText());
} else if (result instanceof SectionSpec) {
report.setUseful(true);
SectionSpec sectionSpec = (SectionSpec) result;
report.setName(sectionSpec.getName());
List<Spec> specs = sectionSpec.getChildren();
for (int i = 0; i < specs.size(); i++) {
QuerySpec spec = (QuerySpec) specs.get(i);
String name = spec.getName();
if (name == null || name.isEmpty()) {
continue;
}
// LeakHunterQuery_Overview
if (name.startsWith("Overview")) {
IResultPie irtPie = (IResultPie) spec.getResult();
List<? extends IResultPie.Slice> pieSlices = irtPie.getSlices();
List<LeakReport.Slice> slices = new ArrayList<>();
for (IResultPie.Slice slice : pieSlices) {
slices.add(
new LeakReport.Slice(slice.getLabel(),
Helper.fetchObjectId(slice.getContext()),
slice.getValue(), slice.getDescription()));
}
report.setSlices(slices);
}
// LeakHunterQuery_ProblemSuspect
// LeakHunterQuery_Hint
else if (name.startsWith("Problem Suspect") || name.startsWith("Hint")) {
LeakReport.Record suspect = new LeakReport.Record();
suspect.setIndex(i);
suspect.setName(name);
CompositeResult cr = (CompositeResult) spec.getResult();
List<CompositeResult.Entry> entries = cr.getResultEntries();
for (CompositeResult.Entry entry : entries) {
String entryName = entry.getName();
if (entryName == null || entryName.isEmpty()) {
IResult r = entry.getResult();
if (r instanceof QuerySpec &&
// LeakHunterQuery_ShortestPaths
((QuerySpec) r).getName().equals("Shortest Paths To the Accumulation Point")) {
IResultTree tree = (IResultTree) ((QuerySpec) r).getResult();
RefinedResultBuilder builder = new RefinedResultBuilder(
new SnapshotQueryContext(context.snapshot), tree);
RefinedTree rst = (RefinedTree) builder.build();
List<?> elements = rst.getElements();
List<LeakReport.ShortestPath> paths = new ArrayList<>();
suspect.setPaths(paths);
for (Object row : elements) {
paths.add(buildPath(context.snapshot, rst, row));
}
}
}
// LeakHunterQuery_Description
// LeakHunterQuery_Overview
else if ((entryName.startsWith("Description") || entryName.startsWith("Overview"))) {
TextResult desText = (TextResult) entry.getResult();
suspect.setDesc(desText.getText());
}
}
List<LeakReport.Record> records = report.getRecords();
if (records == null) {
report.setRecords(records = new ArrayList<>());
}
records.add(suspect);
}
}
}
return report;
});
}