Search in sources :

Example 1 with LeanProfile

use of com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile 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 2 with LeanProfile

use of com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile 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 3 with LeanProfile

use of com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile in project honest-profiler by jvm-profiling-tools.

the class AggregationProfileTest method checkThreadInfoLogic.

@Test
public void checkThreadInfoLogic() {
    LeanProfileGenerator gen = new LeanProfileGenerator();
    SCENARIOS.get(7).executeAndEnd(gen);
    LeanProfile leanProfile = gen.getProfile();
    for (LeanThreadNode threadNode : leanProfile.getThreads().values()) {
        assertNull(threadNode.getThreadInfo());
    }
    AggregationProfile profile = new AggregationProfile(leanProfile);
    Map<Long, LeanThreadNode> threads = profile.getSource().getThreads();
    // Check ThreadInfo has been updated
    assertNotNull("Missing ThreadInfo for thread 1", threads.get(1L).getThreadInfo());
    assertNotNull("Missing ThreadInfo for thread 2", threads.get(2L).getThreadInfo());
    assertNotNull("Missing ThreadInfo for thread 3", threads.get(3L).getThreadInfo());
    assertNotNull("Missing ThreadInfo for thread 4", threads.get(4L).getThreadInfo());
    assertNotNull("Missing ThreadInfo for thread 5", threads.get(5L).getThreadInfo());
    assertNull("There should be no ThreadInfo for thread 6", threads.get(6L).getThreadInfo());
}
Also used : LeanProfileGenerator(com.insightfullogic.honest_profiler.framework.generator.LeanProfileGenerator) LeanProfile(com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile) LeanThreadNode(com.insightfullogic.honest_profiler.core.profiles.lean.LeanThreadNode) Test(org.junit.Test)

Aggregations

LeanProfile (com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile)3 AggregationProfile (com.insightfullogic.honest_profiler.core.aggregation.AggregationProfile)2 CombinedGrouping (com.insightfullogic.honest_profiler.core.aggregation.grouping.CombinedGrouping)2 LeanNode (com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode)2 Map (java.util.Map)2 Collector.of (java.util.stream.Collector.of)2 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)2 Entry (com.insightfullogic.honest_profiler.core.aggregation.result.straight.Entry)1 Flat (com.insightfullogic.honest_profiler.core.aggregation.result.straight.Flat)1 Node (com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node)1 Tree (com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree)1 LeanThreadNode (com.insightfullogic.honest_profiler.core.profiles.lean.LeanThreadNode)1 LeanProfileGenerator (com.insightfullogic.honest_profiler.framework.generator.LeanProfileGenerator)1 Collectors.toList (java.util.stream.Collectors.toList)1 Test (org.junit.Test)1