From b5a212a8c87a7370c385aeec22ea98a58fc7b051 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Tue, 20 Aug 2013 12:21:18 +0300 Subject: [PATCH] Report min and max times from Profiler (#12409) Change-Id: Ifb88038baf9c1b9c872840030dcaefd7b8488f64 --- client/src/com/vaadin/client/Profiler.java | 4 +- .../debug/internal/ProfilerSection.java | 54 ++++++++++++++++--- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/client/src/com/vaadin/client/Profiler.java b/client/src/com/vaadin/client/Profiler.java index caa512b34e..bcbf8279f3 100644 --- a/client/src/com/vaadin/client/Profiler.java +++ b/client/src/com/vaadin/client/Profiler.java @@ -224,7 +224,7 @@ public class Profiler { && eventName.equals(stack.get(stack.size() - 2).getName()) && !isBeginEvent) { // back out of sub event - stackTop.addTime(gwtStatsEvent.getMillis()); + stackTop.leave(gwtStatsEvent.getMillis()); stack.removeLast(); stackTop = stack.getLast(); @@ -240,7 +240,7 @@ public class Profiler { return; } Node previousStackTop = stack.removeLast(); - previousStackTop.addTime(gwtStatsEvent.getMillis()); + previousStackTop.leave(gwtStatsEvent.getMillis()); } else { if (!inEvent) { stackTop = stackTop.enterChild(eventName, diff --git a/client/src/com/vaadin/client/debug/internal/ProfilerSection.java b/client/src/com/vaadin/client/debug/internal/ProfilerSection.java index aa40e8ff17..91f626b9a5 100644 --- a/client/src/com/vaadin/client/debug/internal/ProfilerSection.java +++ b/client/src/com/vaadin/client/debug/internal/ProfilerSection.java @@ -71,6 +71,9 @@ public class ProfilerSection implements Section { private final LinkedHashMap children = new LinkedHashMap(); private double time = 0; private int count = 0; + private double enterTime = 0; + private double minTime = 1000000000; + private double maxTime = 0; /** * Create a new node with the given name. @@ -96,17 +99,17 @@ public class ProfilerSection implements Section { * * @param name * the name of the child - * @param time + * @param timestamp * the timestamp for when the node is entered * @return the child node object */ - public Node enterChild(String name, double time) { + public Node enterChild(String name, double timestamp) { Node child = children.get(name); if (child == null) { child = new Node(name); children.put(name, child); } - child.time -= time; + child.enterTime = timestamp; child.count++; return child; } @@ -121,6 +124,26 @@ public class ProfilerSection implements Section { return time; } + /** + * Gets the minimum time spent for one invocation of this node, + * including time spent in sub nodes + * + * @return the time spent for the fastest invocation, in milliseconds + */ + public double getMinTimeSpent() { + return minTime; + } + + /** + * Gets the maximum time spent for one invocation of this node, + * including time spent in sub nodes + * + * @return the time spent for the slowest invocation, in milliseconds + */ + public double getMaxTimeSpent() { + return maxTime; + } + /** * Gets the number of times this node has been entered * @@ -180,7 +203,11 @@ public class ProfilerSection implements Section { + getCount() + " times (" + roundToSignificantFigures(getTimeSpent() / getCount()) - + " ms per time)."; + + " ms per time, min " + + roundToSignificantFigures(getMinTimeSpent()) + + " ms, max " + + roundToSignificantFigures(getMaxTimeSpent()) + + " ms)."; } if (!children.isEmpty()) { double ownTime = getOwnTime(); @@ -221,6 +248,10 @@ public class ProfilerSection implements Section { totalNode.time += getOwnTime(); totalNode.count += getCount(); + totalNode.minTime = Math.min(totalNode.minTime, + getMinTimeSpent()); + totalNode.maxTime = Math.max(totalNode.maxTime, + getMaxTimeSpent()); } for (Node node : children.values()) { node.sumUpTotals(totals); @@ -228,11 +259,18 @@ public class ProfilerSection implements Section { } /** - * @since - * @param time + * @param timestamp */ - public void addTime(double time) { - this.time += time; + public void leave(double timestamp) { + double elapsed = (timestamp - enterTime); + time += elapsed; + enterTime = 0; + if (elapsed < minTime) { + minTime = elapsed; + } + if (elapsed > maxTime) { + maxTime = elapsed; + } } } -- 2.39.5