private boolean addToGroup(ObjectInfo info, String group) { if (!groups.containsKey(info)) { groups.put(info, group); HeapHistogram histogram = groupHistograms.get(group); if (histogram == null) { histogram = new HeapHistogram(); groupHistograms.put(group, histogram); } histogram.add(info, info.getSize()); return true; } else { return false; } } }
public void print() { assert NativeImageOptions.PrintHeapHistogram.getValue(); HistogramEntry[] entries = data.values().toArray(new HistogramEntry[data.size()]); Arrays.sort(entries, SIZE_COMPARATOR); long totalSize = getTotalSize(); long printedSize = 0; for (HistogramEntry entry : entries) { printedSize += entry.size; System.out.format(entryFormat, entry.count, entry.size, entry.size * 100d / totalSize, printedSize * 100d / totalSize, entry.clazz.toJavaName()); } }
HeapHistogram totalHistogram = new HeapHistogram(); for (ObjectInfo info : objects) { totalHistogram.add(info, info.getSize()); addToGroup(info, "Other"); totalHistogram.printHeadings("=== Total ==="); totalHistogram.print(); entry.getValue().printHeadings("=== " + entry.getKey() + " ==="); entry.getValue().print(); System.out.println("=== Summary ==="); for (Map.Entry<String, HeapHistogram> entry : groupHistograms.entrySet()) { System.out.format("%s; %d; %d\n", entry.getKey(), entry.getValue().getTotalCount(), entry.getValue().getTotalSize()); System.out.format("%s; %d; %d\n", "Total", totalHistogram.getTotalCount(), totalHistogram.getTotalSize());
void printHistogram() { final HeapHistogram histogram = new HeapHistogram(); final Set<ObjectInfo> uniqueObjectInfo = new HashSet<>(); long uniqueCount = 0L; if (info.getPartition() == this) { if (uniqueObjectInfo.add(info)) { histogram.add(info, info.getSize()); uniqueCount += 1L; uniqueSize += info.getSize(); final double countPercent = 100.0D * ((double) uniqueCount / (double) nonuniqueCount); final double sizePercent = 100.0D * ((double) uniqueSize / (double) nonuniqueSize); histogram.printHeadings(String.format("=== Partition: %s count: %d / %d = %.1f%% size: %d / %d = %.1f%% ===", // histogram.print();