Browse Source

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
tags/7.0.2
Leif Åstrand 11 years ago
parent
commit
d6cf871c7d

+ 24
- 1
client/src/com/vaadin/client/ApplicationConnection.java View File

@@ -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
*/
@@ -947,6 +958,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
@@ -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 "

+ 4
- 1
uitest/src/com/vaadin/tests/performance/BasicPerformanceTest.java View File

@@ -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() {

+ 7
- 4
uitest/src/com/vaadin/tests/util/TestUtils.java View File

@@ -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() {

Loading…
Cancel
Save