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())
// Parent of a root LeanNode is null
.filter(node -> node != null)
// Filter out duplicate parents
.distinct()
.collect(groupingBy(
// Group LeanNodes by calculated key
node -> grouping.apply(source, node),
Expand Down
Expand Up @@ -6,6 +6,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;

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

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

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

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

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

this.frame = frame;
data = new NumericInfo(nanos);
this.parent = parent;
Expand All @@ -44,17 +52,24 @@ public LeanNode(FrameInfo frame, long nanos, LeanNode parent)
/**
* 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)
{
this.id = source.id;

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

public int getId()
{
return id;
}

public FrameInfo getFrame()
{
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)));
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

/**
* Binds the local target {@link Property} to the target {@link Property} in the {@link ProfileContext}, using the
* target extractor function. The net effect is that the controller will start tracking changes to the target
* instance in the {@link ProfileContext}.
* Activate or deactivate the current view. When activated, the view tracks changes in the target.
*
* @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)
{

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

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

private ProfileContext profileContext;

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

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

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

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

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

if (viewType == FLAME)
{
Expand Down

0 comments on commit e3553b2

Please sign in to comment.