From 4aab9e1d0f0782f2fe59b5711de292220d21be7a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Genevi=C3=A8ve=20Bastien?= Date: Sun, 18 Sep 2016 21:25:05 -0400 Subject: [PATCH] timing: Fix duration of flamegraph view MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Instead of having a duration of the full length of the trace, it has the duration of the longest element. Change-Id: Id56b0d23b8a7619672eb3537dd5ca5d4392708db Signed-off-by: Geneviève Bastien Reviewed-on: https://git.eclipse.org/r/81301 Reviewed-by: Hudson CI Reviewed-by: Matthew Khouzam Tested-by: Matthew Khouzam --- .../flamegraph/FlameGraphContentProvider.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/flamegraph/FlameGraphContentProvider.java b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/flamegraph/FlameGraphContentProvider.java index d7361665ad..02a6c70ca7 100644 --- a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/flamegraph/FlameGraphContentProvider.java +++ b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/flamegraph/FlameGraphContentProvider.java @@ -36,8 +36,7 @@ import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry; */ public class FlameGraphContentProvider implements ITimeGraphContentProvider { - private List fFlameGraphEntries = new ArrayList<>(); - private long fThreadDuration; + private final List fFlameGraphEntries = new ArrayList<>(); private ITmfTrace fActiveTrace; private SortOption fSortOption = SortOption.BY_NAME; private @NonNull Comparator fThreadComparator = new ThreadNameComparator(); @@ -55,16 +54,19 @@ public class FlameGraphContentProvider implements ITimeGraphContentProvider { * A stack used to save the functions timeStamps */ private void setData(AggregatedCalledFunction firstNode, List childrenEntries, Deque timestampStack) { + long lastEnd = timestampStack.peek(); for (int i = 0; i < firstNode.getMaxDepth(); i++) { if (i >= childrenEntries.size()) { - FlamegraphDepthEntry entry = new FlamegraphDepthEntry(String.valueOf(i), 0, fActiveTrace.getEndTime().toNanos() - fActiveTrace.getStartTime().toNanos(), i, i); + FlamegraphDepthEntry entry = new FlamegraphDepthEntry(String.valueOf(i), 0, firstNode.getDuration(), i, i); childrenEntries.add(entry); } + childrenEntries.get(i).updateEndTime(lastEnd + firstNode.getDuration()); } FlamegraphDepthEntry firstEntry = checkNotNull(childrenEntries.get(0)); - firstEntry.addEvent(new FlamegraphEvent(firstEntry, timestampStack.peek(), firstNode)); + firstEntry.addEvent(new FlamegraphEvent(firstEntry, lastEnd, firstNode)); // Build the event list for next entries (next depth) addEvent(firstNode, childrenEntries, timestampStack); + timestampStack.pop(); } /** @@ -133,24 +135,24 @@ public class FlameGraphContentProvider implements ITimeGraphContentProvider { * The node of the aggregation tree */ private void buildChildrenEntries(ThreadNode threadNode) { - FlamegraphDepthEntry threadEntry = new FlamegraphDepthEntry("", 0, fActiveTrace.getEndTime().toNanos() - fActiveTrace.getStartTime().toNanos(), fFlameGraphEntries.size(), threadNode.getId()); //$NON-NLS-1$ + FlamegraphDepthEntry threadEntry = new FlamegraphDepthEntry("", 0, 0, fFlameGraphEntries.size(), threadNode.getId()); //$NON-NLS-1$ List childrenEntries = new ArrayList<>(); - fThreadDuration = 0L; + Deque timestampStack = new ArrayDeque<>(); + timestampStack.push(0L); // Sort children by duration threadNode.getChildren().stream() .sorted(Comparator.comparingLong(AggregatedCalledFunction::getDuration)) .forEach(rootFunction -> { - Deque timestampStack = new ArrayDeque<>(); - timestampStack.push(fThreadDuration); setData(rootFunction, childrenEntries, timestampStack); - fThreadDuration += rootFunction.getDuration(); - timestampStack.pop(); + long currentThreadDuration = timestampStack.pop() + rootFunction.getDuration(); + timestampStack.push(currentThreadDuration); }); childrenEntries.forEach(child -> { if (child != null) { threadEntry.addChild(child); } }); + threadEntry.updateEndTime(timestampStack.pop()); threadEntry.setName(threadNode.getSymbol().toString()); fFlameGraphEntries.add(threadEntry); } -- 2.34.1