Search in sources :

Example 1 with AggregationProfile

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

the class DescendantFlatAggregator method aggregate.

/**
 * This method aggregates all descendants of a {@link Node} into a {@link Flat}, using the original
 * {@link CombinedGrouping} from the {@link Tree} the {@link Node} belongs to.
 *
 * @see SubAggregator#aggregate(Object)
 */
@Override
public Flat aggregate(Node parent) {
    Aggregation<Keyed<String>> aggregation = parent.getAggregation();
    AggregationProfile source = aggregation.getSource();
    CombinedGrouping grouping = aggregation.getGrouping();
    Flat result = new Flat(source, grouping);
    result.getData().addAll(// Create a stream of all descendant nodes, and aggregate according to the Grouping
    parent.flattenDescendants().collect(groupingBy(// Group Nodes by their key
    Node::getKey, // Downstream collector, aggregates the Nodes in a single group
    of(// Supplier, creates an empty Entry
    () -> {
        Entry entry = new Entry(aggregation);
        // Set the reference by default for all nodes to the global aggregation.
        entry.setReference(source.getGlobalData());
        return entry;
    }, // Accumulator, adds a Node to the accumulator Node
    (x, y) -> x.combine(y), // Combiner, combines to entries
    (x, y) -> x.combine(y)))).values());
    return result;
}
Also used : AggregationProfile(com.insightfullogic.honest_profiler.core.aggregation.AggregationProfile) Entry(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Entry) Flat(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Flat) Keyed(com.insightfullogic.honest_profiler.core.aggregation.result.Keyed) CombinedGrouping(com.insightfullogic.honest_profiler.core.aggregation.grouping.CombinedGrouping)

Example 2 with AggregationProfile

use of com.insightfullogic.honest_profiler.core.aggregation.AggregationProfile 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 AggregationProfile

use of com.insightfullogic.honest_profiler.core.aggregation.AggregationProfile 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 AggregationProfile

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

the class FlatProfileAggregator method aggregate.

/**
 * Aggregates an {@link AggregationProfile} into a {@link Flat}. The {@link CombinedGrouping} specifies which
 * {@link LeanNode}s are aggregated together.
 *
 * @see ProfileAggregator#aggregate(AggregationProfile, CombinedGrouping)
 */
@Override
public Flat aggregate(AggregationProfile input, CombinedGrouping grouping) {
    // Prepare result.
    Flat result = new Flat(input, grouping);
    LeanProfile source = input.getSource();
    // Flatten all LeanNodes into a Stream, then collect it into a Map where the key is calculated by the groupings,
    // and the value is the aggregation of the LeanNodes corresponding to the key.
    Map<String, Entry> entryMap = source.getThreads().values().stream().flatMap(LeanNode::flatten).filter(node -> !node.isThreadNode()).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 Entry
    () -> new Entry(result), // Accumulator, aggregates a LeanNode into the Entry accumulator
    (entry, leanNode) -> entry.add(leanNode), // Combiner, combines two Entries with the same key
    (entry1, entry2) -> entry1.combine(entry2))));
    // Add the aggregated Entries to the result list, after setting their key and reference.
    result.getData().addAll(entryMap.entrySet().stream().map(mapEntry -> {
        Entry entry = mapEntry.getValue();
        // The key must be set explicitly here because it isn't set in the collector.
        entry.setKey(mapEntry.getKey());
        // Set the reference by default for all nodes to the global aggregation.
        entry.setReference(input.getGlobalData());
        return entry;
    }).collect(toList()));
    return result;
}
Also used : LeanNode(com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode) Collectors.toList(java.util.stream.Collectors.toList) CombinedGrouping(com.insightfullogic.honest_profiler.core.aggregation.grouping.CombinedGrouping) LeanNode(com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode) Map(java.util.Map) Entry(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Entry) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Flat(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Flat) AggregationProfile(com.insightfullogic.honest_profiler.core.aggregation.AggregationProfile) LeanProfile(com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile) Collector.of(java.util.stream.Collector.of) Entry(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Entry) LeanProfile(com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile) Flat(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Flat)

Example 5 with AggregationProfile

use of com.insightfullogic.honest_profiler.core.aggregation.AggregationProfile 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)

Aggregations

AggregationProfile (com.insightfullogic.honest_profiler.core.aggregation.AggregationProfile)7 CombinedGrouping (com.insightfullogic.honest_profiler.core.aggregation.grouping.CombinedGrouping)7 LeanNode (com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode)6 Keyed (com.insightfullogic.honest_profiler.core.aggregation.result.Keyed)5 Node (com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node)5 Tree (com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree)5 Entry (com.insightfullogic.honest_profiler.core.aggregation.result.straight.Entry)4 Map (java.util.Map)4 Collector.of (java.util.stream.Collector.of)4 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)4 Aggregation (com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation)2 Flat (com.insightfullogic.honest_profiler.core.aggregation.result.straight.Flat)2 LeanProfile (com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile)2 Collectors.toList (java.util.stream.Collectors.toList)1