Search in sources :

Example 1 with Node

use of com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node in project honest-profiler by jvm-profiling-tools.

the class ReferenceUtil method switchReference.

/**
 * Set the reference of all {@link Node}s contained in the provided {@link Tree} according to the specified
 * {@link ReferenceMode}. The reference of a {@link Node} is used for calculating the percentage values.
 * <p>
 * Please consult the {@link ReferenceMode} documentation for more information about the meaning of the reference
 * modes.
 * <p>
 * WARNING : the {@link ReferenceMode#THREAD} mode can only be used for {@link Tree}s or {@link TreeDiff}s where the
 * top-level children represent thread-level aggregations. Similarly, the {@link ReferenceMode#PARENT} mode can only
 * be used in {@link Tree}s or {@link TreeDiff}s.
 * <p>
 * @param tree the {@link Tree} whose references are to be changed
 * @param mode the strategy for setting the references
 */
public static void switchReference(Tree tree, ReferenceMode mode) {
    switch(mode) {
        case GLOBAL:
            NumericInfo global = tree.getSource().getGlobalData();
            tree.flatten().forEach(node -> node.setReference(global));
            return;
        case THREAD:
            tree.getData().forEach(rootNode -> {
                // The root nodes are presumed to be thread-level aggregations. If not, the results are unspecified.
                NumericInfo reference = rootNode.getData();
                rootNode.getChildren().forEach(child -> child.flatten().forEach(node -> node.setReference(reference)));
            });
            return;
        case PARENT:
            tree.getData().forEach(node -> setReferenceToParent(null, node));
            return;
    }
}
Also used : Tree(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree) Node(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node) NumericInfo(com.insightfullogic.honest_profiler.core.profiles.lean.info.NumericInfo) TreeDiff(com.insightfullogic.honest_profiler.core.aggregation.result.diff.TreeDiff) NumericInfo(com.insightfullogic.honest_profiler.core.profiles.lean.info.NumericInfo)

Example 2 with Node

use of com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node in project honest-profiler by jvm-profiling-tools.

the class DescendantTreeAggregator method aggregate.

// Aggregator Implementation
/**
 * @see SubAggregator#aggregate(Object)
 */
@Override
public Tree aggregate(Entry input) {
    Aggregation<Keyed<String>> aggregation = input.getAggregation();
    AggregationProfile source = aggregation.getSource();
    CombinedGrouping grouping = aggregation.getGrouping();
    Tree result = new Tree(source, input.getAggregation().getGrouping());
    Node root = new Node(input);
    result.getData().add(root);
    addChildren(source, root, result, grouping);
    return result;
}
Also used : AggregationProfile(com.insightfullogic.honest_profiler.core.aggregation.AggregationProfile) LeanNode(com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode) Node(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node) Tree(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree) Keyed(com.insightfullogic.honest_profiler.core.aggregation.result.Keyed) CombinedGrouping(com.insightfullogic.honest_profiler.core.aggregation.grouping.CombinedGrouping)

Example 3 with Node

use of com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node in project honest-profiler by jvm-profiling-tools.

the class DescendantTreeAggregator method addChildren.

/**
 * Recursive method for aggregating the children (and descendants) of the {@link LeanNode}s which are aggregated by
 * the provided {@link Node}.
 * <p>
 * @param source the original {@link AggregationProfile}
 * @param child the input {@link Node}
 * @param tree the resulting {@link Tree}
 * @param grouping the key calculation grouping
 */
private void addChildren(AggregationProfile source, Node child, Tree tree, CombinedGrouping grouping) {
    Map<String, Node> result = child.getAggregatedNodes().stream().flatMap(node -> node.getChildren().stream()).collect(groupingBy(// Group LeanNodes by calculated key
    node -> grouping.apply(source, node), // Downstream collector, collects LeanNodes in a single group
    of(// Supplier, creates an empty Node
    () -> {
        Node node = new Node(tree);
        // Set the reference by default for all nodes to the global aggregation.
        node.setReference(source.getGlobalData());
        return node;
    }, // Accumulator, aggregates a LeanNode into the Node accumulator
    (x, y) -> {
        x.add(y);
        x.setKey(grouping.apply(source, y));
    }, // Combiner, combines two Nodes with the same key
    (x, y) -> x.combine(y))));
    // Add the aggregated children as children to the Node, and recurse
    result.values().forEach(parent -> {
        child.addChild(parent);
        // Recursively add descendants
        addChildren(source, parent, tree, grouping);
    });
}
Also used : CombinedGrouping(com.insightfullogic.honest_profiler.core.aggregation.grouping.CombinedGrouping) LeanNode(com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode) Tree(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree) Map(java.util.Map) Aggregation(com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation) Keyed(com.insightfullogic.honest_profiler.core.aggregation.result.Keyed) Entry(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Entry) Node(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) AggregationProfile(com.insightfullogic.honest_profiler.core.aggregation.AggregationProfile) Collector.of(java.util.stream.Collector.of) LeanNode(com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode) Node(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node)

