&& 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();
return;
}
Node previousStackTop = stack.removeLast();
- previousStackTop.addTime(gwtStatsEvent.getMillis());
+ previousStackTop.leave(gwtStatsEvent.getMillis());
} else {
if (!inEvent) {
stackTop = stackTop.enterChild(eventName,
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.
*
* @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;
}
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
*
+ 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();
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);
}
/**
- * @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;
+ }
}
}