From 9ffe33070778612fa10851040b5f27bf39ccaf81 Mon Sep 17 00:00:00 2001 From: PhRX Date: Thu, 9 Feb 2017 10:44:09 +0100 Subject: [PATCH] Fixes as per review comments by @chhsiao90 - Fixed javadoc typos - Better constant name - Simplification of LeanNode aggregation code --- .../core/collector/lean/LeanLogCollector.java | 4 +- .../core/profiles/lean/LeanNode.java | 42 ++++--------------- .../core/profiles/lean/info/NumericInfo.java | 12 ------ 3 files changed, 9 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/insightfullogic/honest_profiler/core/collector/lean/LeanLogCollector.java b/src/main/java/com/insightfullogic/honest_profiler/core/collector/lean/LeanLogCollector.java index d94100436..0388701da 100644 --- a/src/main/java/com/insightfullogic/honest_profiler/core/collector/lean/LeanLogCollector.java +++ b/src/main/java/com/insightfullogic/honest_profiler/core/collector/lean/LeanLogCollector.java @@ -31,7 +31,7 @@ public class LeanLogCollector implements LogEventListener, ProfileSource { // Class Properties - private static final long SECONDSTONANOS = 1000 * 1000 * 1000; + private static final long SECONDS_TO_NANOS = 1000 * 1000 * 1000; // Instance Properties @@ -223,7 +223,7 @@ private void updateTime(long newSeconds, long newNanos) long secondsDiff = newSeconds - prevSeconds; long nanosDiff = newNanos - prevNanos; - nanosSpent = (secondsDiff * SECONDSTONANOS) + nanosDiff; + nanosSpent = (secondsDiff * SECONDS_TO_NANOS) + nanosDiff; } prevSeconds = newSeconds; diff --git a/src/main/java/com/insightfullogic/honest_profiler/core/profiles/lean/LeanNode.java b/src/main/java/com/insightfullogic/honest_profiler/core/profiles/lean/LeanNode.java index ec84315ac..d92ee9b43 100644 --- a/src/main/java/com/insightfullogic/honest_profiler/core/profiles/lean/LeanNode.java +++ b/src/main/java/com/insightfullogic/honest_profiler/core/profiles/lean/LeanNode.java @@ -57,24 +57,6 @@ protected LeanNode(FrameInfo frame, LeanNode parent) childMap = new HashMap<>(); } - /** - * "Self constructor" for a LeanNode associated with the "bottom frame" of a stack trace, i.e. the one for which - * self time is recorded. - * - * @param frame the {@link FrameInfo} for this LeanNode - * @param nanos the self time associated with the frame - * @param parent the parent LeanNode - */ - private LeanNode(FrameInfo frame, long nanos, LeanNode parent) - { - id = ID_GENERATOR.getAndIncrement(); - - this.frame = frame; - data = new NumericInfo(nanos); - this.parent = parent; - childMap = new HashMap<>(); - } - /** * Copy constructor. * @@ -169,29 +151,19 @@ public boolean isThreadNode() * {@link TraceStart} following it * @param child the child {@link FrameInfo} of the current LeanNode * @param last a boolean indicating if the child is the last in the stack trace sample - * @return this node + * @return the aggregated child {@link LeanNode} */ public LeanNode add(long nanos, FrameInfo child, boolean last) { // Non-self add, which updates total time and sample count only. data.add(nanos, false); - return childMap.compute( - child, - (k, v) -> - // Create a new LeanNode if no children have been recorded for this FrameInfo - v == null ? (last ? - // New child is the last in stack, use "Self constructor". - new LeanNode(child, nanos, this) - // New child is not the last in stack, use "Non-self constructor". - : new LeanNode(child, this)) - // Aggregate the information into an existing child - : (last ? - // Child is last in stack, use the "self add" on existing child - v.addSelf(nanos) : - // Child is not last in stack, return existing child (its "total" numbers will be updated when its - // child is added) - v)); + LeanNode childNode = childMap.computeIfAbsent(child, k -> new LeanNode(k, this)); + if (last) + { + childNode.addSelf(nanos); + } + return childNode; } /** diff --git a/src/main/java/com/insightfullogic/honest_profiler/core/profiles/lean/info/NumericInfo.java b/src/main/java/com/insightfullogic/honest_profiler/core/profiles/lean/info/NumericInfo.java index 880ab3426..ed2f48db7 100644 --- a/src/main/java/com/insightfullogic/honest_profiler/core/profiles/lean/info/NumericInfo.java +++ b/src/main/java/com/insightfullogic/honest_profiler/core/profiles/lean/info/NumericInfo.java @@ -6,7 +6,6 @@ import com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation; import com.insightfullogic.honest_profiler.core.parser.StackFrame; -import com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode; /** * NumericInfo collects the four basic amounts tracked by the profiles and {@link Aggregation}s @@ -43,17 +42,6 @@ public NumericInfo() this(ZERO, ZERO, 0, 0); } - /** - * Constructor for an item with self and total time known, used when creating a new {@link LeanNode}. Self and total - * time are set to the provided time, and self and total sample count are set to 1. - * - * @param selfNanos the self (and total) time - */ - public NumericInfo(long selfNanos) - { - this(BigInteger.valueOf(selfNanos), BigInteger.valueOf(selfNanos), 1, 1); - } - /** * Copy constructor. *