use of com.android.tools.perflib.heap.ClassObj in project android_frameworks_base by DirtyUnicorns.
the class Hprof method analyzeHprof.
/**
* Return a map of class names to class-loader names derived from the hprof dump.
*
* @param hprofLocalFile
*/
public static Map<String, String> analyzeHprof(File hprofLocalFile) throws Exception {
Snapshot snapshot = Snapshot.createSnapshot(new MemoryMappedFileBuffer(hprofLocalFile));
Map<String, Set<ClassObj>> classes = Queries.classes(snapshot, null);
Map<String, String> retValue = new HashMap<String, String>();
for (Map.Entry<String, Set<ClassObj>> e : classes.entrySet()) {
for (ClassObj c : e.getValue()) {
String cl = c.getClassLoader() == null ? null : c.getClassLoader().toString();
String cName = c.getClassName();
int aDepth = 0;
while (cName.endsWith("[]")) {
cName = cName.substring(0, cName.length() - 2);
aDepth++;
}
String newName = transformPrimitiveClass(cName);
if (aDepth > 0) {
// Need to use kind-a descriptor syntax. If it was transformed, it is primitive.
if (newName.equals(cName)) {
newName = "L" + newName + ";";
}
for (int i = 0; i < aDepth; i++) {
newName = "[" + newName;
}
}
retValue.put(newName, cl);
}
}
// Free up memory.
snapshot.dispose();
return retValue;
}
use of com.android.tools.perflib.heap.ClassObj in project android by JetBrains.
the class ClassesTreeView method restoreViewState.
private void restoreViewState(@NotNull final SelectionModel selectionModel) {
ClassObj classToSelect = selectionModel.getClassObj();
TreeNode nodeToSelect = null;
if (classToSelect != null) {
nodeToSelect = findClassObjNode(classToSelect);
}
sortTree(myRoot);
myTreeModel.nodeStructureChanged(myRoot);
final TreeNode targetNode = nodeToSelect;
if (targetNode != null) {
// If the new heap has the selected class (from a previous heap), then select it and scroll to it.
myColumnTree.revalidate();
final TreePath pathToSelect = new TreePath(myTreeModel.getPathToRoot(targetNode));
myTree.setSelectionPath(pathToSelect);
// This is kind of clunky, but the viewport doesn't know how big the tree is until it repaints.
// We need to do this because the contents of this tree has been more or less completely replaced.
// Unfortunately, calling repaint() only queues it, so we actually need an extra frame to select the node.
ApplicationManager.getApplication().invokeLater(() -> myTree.scrollPathToVisible(pathToSelect));
} else {
selectionModel.setClassObj(null);
if (myTree.getRowCount() > 0) {
myTree.scrollRowToVisible(0);
}
}
}
use of com.android.tools.perflib.heap.ClassObj in project android by JetBrains.
the class ClassesTreeView method getTargetFiles.
@Nullable
private PsiClassNavigation[] getTargetFiles() {
TreePath path = myTree.getSelectionPath();
if (path.getPathCount() < 2) {
return null;
}
assert path.getLastPathComponent() instanceof HeapNode;
HeapNode node = (HeapNode) path.getLastPathComponent();
if (node instanceof HeapClassObjNode) {
ClassObj classObj = ((HeapClassObjNode) node).getClassObj();
String className = classObj.getClassName();
int arrayIndex = className.indexOf("[");
if (arrayIndex >= 0) {
className = className.substring(0, arrayIndex);
}
return PsiClassNavigation.getNavigationForClass(myProject, className);
}
return null;
}
use of com.android.tools.perflib.heap.ClassObj 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);
}
use of com.android.tools.perflib.heap.ClassObj in project platform_frameworks_base by android.
the class Hprof method analyzeHprof.
/**
* Return a map of class names to class-loader names derived from the hprof dump.
*
* @param hprofLocalFile
*/
public static Map<String, String> analyzeHprof(File hprofLocalFile) throws Exception {
Snapshot snapshot = Snapshot.createSnapshot(new MemoryMappedFileBuffer(hprofLocalFile));
Map<String, Set<ClassObj>> classes = Queries.classes(snapshot, null);
Map<String, String> retValue = new HashMap<String, String>();
for (Map.Entry<String, Set<ClassObj>> e : classes.entrySet()) {
for (ClassObj c : e.getValue()) {
String cl = c.getClassLoader() == null ? null : c.getClassLoader().toString();
String cName = c.getClassName();
int aDepth = 0;
while (cName.endsWith("[]")) {
cName = cName.substring(0, cName.length() - 2);
aDepth++;
}
String newName = transformPrimitiveClass(cName);
if (aDepth > 0) {
// Need to use kind-a descriptor syntax. If it was transformed, it is primitive.
if (newName.equals(cName)) {
newName = "L" + newName + ";";
}
for (int i = 0; i < aDepth; i++) {
newName = "[" + newName;
}
}
retValue.put(newName, cl);
}
}
// Free up memory.
snapshot.dispose();
return retValue;
}
Aggregations