aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2013-02-28 13:10:09 +0200
committerLeif Åstrand <leif@vaadin.com>2013-03-01 16:45:52 +0200
commitd6cf871c7d3cd7e48db3450b02361e24fe652670 (patch)
tree51f466aba61b28ba1e250df33e2548dadffc4aa4
parent7f9e51e0e31c5c0a699c7ca486aaf993d5aec347 (diff)
downloadvaadin-framework-d6cf871c7d3cd7e48db3450b02361e24fe652670.tar.gz
vaadin-framework-d6cf871c7d3cd7e48db3450b02361e24fe652670.zip
Add bootstrap performance measuring support (#11188)
svn changeset:25664/svn branch:6.8 Conflicts: client/src/com/vaadin/client/ApplicationConnection.java uitest/src/com/vaadin/tests/performance/BasicPerformanceTest.java uitest/src/com/vaadin/tests/util/TestUtils.java Change-Id: I699e7b47ad5a62b67dbdf1004da5e5daf009ba25
-rw-r--r--client/src/com/vaadin/client/ApplicationConnection.java25
-rw-r--r--uitest/src/com/vaadin/tests/performance/BasicPerformanceTest.java5
-rw-r--r--uitest/src/com/vaadin/tests/util/TestUtils.java11
3 files changed, 35 insertions, 6 deletions
diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java
index 1a637e3161..ab9f95e8fd 100644
--- a/client/src/com/vaadin/client/ApplicationConnection.java
+++ b/client/src/com/vaadin/client/ApplicationConnection.java
@@ -16,7 +16,7 @@
package com.vaadin.client;
-import java.util.ArrayList;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
@@ -500,6 +500,7 @@ public class ApplicationConnection {
ap.@com.vaadin.client.ApplicationConnection::totalProcessingTime
];
pd = pd.concat(ap.@com.vaadin.client.ApplicationConnection::serverTimingInfo);
+ pd[pd.length] = ap.@com.vaadin.client.ApplicationConnection::bootstrapTime;
return pd;
});
@@ -513,6 +514,16 @@ public class ApplicationConnection {
$wnd.vaadin.clients[TTAppId] = client;
}-*/;
+ private static native final int calculateBootstrapTime()
+ /*-{
+ if ($wnd.performance && $wnd.performance.timing) {
+ return (new Date).getTime() - $wnd.performance.timing.responseStart;
+ } else {
+ // performance.timing not supported
+ return -1;
+ }
+ }-*/;
+
/**
* Helper for tt initialization
*/
@@ -948,6 +959,15 @@ public class ApplicationConnection {
protected int totalProcessingTime;
/**
+ * Holds the time it took to load the page and render the first view. 0
+ * means that this value has not yet been calculated because the first view
+ * has not yet been rendered (or that your browser is very fast). -1 means
+ * that the browser does not support the performance.timing feature used to
+ * get this measurement.
+ */
+ private int bootstrapTime;
+
+ /**
* Holds the timing information from the server-side. How much time was
* spent servicing the last request and how much time has been spent
* servicing the session so far. These values are always one request behind,
@@ -1512,6 +1532,9 @@ public class ApplicationConnection {
lastProcessingTime = (int) ((new Date().getTime()) - start
.getTime());
totalProcessingTime += lastProcessingTime;
+ if (bootstrapTime == 0) {
+ bootstrapTime = calculateBootstrapTime();
+ }
VConsole.log(" Processing time was "
+ String.valueOf(lastProcessingTime) + "ms for "
diff --git a/uitest/src/com/vaadin/tests/performance/BasicPerformanceTest.java b/uitest/src/com/vaadin/tests/performance/BasicPerformanceTest.java
index b0047d6b62..04fe18fc08 100644
--- a/uitest/src/com/vaadin/tests/performance/BasicPerformanceTest.java
+++ b/uitest/src/com/vaadin/tests/performance/BasicPerformanceTest.java
@@ -22,13 +22,14 @@ public class BasicPerformanceTest extends UI {
private int clientLimit;
private int serverLimit;
+ private boolean reportBootstap = true;
private String performanceTopic;
private final Button reportPerformanceButton = new Button(
"Report some performance", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
TestUtils.reportPerformance(performanceTopic, serverLimit,
- clientLimit);
+ clientLimit, reportBootstap);
event.getButton().setEnabled(false);
}
});
@@ -37,6 +38,7 @@ public class BasicPerformanceTest extends UI {
public void init(VaadinRequest request) {
setContent(buildMainLayout());
updatePerformanceReporting("first load", 100, 100);
+ reportBootstap = true;
}
private void updatePerformanceReporting(String performanceTopic,
@@ -47,6 +49,7 @@ public class BasicPerformanceTest extends UI {
reportPerformanceButton.setCaption("Report performance for "
+ performanceTopic);
reportPerformanceButton.setEnabled(true);
+ reportBootstap = false;
}
private ComponentContainer buildMainLayout() {
diff --git a/uitest/src/com/vaadin/tests/util/TestUtils.java b/uitest/src/com/vaadin/tests/util/TestUtils.java
index 6cb6e79c1c..5c6315a23a 100644
--- a/uitest/src/com/vaadin/tests/util/TestUtils.java
+++ b/uitest/src/com/vaadin/tests/util/TestUtils.java
@@ -120,20 +120,23 @@ public class TestUtils {
public static void installPerformanceReporting(TextArea targetTextArea) {
targetTextArea.setId("performanceTestTarget");
JavaScript
- .eval("window.reportVaadinPerformance = function(topic, serverLimit, clientLimit) {"
+ .eval("window.reportVaadinPerformance = function(topic, serverLimit, clientLimit, bootstrapTime) {"
+ "var element = document.getElementById('performanceTestTarget');"
+ "var text = topic + ': \\n';"
+ "for(var k in window.vaadin.clients) {"
+ "var p = window.vaadin.clients[k].getProfilingData();"
+ "text += ' Server time: ' + (p[3] > serverLimit?'FAIL':'OK') + ' (' + p[3] +')\\n';"
+ "text += ' Client time: ' + (p[0] > clientLimit?'FAIL':'OK') + ' (' + p[0] +')\\n';"
+ + "if (bootstrapTime) text += ' Bootstrap time: ' + (p[4] > clientLimit?'FAIL':'OK') + ' (' + p[4] +')\\n';"
+ "}" + "element.value = text;" + "}");
}
public static void reportPerformance(String topic, int serverLimit,
- int totalLimit) {
- JavaScript.eval("window.reportVaadinPerformance(\"" + topic + "\", "
- + serverLimit + ", " + totalLimit + ");");
+ int clientLimit, boolean bootstrapTime) {
+ JavaScript
+ .eval("window.reportVaadinPerformance(\"" + topic + "\", "
+ + serverLimit + ", " + clientLimit + ","
+ + bootstrapTime + ");");
}
public static IndexedContainer getISO3166Container() {