]> source.dussan.org Git - vaadin-framework.git/commitdiff
Report min and max times from Profiler (#12409)
authorHenri Sara <hesara@vaadin.com>
Tue, 20 Aug 2013 09:21:18 +0000 (12:21 +0300)
committerHenri Sara <hesara@vaadin.com>
Tue, 20 Aug 2013 09:21:18 +0000 (12:21 +0300)
Change-Id: Ifb88038baf9c1b9c872840030dcaefd7b8488f64

client/src/com/vaadin/client/Profiler.java
client/src/com/vaadin/client/debug/internal/ProfilerSection.java

index caa512b34eea7c9cbac253104b69e3e1ca1fc117..bcbf8279f3f70dc03635d3e4b7d504075c80c20b 100644 (file)
@@ -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,
index aa40e8ff174ae8abb5af99d86176179fb4c1d8b8..91f626b9a59be4f8f7c5fd31c151c17aa9b48818 100644 (file)
@@ -71,6 +71,9 @@ public class ProfilerSection implements Section {
         private final LinkedHashMap<String, Node> children = new LinkedHashMap<String, Node>();
         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;
+            }
         }
     }