Search in sources :

Example 1 with ClassObj

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;
}
Also used : MemoryMappedFileBuffer(com.android.tools.perflib.captures.MemoryMappedFileBuffer) ClassObj(com.android.tools.perflib.heap.ClassObj) Snapshot(com.android.tools.perflib.heap.Snapshot) Set(java.util.Set) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ClassObj

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);
        }
    }
}
Also used : ClassObj(com.android.tools.perflib.heap.ClassObj) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode)

Example 3 with ClassObj

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;
}
Also used : ClassObj(com.android.tools.perflib.heap.ClassObj) HeapNode(com.android.tools.idea.editors.hprof.views.nodedata.HeapNode) TreePath(javax.swing.tree.TreePath) HeapClassObjNode(com.android.tools.idea.editors.hprof.views.nodedata.HeapClassObjNode) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ClassObj

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);
}
Also used : ClassObj(com.android.tools.perflib.heap.ClassObj) IOException(java.io.IOException) Heap(com.android.tools.perflib.heap.Heap)

Example 5 with ClassObj

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;
}
Also used : MemoryMappedFileBuffer(com.android.tools.perflib.captures.MemoryMappedFileBuffer) ClassObj(com.android.tools.perflib.heap.ClassObj) Snapshot(com.android.tools.perflib.heap.Snapshot) Set(java.util.Set) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ClassObj (com.android.tools.perflib.heap.ClassObj)8 MemoryMappedFileBuffer (com.android.tools.perflib.captures.MemoryMappedFileBuffer)5 Snapshot (com.android.tools.perflib.heap.Snapshot)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Set (java.util.Set)5 TreePath (javax.swing.tree.TreePath)2 HeapClassObjNode (com.android.tools.idea.editors.hprof.views.nodedata.HeapClassObjNode)1 HeapNode (com.android.tools.idea.editors.hprof.views.nodedata.HeapNode)1 Heap (com.android.tools.perflib.heap.Heap)1 IOException (java.io.IOException)1 TreeNode (javax.swing.tree.TreeNode)1 Nullable (org.jetbrains.annotations.Nullable)1