Skip to content

Commit

Permalink
More Graphy Goodness : Diff FlameGraphs; gradients; better text spacing
Browse files Browse the repository at this point in the history
Most of the day was spent on the color scheme though. Still not there,
but at least very easily tweakable (and in the future maybe even through
sliders in the UI, if need be).
  • Loading branch information
PhRX committed Feb 16, 2017
1 parent fe0f040 commit 98e8d5b
Show file tree
Hide file tree
Showing 16 changed files with 867 additions and 240 deletions.
@@ -0,0 +1,20 @@
package com.insightfullogic.honest_profiler.core.aggregation.result;

import java.util.List;

/**
* Interface for data structure classes which have children ot type T.
* <p>
*
* @param <T> the type of the children
*/
public interface Parent<T>
{
/**
* Returns the list of children.
* <p>
*
* @return Returns the list of children
*/
List<T> getChildren();
}
@@ -1,20 +1,22 @@
package com.insightfullogic.honest_profiler.core.aggregation.result.diff; package com.insightfullogic.honest_profiler.core.aggregation.result.diff;


import static java.lang.Math.max;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;


import java.util.Collection; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Predicate; import java.util.function.Predicate;


import com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation; import com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation;
import com.insightfullogic.honest_profiler.core.aggregation.result.Parent;
import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node; import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node;


