Search in sources :

Example 1 with JavaRuntimeMemoryCategory

use of com.ibm.dtfj.java.JavaRuntimeMemoryCategory in project openj9 by eclipse.

the class InfoMemoryCommand method printAllMemoryCategories.

/**
 * Print out the memory categories in nice ASCII art tree similar to the ones in javacore.
 * @param out the PrintStream to write to.
 * @param memoryCategories the memory categories to write
 */
private void printAllMemoryCategories(PrintStream out, Iterator memoryCategories) {
    try {
        while (memoryCategories.hasNext()) {
            Object obj = memoryCategories.next();
            if (obj instanceof JavaRuntimeMemoryCategory) {
                JavaRuntimeMemoryCategory category = (JavaRuntimeMemoryCategory) obj;
                LinkedList<Integer> stack = new LinkedList<Integer>();
                int childCount = countPrintableChildren(category);
                stack.addLast(childCount);
                printCategory(category, stack, out);
            }
        }
    } catch (CorruptDataException cde) {
        out.println("Corrupt Data encountered walking memory categories");
        logger.log(Level.FINE, Exceptions.getCorruptDataExceptionString(), cde);
    }
}
Also used : JavaRuntimeMemoryCategory(com.ibm.dtfj.java.JavaRuntimeMemoryCategory) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) LinkedList(java.util.LinkedList)

Example 2 with JavaRuntimeMemoryCategory

use of com.ibm.dtfj.java.JavaRuntimeMemoryCategory in project openj9 by eclipse.

the class NativeMemorySectionParser method topLevelRule.

protected void topLevelRule() throws ParserException {
    IImageProcessBuilder fImageProcessBuilder = fImageBuilder.getCurrentAddressSpaceBuilder().getCurrentImageProcessBuilder();
    IJavaRuntimeBuilder fRuntimeBuilder = fImageProcessBuilder.getCurrentJavaRuntimeBuilder();
    IAttributeValueMap results = null;
    Stack categoryStack = new Stack();
    processTagLineOptional(T_0MEMUSER);
    while ((results = processMemUserLine()) != null) {
        String name = results.getTokenValue(A_NAME);
        /* If no name available, this is a spacing line */
        if (name == null) {
            continue;
        }
        int depth = results.getIntValue(A_DEPTH);
        while (categoryStack.size() >= depth) {
            categoryStack.pop();
        }
        long deepBytes = parseCommaDelimitedLong(results.getTokenValue(A_DEEP_BYTES));
        long deepAllocations = parseCommaDelimitedLong(results.getTokenValue(A_DEEP_ALLOCATIONS));
        JavaRuntimeMemoryCategory parent = null;
        if (categoryStack.size() > 0) {
            parent = (JavaRuntimeMemoryCategory) categoryStack.peek();
        }
        if (name.equals(OTHER_CATEGORY)) {
            if (parent == null) {
                throw new ParserException("Parse error: Unexpected NULL parent category for \"Other\" memory category");
            }
            fRuntimeBuilder.setShallowCountersForCategory(parent, deepBytes, deepAllocations);
        } else {
            JavaRuntimeMemoryCategory category = fRuntimeBuilder.addMemoryCategory(name, deepBytes, deepAllocations, parent);
            categoryStack.push(category);
        }
    }
}
Also used : ParserException(com.ibm.dtfj.javacore.parser.framework.parser.ParserException) IAttributeValueMap(com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap) JavaRuntimeMemoryCategory(com.ibm.dtfj.java.JavaRuntimeMemoryCategory) IJavaRuntimeBuilder(com.ibm.dtfj.javacore.builder.IJavaRuntimeBuilder) IImageProcessBuilder(com.ibm.dtfj.javacore.builder.IImageProcessBuilder) Stack(java.util.Stack)

Example 3 with JavaRuntimeMemoryCategory

use of com.ibm.dtfj.java.JavaRuntimeMemoryCategory in project openj9 by eclipse.

the class InfoMemoryCommand method printCategory.

/**
 * Print a category and any of it's children. The stack argument is a list of how many children
 * each parent category has so we can work out how to print the ascii art lines from parents
 * to children.
 *
 * @param category
 * @param stack
 * @param out
 */
private void printCategory(JavaRuntimeMemoryCategory category, LinkedList<Integer> stack, PrintStream out) {
    int depth = stack.size() - 1;
    try {
        if (category.getShallowBytes() > 0 || category.getDeepBytes() > 0) {
            /* Do the indenting and the ASCII art tree */
            indentToDepth(new String[] { "|  ", "|  ", "   " }, stack, out, depth);
            if (depth > 0) {
                out.println();
            }
            indentToDepth(new String[] { "+--", "|  ", "   " }, stack, out, depth);
            /* Actually print out the interesting data */
            out.printf("%s: %d bytes / %d allocations\n", category.getName(), category.getDeepBytes(), category.getDeepAllocations());
            /* Only descend if there's really more data in sub categories unaccounted for. */
            if (category.getDeepBytes() > category.getShallowBytes()) {
                Iterator memoryCategories = category.getChildren();
                JavaRuntimeMemoryCategory other = getOtherCategory(category);
                while (memoryCategories.hasNext()) {
                    int parentCount = stack.get(depth);
                    parentCount--;
                    stack.set(depth, parentCount);
                    Object obj = memoryCategories.next();
                    if (obj instanceof JavaRuntimeMemoryCategory) {
                        JavaRuntimeMemoryCategory next = (JavaRuntimeMemoryCategory) obj;
                        int childCount = countPrintableChildren(next);
                        stack.addLast(childCount);
                        printCategory(next, stack, out);
                        stack.removeLast();
                    }
                }
                /* Add magic "Other" category for unaccounted memory. (Like javacore) */
                if (other != null) {
                    // "Other" will never have children.
                    stack.addLast(0);
                    printCategory(other, stack, out);
                    stack.removeLast();
                }
            }
        }
    } catch (CorruptDataException cde) {
        out.println("Corrupt Data encountered walking memory categories");
        logger.log(Level.FINE, Exceptions.getCorruptDataExceptionString(), cde);
    }
}
Also used : JavaRuntimeMemoryCategory(com.ibm.dtfj.java.JavaRuntimeMemoryCategory) Iterator(java.util.Iterator) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Aggregations

JavaRuntimeMemoryCategory (com.ibm.dtfj.java.JavaRuntimeMemoryCategory)3 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)2 IImageProcessBuilder (com.ibm.dtfj.javacore.builder.IImageProcessBuilder)1 IJavaRuntimeBuilder (com.ibm.dtfj.javacore.builder.IJavaRuntimeBuilder)1 ParserException (com.ibm.dtfj.javacore.parser.framework.parser.ParserException)1 IAttributeValueMap (com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 Stack (java.util.Stack)1