Skip to content

Commit

Permalink
Fixed duplicate ancestor counting
Browse files Browse the repository at this point in the history
Added a unique ID to LeanNode so we can weed out duplicates (like in the
aggregator fixed here), but it may also become useful in other cases
(e.g. in the future we can push out incremental LeanProfile updates
instead of full LeanProfiles which may (or may not) save a lot of
processing).

Also some very minor refactoring.
  • Loading branch information
PhRX committed Feb 6, 2017
1 parent 68ba5d2 commit e3553b2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 30 deletions.
Expand Up @@ -56,6 +56,8 @@ private void addAncestors(AggregationProfile source, Node child, Tree tree,
Map<String, Node> result = child.getAggregatedNodes().stream().map(node -> node.getParent()) Map<String, Node> result = child.getAggregatedNodes().stream().map(node -> node.getParent())
// Parent of a root LeanNode is null // Parent of a root LeanNode is null
.filter(node -> node != null) .filter(node -> node != null)
// Filter out duplicate parents
.distinct()
.collect(groupingBy( .collect(groupingBy(
// Group LeanNodes by calculated key // Group LeanNodes by calculated key
node -> grouping.apply(source, node), node -> grouping.apply(source, node),
Expand Down
Expand Up @@ -6,6 +6,7 @@
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream; import java.util.stream.Stream;


import com.insightfullogic.honest_profiler.core.parser.TraceStart; import com.insightfullogic.honest_profiler.core.parser.TraceStart;
Expand All @@ -20,13 +21,18 @@
*/ */
public class LeanNode public class LeanNode
{ {
private static final AtomicInteger ID_GENERATOR = new AtomicInteger(0);

private final int id;
private final FrameInfo frame; private final FrameInfo frame;
private final NumericInfo data; private final NumericInfo data;
private LeanNode parent; private LeanNode parent;
private final Map<FrameInfo, LeanNode> childMap; private final Map<FrameInfo, LeanNode> childMap;


public LeanNode(FrameInfo frame, LeanNode parent) public LeanNode(FrameInfo frame, LeanNode parent)
{ {
id = ID_GENERATOR.getAndIncrement();

this.frame = frame; this.frame = frame;
data = new NumericInfo(); data = new NumericInfo();
this.parent = parent; this.parent = parent;
Expand All @@ -35,6 +41,8 @@ public LeanNode(FrameInfo frame, LeanNode parent)


public LeanNode(FrameInfo frame, long nanos, LeanNode parent) public LeanNode(FrameInfo frame, long nanos, LeanNode parent)
{ {
id = ID_GENERATOR.getAndIncrement();

this.frame = frame; this.frame = frame;
data = new NumericInfo(nanos); data = new NumericInfo(nanos);
this.parent = parent; this.parent = parent;
Expand All @@ -44,17 +52,24 @@ public LeanNode(FrameInfo frame, long nanos, LeanNode parent)
/** /**
* Copy constructor. * Copy constructor.
* *
* @param source the source SlimNode which is being copied * @param source the source LeanNode which is being copied
*/ */
protected LeanNode(LeanNode source, LeanNode newParent) protected LeanNode(LeanNode source, LeanNode newParent)
{ {
this.id = source.id;

this.frame = source.frame; this.frame = source.frame;
this.data = source.data.copy(); this.data = source.data.copy();
this.parent = newParent; this.parent = newParent;
this.childMap = new HashMap<>(); this.childMap = new HashMap<>();
source.childMap.forEach((key, value) -> this.childMap.put(key.copy(), value.copy(this))); source.childMap.forEach((key, value) -> this.childMap.put(key.copy(), value.copy(this)));
} }


public int getId()
{
return id;
}

public FrameInfo getFrame() public FrameInfo getFrame()
{ {
return frame; return frame;
Expand Down Expand Up @@ -156,4 +171,15 @@ public String toDeepString(int level, Map<Long, MethodInfo> methodMap)
childMap.values().forEach(child -> result.append(child.toDeepString(level + 1, methodMap))); childMap.values().forEach(child -> result.append(child.toDeepString(level + 1, methodMap)));
return result.toString(); return result.toString();
} }

@Override
public boolean equals(Object other)
{
return other instanceof LeanNode && ((LeanNode)other).id == id;
}

public int hashcode()
{
return id;
}
} }
Expand Up @@ -139,22 +139,26 @@ public void bind(ObservableObjectValue<? extends Object> source,
// Activation // Activation


/** /**
* Binds the local target {@link Property} to the target {@link Property} in the {@link ProfileContext}, using the * Activate or deactivate the current view. When activated, the view tracks changes in the target.
* target extractor function. The net effect is that the controller will start tracking changes to the target *
* instance in the {@link ProfileContext}. * @param active a boolean indicating whether to activate or deactivate the view.
*/ */
public void activate() public void setActive(boolean active)
{ {
target.bind(sourceBinding); if (active)
} {


/** // Binds the local target Property to the target Property in the ProfileContext, using the target extractor
* Unbinds the local target {@link Property}. The controller no longer tracks changes to the target {@link Property} // function. The net effect is that the controller will start tracking changes to the target instance in the
* in the {@link ProfileContext}. // ProfileContext.
*/ target.bind(sourceBinding);
public void deactivate() }
{ else
target.unbind(); {
// Unbinds the local target Property. The controller no longer tracks changes to the target Property in the
// ProfileContext.
target.unbind();
}
} }


// AbstractViewController Implementation // AbstractViewController Implementation
Expand Down
Expand Up @@ -97,18 +97,18 @@ public class ProfileRootController extends AbstractController


private ProfileContext profileContext; private ProfileContext profileContext;


private Map<ViewType, List<AbstractProfileViewController<?, ?>>> viewToControllerMap; private Map<ViewType, List<AbstractProfileViewController<?, ?>>> controllerMap;


@Override @Override
@FXML @FXML
public void initialize() public void initialize()
{ {
super.initialize(); super.initialize();


viewToControllerMap = new HashMap<>(); controllerMap = new HashMap<>();
viewToControllerMap.put(FLAT, asList(flatController, callingController, calledController)); controllerMap.put(FLAT, asList(flatController, callingController, calledController));
viewToControllerMap.put(TREE, asList(treeController, descendantsController)); controllerMap.put(TREE, asList(treeController, descendantsController));
viewToControllerMap.put(FLAME, asList(flameController)); controllerMap.put(FLAME, asList(flameController));
} }


// Instance Accessors // Instance Accessors
Expand Down Expand Up @@ -185,17 +185,8 @@ private void show(ViewType viewType)
child.setVisible(viewType.ordinal() == i); child.setVisible(viewType.ordinal() == i);
} }


viewToControllerMap.forEach((type, controllerList) -> controllerMap
{ .forEach((type, list) -> list.forEach(ctrl -> ctrl.setActive(viewType == type)));
if (viewType == type)
{
controllerList.forEach(AbstractProfileViewController::activate);
}
else
{
controllerList.forEach(AbstractProfileViewController::deactivate);
}
});


if (viewType == FLAME) if (viewType == FLAME)
{ {
Expand Down

0 comments on commit e3553b2

Please sign in to comment.