Example 4 with Node

use of com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node in project honest-profiler by jvm-profiling-tools.

the class TreeProfileAggregator method aggregate.

// Aggregator Implementation
/**
 * Aggregates an {@link AggregationProfile} into a {@link Tree}. The {@link CombinedGrouping} specifies which
 * {@link LeanNode}s are aggregated together.
 *
 * @see ProfileAggregator#aggregate(AggregationProfile, CombinedGrouping)
 */
@Override
public Tree aggregate(AggregationProfile input, CombinedGrouping grouping) {
    // Prepare result.
    Tree result = new Tree(input, grouping);
    LeanProfile profile = input.getSource();
    Map<String, Node> nodeMap = profile.getThreads().values().stream().collect(groupingBy(// Group LeanNodes by calculated key
    node -> grouping.apply(input, node), // Downstream collector, aggregates LeanNodes in a single group
    of(// Supplier, creates an empty Node
    () -> new Node(result), // Accumulator, aggregates a LeanNode into the Node accumulator
    (node, leanNode) -> {
        node.add(leanNode);
        node.setKey(grouping.apply(input, leanNode));
        // Aggregate descendants of a LeanNode recursively into children of accumulator. The recursion
        // happens inside the Node.addChild() method, triggered by the boolean parameter.
        leanNode.getChildren().forEach(child -> node.addChild(child, grouping, true));
    }, // Combiner, combines two Nodes with the same key
    (node1, node2) -> node1.combine(node2))));
    // Set the reference by default for all nodes to the global aggregation.
    // We do this here because the addChild() method doesn't propagate the reference, and proably shouldn't.
    nodeMap.values().stream().flatMap(Node::flatten).forEach(node -> {
        node.setReference(input.getGlobalData());
    });
    result.getData().addAll(nodeMap.values());
    return result;
}
Also used : CombinedGrouping(com.insightfullogic.honest_profiler.core.aggregation.grouping.CombinedGrouping) LeanNode(com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode) Tree(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree) Map(java.util.Map) Node(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) AggregationProfile(com.insightfullogic.honest_profiler.core.aggregation.AggregationProfile) LeanProfile(com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile) Collector.of(java.util.stream.Collector.of) LeanProfile(com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile) LeanNode(com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode) Node(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node) Tree(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree)

Example 5 with Node

use of com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node in project honest-profiler by jvm-profiling-tools.

the class ContextMenuUtil method getContextMenu.

/**
 * Constructs the {@link ContextMenu} for a {@link TreeItem}.
 * <p>
 * Based on the type of the Object contained in the {@link TreeItem}, menu options can be added.
 * <p>
 * The following options are always provided : Expand All (selected node and all its descendants), Expand First Only
 * (recursively expand only the first child) and Collapse All (collapse the entire subtree).
 * <p>
 * For {@link Node}s, the menu will (when fixed) add an Export To File option.
 * <p>
 *
 * @param <T> the type of the item contained in the {@link TreeItem}
 * @param appCtx the {@link ApplicationContext} of the application
 * @param treeItem the {@link TreeItem} for which the {@link ContextMenu} is constructed
 * @return the constructed {@link ContextMenu}
 */
