use of com.android.tools.perflib.heap.Heap in project android by JetBrains.
the class ClassHistogramView method generateClassHistogramFromHeapDumpInfos.
void generateClassHistogramFromHeapDumpInfos(@NotNull MemoryDataCache dataCache, @Nullable HeapDumpInfo mainHeapDumpInfo, @Nullable HeapDumpInfo diffHeapDumpInfo) {
// TODO make this method asynchronous
if (myMainHeapDump == null || myMainHeapDump.getInfo() != mainHeapDumpInfo) {
if (myMainHeapDump != null) {
myMainHeapDump.dispose();
myMainHeapDump = null;
}
if (mainHeapDumpInfo != null) {
try {
myMainHeapDump = new HeapDump(dataCache, mainHeapDumpInfo);
} catch (IOException exception) {
getLog().info("Error generating Snapshot from heap dump file.", exception);
return;
}
}
}
if (myDiffHeapDump == null || myDiffHeapDump.getInfo() != diffHeapDumpInfo) {
if (myDiffHeapDump != null) {
myDiffHeapDump.dispose();
myDiffHeapDump = null;
}
if (diffHeapDumpInfo != null) {
try {
myDiffHeapDump = new HeapDump(dataCache, diffHeapDumpInfo);
} catch (IOException exception) {
getLog().info("Error generating Snapshot from heap dump file.", exception);
return;
}
}
}
HeapDump positiveHeapDump = myDiffHeapDump != null ? myDiffHeapDump : myMainHeapDump;
HeapDump negativeHeapDump = myDiffHeapDump != null ? myMainHeapDump : null;
Map<String, Integer> instanceMap = new HashMap<>();
// Compute the positive delta from the next heap dump
if (positiveHeapDump != null) {
for (Heap heap : positiveHeapDump.mySnapshot.getHeaps()) {
for (ClassObj classObj : heap.getClasses()) {
String className = classObj.getClassName();
int instanceCount = classObj.getInstanceCount() + instanceMap.getOrDefault(className, 0);
instanceMap.put(className, instanceCount);
}
}
}
// Subtract the negative delta from the main heap dump
if (negativeHeapDump != null) {
for (Heap heap : negativeHeapDump.mySnapshot.getHeaps()) {
for (ClassObj classObj : heap.getClasses()) {
String className = classObj.getClassName();
int instanceCount = instanceMap.getOrDefault(className, 0) - classObj.getInstanceCount();
instanceMap.put(className, instanceCount);
}
}
}
generateClassHistogram(instanceMap);
}
Aggregations