/** /**
* Subclass of {@link DiffEntry} which allows to arrange the items into a tree. * Subclass of {@link DiffEntry} which allows to arrange the items into a tree.
*/ */
public class DiffNode extends DiffEntry public class DiffNode extends DiffEntry implements Parent<DiffNode>
{ {
// Instance Properties // Instance Properties


Expand All @@ -25,6 +27,7 @@ public class DiffNode extends DiffEntry
/** /**
* Constructor whach takes the two {@link Node}s to be compared as arguments. * Constructor whach takes the two {@link Node}s to be compared as arguments.
* <p> * <p>
*
* @param baseNode the {@link Node} from the Base {@link Aggregation} * @param baseNode the {@link Node} from the Base {@link Aggregation}
* @param newNode the {@link Node} from the New {@link Aggregation} * @param newNode the {@link Node} from the New {@link Aggregation}
*/ */
Expand All @@ -40,6 +43,7 @@ public DiffNode(Node baseNode, Node newNode)
/** /**
* Specialized internal constructor for {@link #copyWithFilter(Predicate)}. * Specialized internal constructor for {@link #copyWithFilter(Predicate)}.
* <p> * <p>
*
* @param node the {@link DiffNode} being copied * @param node the {@link DiffNode} being copied
* @param children the new, filtered children * @param children the new, filtered children
*/ */
Expand All @@ -59,6 +63,7 @@ private DiffNode(DiffNode node, List<DiffNode> children)
* The return value is provided as a convenience for * The return value is provided as a convenience for
* {@link TreeDiff#set(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree, com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree)}. * {@link TreeDiff#set(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree, com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree)}.
* <p> * <p>
*
* @param node the Base {@link Node} * @param node the Base {@link Node}
* @return this {@link DiffNode} * @return this {@link DiffNode}
*/ */
Expand All @@ -76,6 +81,7 @@ public DiffNode setBase(Node node)
* The return value is provided as a convenience for * The return value is provided as a convenience for
* {@link TreeDiff#set(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree, com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree)}. * {@link TreeDiff#set(com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree, com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree)}.
* <p> * <p>
*
* @param node the New {@link Node} * @param node the New {@link Node}
* @return this {@link DiffNode} * @return this {@link DiffNode}
*/ */
Expand All @@ -90,17 +96,41 @@ public DiffNode setNew(Node node)
/** /**
* Returns the children of this node. * Returns the children of this node.
* <p> * <p>
* @return a {@link Collection} containing the children of this node. *
* @return a {@link List} containing the children of this node.
*/ */
public Collection<DiffNode> getChildren() @Override
public List<DiffNode> getChildren()
{ {
return children.values(); return new ArrayList<>(children.values());
}

/**
* Calculate the depth of the (sub)tree with this Node as root. Returns 0 if there are no children.
* <p>
*
* @return the depth of the (sub)tree with this Node as root, whereby an empty tree has depth 0
*/
public int getDescendantDepth()
{
if (children.isEmpty())
{
return 0;
}

int depth = 0;
for (DiffNode child : children.values())
{
depth = max(depth, child.getDescendantDepth() + 1);
}
return depth;
} }


/** /**
* Filter the descendants of this DiffNode recursively, creating copies of the "survivors". If this node has * Filter the descendants of this DiffNode recursively, creating copies of the "survivors". If this node has
* survivor descendants or is accepted by the filter, the copy is returned, otherwise the method returns null. * survivor descendants or is accepted by the filter, the copy is returned, otherwise the method returns null.
* <p> * <p>
*
* @param filter the filter to be applied to this node and its descendants. * @param filter the filter to be applied to this node and its descendants.
* @return a new {@link DiffNode} containing the filtered information, or null * @return a new {@link DiffNode} containing the filtered information, or null
*/ */
Expand All @@ -118,6 +148,7 @@ public DiffNode copyWithFilter(Predicate<DiffNode> filter)
* Create child DiffNodes or set the Base {@link Node} for existing ones, based on the children from the provided * Create child DiffNodes or set the Base {@link Node} for existing ones, based on the children from the provided
* {@link Node}. * {@link Node}.
* <p> * <p>
*
* @param node the Base {@link Node} whose children need to be incorporated into the children of this node * @param node the Base {@link Node} whose children need to be incorporated into the children of this node
*/ */
private void addBaseChildren(Node node) private void addBaseChildren(Node node)
Expand All @@ -133,6 +164,7 @@ private void addBaseChildren(Node node)
* Create child DiffNodes or set the New {@link Node} for existing ones, based on the children from the provided * Create child DiffNodes or set the New {@link Node} for existing ones, based on the children from the provided
* {@link Node}. * {@link Node}.
* <p> * <p>
*
* @param node the Base {@link Node} whose children need to be incorporated into the children of this node * @param node the Base {@link Node} whose children need to be incorporated into the children of this node
*/ */
private void addNewChildren(Node node) private void addNewChildren(Node node)
Expand All @@ -148,6 +180,7 @@ private void addNewChildren(Node node)
* Sets the Base {@link Node} of the correct child DiffNode to the provided {@link Node}, or create a new child * Sets the Base {@link Node} of the correct child DiffNode to the provided {@link Node}, or create a new child
* DiffNode if it doesn't exist yet, and set the Base {@link Node} in it to the provided {@link Node}. * DiffNode if it doesn't exist yet, and set the Base {@link Node} in it to the provided {@link Node}.
* <p> * <p>
*
* @param child the {@link Node} to be added as Base {@link Node} of a child DiffNode * @param child the {@link Node} to be added as Base {@link Node} of a child DiffNode
*/ */
private void addBaseChild(Node child) private void addBaseChild(Node child)
Expand All @@ -161,6 +194,7 @@ private void addBaseChild(Node child)
* Sets the New {@link Node} of the correct child DiffNode to the provided {@link Node}, or create a new child * Sets the New {@link Node} of the correct child DiffNode to the provided {@link Node}, or create a new child
* DiffNode if it doesn't exist yet, and set the New {@link Node} in it to the provided {@link Node}. * DiffNode if it doesn't exist yet, and set the New {@link Node} in it to the provided {@link Node}.
* <p> * <p>
*
* @param child the {@link Node} to be added as New {@link Node} of a child DiffNode * @param child the {@link Node} to be added as New {@link Node} of a child DiffNode
*/ */
private void addNewChild(Node child) private void addNewChild(Node child)
Expand Down
Expand Up @@ -35,17 +35,20 @@ public TreeDiff()
/** /**
* Internal Copy constructor. * Internal Copy constructor.
* <p> * <p>
*
* @param entries the {@link List} of {@link DiffNode}s to be copied into this Diff * @param entries the {@link List} of {@link DiffNode}s to be copied into this Diff
*/ */
private TreeDiff(List<DiffNode> entries) private TreeDiff(Tree baseTree, Tree newTree, List<DiffNode> entries)
{ {
super.setAggregations(baseTree, newTree);
data = new HashMap<>(); data = new HashMap<>();
entries.forEach(entry -> data.put(entry.getKey(), entry)); entries.forEach(entry -> data.put(entry.getKey(), entry));
} }


/** /**
* Sets the Base and New {@link Tree}s, and calculates the diff contents. * Sets the Base and New {@link Tree}s, and calculates the diff contents.
* <p> * <p>
*
* @param baseTree the Base {@link Tree} * @param baseTree the Base {@link Tree}
* @param newTree the New {@link Tree} * @param newTree the New {@link Tree}
*/ */
Expand All @@ -67,6 +70,7 @@ public void set(Tree baseTree, Tree newTree)
/** /**
* Returns the {@link DiffNode}s from this Diff. * Returns the {@link DiffNode}s from this Diff.
* <p> * <p>
*
* @return a {@link Collection} containing the {@link DiffNode}s from this Diff * @return a {@link Collection} containing the {@link DiffNode}s from this Diff
*/ */
public Collection<DiffNode> getData() public Collection<DiffNode> getData()
Expand All @@ -80,6 +84,8 @@ public Collection<DiffNode> getData()
public TreeDiff filter(FilterSpecification<DiffNode> filterSpec) public TreeDiff filter(FilterSpecification<DiffNode> filterSpec)
{ {
return new TreeDiff( return new TreeDiff(
getBaseAggregation(),
getNewAggregation(),
getData().stream().map(node -> node.copyWithFilter(filterSpec.getFilter())) getData().stream().map(node -> node.copyWithFilter(filterSpec.getFilter()))
.filter(node -> node != null).collect(toList())); .filter(node -> node != null).collect(toList()));
} }
Expand Down
Expand Up @@ -15,12 +15,13 @@
import com.insightfullogic.honest_profiler.core.aggregation.grouping.CombinedGrouping; import com.insightfullogic.honest_profiler.core.aggregation.grouping.CombinedGrouping;
import com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation; import com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation;
import com.insightfullogic.honest_profiler.core.aggregation.result.Keyed; import com.insightfullogic.honest_profiler.core.aggregation.result.Keyed;
import com.insightfullogic.honest_profiler.core.aggregation.result.Parent;
import com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode; import com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode;


/** /**
* Wrapper for {@link Entry} which allows organizing them into a tree structure. * Wrapper for {@link Entry} which allows organizing them into a tree structure.
*/ */
public class Node extends Entry public class Node extends Entry implements Parent<Node>
{ {
// Instance Properties // Instance Properties


Expand All @@ -31,6 +32,7 @@ public class Node extends Entry
/** /**
* Create an empty Node for the specified {@link Aggregation}. * Create an empty Node for the specified {@link Aggregation}.
* <p> * <p>
*
* @param <T> the type of the data items contained in the {@link Aggregation} * @param <T> the type of the data items contained in the {@link Aggregation}
* @param aggregation the {@link Aggregation} the created Node belongs to * @param aggregation the {@link Aggregation} the created Node belongs to
*/ */
Expand All @@ -43,6 +45,7 @@ public <T extends Keyed<String>> Node(Aggregation<T> aggregation)
/** /**
* Create a Node based on an {@link Entry}. The information of the {@link Entry} is copied into this Node. * Create a Node based on an {@link Entry}. The information of the {@link Entry} is copied into this Node.
* <p> * <p>
*
* @param entry the {@link Entry} the Node is based on * @param entry the {@link Entry} the Node is based on
*/ */
public Node(Entry entry) public Node(Entry entry)
Expand All @@ -54,6 +57,7 @@ public Node(Entry entry)
/** /**
* Copy Constructor. * Copy Constructor.
* <p> * <p>
*
* @param node the Node being copied * @param node the Node being copied
* @param children the (new) children of the Node * @param children the (new) children of the Node
*/ */
Expand All @@ -64,11 +68,15 @@ private Node(Node node, List<Node> children)
children.forEach(child -> this.children.put(child.getKey(), child)); children.forEach(child -> this.children.put(child.getKey(), child));
} }


// Instance Accessors

/** /**
* Returns the children of the Node. * Returns the children of the Node.
* <p> * <p>
*
* @return the children of the Node * @return the children of the Node
*/ */
@Override
public List<Node> getChildren() public List<Node> getChildren()
{ {
return new ArrayList<>(children.values()); return new ArrayList<>(children.values());
Expand All @@ -77,6 +85,7 @@ public List<Node> getChildren()
/** /**
* Calculate the depth of the (sub)tree with this Node as root. Returns 0 if there are no children. * Calculate the depth of the (sub)tree with this Node as root. Returns 0 if there are no children.
* <p> * <p>
*
* @return the depth of the (sub)tree with this Node as root, whereby an empty tree has depth 0 * @return the depth of the (sub)tree with this Node as root, whereby an empty tree has depth 0
*/ */
public int getDescendantDepth() public int getDescendantDepth()
Expand All @@ -97,6 +106,7 @@ public int getDescendantDepth()
/** /**
* Adggregates a Node into the children of this Node. * Adggregates a Node into the children of this Node.
* <p> * <p>
*
* @param child the Node to be aggregated as child * @param child the Node to be aggregated as child
* @return the Node resulting from the aggregation * @return the Node resulting from the aggregation
*/ */
Expand All @@ -109,6 +119,7 @@ public Node addChild(Node child)
* Aggregates a {@link LeanNode} into the children of this Node, using the specified {@link CombinedGrouping} to * Aggregates a {@link LeanNode} into the children of this Node, using the specified {@link CombinedGrouping} to
* determine the aggregation key, and recursively aggregating the {@link LeanNode} descendants as well if specified. * determine the aggregation key, and recursively aggregating the {@link LeanNode} descendants as well if specified.
* <p> * <p>
*
* @param child the {@link LeanNode} to be aggregated into the children of this Node * @param child the {@link LeanNode} to be aggregated into the children of this Node
* @param grouping the {@link CombinedGrouping} used for determining the aggregation key * @param grouping the {@link CombinedGrouping} used for determining the aggregation key
* @param recurse a boolean specifying whether the {@link LeanNode} descendants should be aggregated recursively * @param recurse a boolean specifying whether the {@link LeanNode} descendants should be aggregated recursively
Expand All @@ -133,6 +144,7 @@ public void addChild(LeanNode child, CombinedGrouping grouping, boolean recurse)
/** /**
* Combines another Node into this one. The descendants will also be combined recursively. * Combines another Node into this one. The descendants will also be combined recursively.
* <p> * <p>
*
* @param other he Node to be combined into this Node * @param other he Node to be combined into this Node
* @return this Node * @return this Node
*/ */
Expand All @@ -148,6 +160,7 @@ public Node combine(Node other)
/** /**
* Returns a copy of this Node. * Returns a copy of this Node.
* <p> * <p>
*
* @return a copy of this Node * @return a copy of this Node
*/ */
public Node copy() public Node copy()
Expand All @@ -161,6 +174,7 @@ public Node copy()
* Returns a copy of this Node applying a filter to itself and any descendants. The method returns null if no * Returns a copy of this Node applying a filter to itself and any descendants. The method returns null if no
* children are accepted by the filter and the node itself isn't accepted either. * children are accepted by the filter and the node itself isn't accepted either.
* <p> * <p>
*
* @param filter a {@link Predicate} for accepting Nodes * @param filter a {@link Predicate} for accepting Nodes
* @return the filtered Node or null if the Node and none of its descendants are accepted * @return the filtered Node or null if the Node and none of its descendants are accepted
*/ */
Expand All @@ -175,6 +189,7 @@ public Node copyWithFilter(Predicate<Node> filter)
/** /**
* Return a {@link Stream} of Nodes consisting of this Node and all its descendants. * Return a {@link Stream} of Nodes consisting of this Node and all its descendants.
* <p> * <p>
*
* @return a {@link Stream} of Nodes consisting of this Node and all its descendants * @return a {@link Stream} of Nodes consisting of this Node and all its descendants
*/ */
public Stream<Node> flatten() public Stream<Node> flatten()
Expand All @@ -185,6 +200,7 @@ public Stream<Node> flatten()
/** /**
* Return a {@link Stream} of Nodes consisting of all the descendants of this Node. This Node is not included. * Return a {@link Stream} of Nodes consisting of all the descendants of this Node. This Node is not included.
* <p> * <p>
*
* @return a {@link Stream} of Nodes consisting of all the descendants of this Node * @return a {@link Stream} of Nodes consisting of all the descendants of this Node
*/ */
public Stream<Node> flattenDescendants() public Stream<Node> flattenDescendants()
Expand Down

0 comments on commit 98e8d5b

Please sign in to comment.