private static <T> ContextMenu getContextMenu(ApplicationContext appCtx, TreeItem<T> treeItem) {
    ContextMenu menu = new ContextMenu();
    addMenuItem(menu.getItems(), appCtx.textFor(CTXMENU_TREE_EXPANDFULLY), info -> expandFully(treeItem));
    addMenuItem(menu.getItems(), appCtx.textFor(CTXMENU_TREE_EXPANDFIRSTONLY), info -> expandFirstOnly(treeItem));
    addMenuItem(menu.getItems(), appCtx.textFor(CTXMENU_TREE_COLLAPSE), info -> collapseFully(treeItem));
    // TODO FIX - ProfileNodes are no longer used.
    if (treeItem.getValue() instanceof Node) {
        addMenuItem(menu.getItems(), appCtx.textFor(CTXMENU_TREE_EXPORTSUBTREE), info -> showExportDialog(appCtx, menu.getScene().getWindow(), "stack_profile.txt", out -> writeStack(out, (Node) treeItem.getValue())));
    }
    return menu;
}
Also used : ObjectProperty(javafx.beans.property.ObjectProperty) CTXMENU_TREE_EXPANDFIRSTONLY(com.insightfullogic.honest_profiler.ports.javafx.util.ResourceUtil.CTXMENU_TREE_EXPANDFIRSTONLY) ReadOnlyObjectProperty(javafx.beans.property.ReadOnlyObjectProperty) CTXMENU_TREE_COLLAPSE(com.insightfullogic.honest_profiler.ports.javafx.util.ResourceUtil.CTXMENU_TREE_COLLAPSE) TreeItem(javafx.scene.control.TreeItem) Node(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node) ObjectBinding(javafx.beans.binding.ObjectBinding) Property(javafx.beans.property.Property) CTXMENU_TREE_EXPANDFULLY(com.insightfullogic.honest_profiler.ports.javafx.util.ResourceUtil.CTXMENU_TREE_EXPANDFULLY) TreeUtil.expandFully(com.insightfullogic.honest_profiler.ports.javafx.util.TreeUtil.expandFully) ApplicationContext(com.insightfullogic.honest_profiler.ports.javafx.model.ApplicationContext) DialogUtil.showExportDialog(com.insightfullogic.honest_profiler.ports.javafx.util.DialogUtil.showExportDialog) TreeUtil.expandFirstOnly(com.insightfullogic.honest_profiler.ports.javafx.util.TreeUtil.expandFirstOnly) TreeTableRow(javafx.scene.control.TreeTableRow) TreeTableView(javafx.scene.control.TreeTableView) ContextMenu(javafx.scene.control.ContextMenu) TreeTableCell(javafx.scene.control.TreeTableCell) TreeCell(javafx.scene.control.TreeCell) TreeUtil.collapseFully(com.insightfullogic.honest_profiler.ports.javafx.util.TreeUtil.collapseFully) CTXMENU_TREE_EXPORTSUBTREE(com.insightfullogic.honest_profiler.ports.javafx.util.ResourceUtil.CTXMENU_TREE_EXPORTSUBTREE) MenuUtil.addMenuItem(com.insightfullogic.honest_profiler.ports.javafx.util.MenuUtil.addMenuItem) ReportUtil.writeStack(com.insightfullogic.honest_profiler.ports.javafx.util.report.ReportUtil.writeStack) Node(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node) ContextMenu(javafx.scene.control.ContextMenu)

Aggregations

Node (com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node)13 Tree (com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree)6 LeanNode (com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode)6 AggregationProfile (com.insightfullogic.honest_profiler.core.aggregation.AggregationProfile)5 CombinedGrouping (com.insightfullogic.honest_profiler.core.aggregation.grouping.CombinedGrouping)5 Keyed (com.insightfullogic.honest_profiler.core.aggregation.result.Keyed)4 Entry (com.insightfullogic.honest_profiler.core.aggregation.result.straight.Entry)3 Map (java.util.Map)3 Collector.of (java.util.stream.Collector.of)3 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)3 Aggregation (com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation)2 TreeTableViewCheckAdapter (com.insightfullogic.honest_profiler.framework.checker.TreeTableViewCheckAdapter)2 ContextMenu (javafx.scene.control.ContextMenu)2 TreeTableView (javafx.scene.control.TreeTableView)2 FrameGrouping (com.insightfullogic.honest_profiler.core.aggregation.grouping.FrameGrouping)1 ThreadGrouping (com.insightfullogic.honest_profiler.core.aggregation.grouping.ThreadGrouping)1 DiffEntry (com.insightfullogic.honest_profiler.core.aggregation.result.diff.DiffEntry)1 DiffNode (com.insightfullogic.honest_profiler.core.aggregation.result.diff.DiffNode)1 TreeDiff (com.insightfullogic.honest_profiler.core.aggregation.result.diff.TreeDiff)1 LeanProfile (com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile)1