From 276e6fc6c1d2643c77d0e4abea8cf862cd8b9718 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Fri, 1 Mar 2013 18:17:57 +0200 Subject: [PATCH] Add performance.timing support to Profiler (#11188) Change-Id: I3fb14b1280a1ee8bfaa2aeab87b40c374d2e4443 --- .../vaadin/client/ApplicationConnection.java | 3 + client/src/com/vaadin/client/Profiler.java | 57 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index ab9f95e8fd..2610530a80 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -1534,6 +1534,9 @@ public class ApplicationConnection { totalProcessingTime += lastProcessingTime; if (bootstrapTime == 0) { bootstrapTime = calculateBootstrapTime(); + if (Profiler.isEnabled() && bootstrapTime != -1) { + Profiler.logBootstrapTimings(); + } } VConsole.log(" Processing time was " diff --git a/client/src/com/vaadin/client/Profiler.java b/client/src/com/vaadin/client/Profiler.java index be26da859f..15de339572 100644 --- a/client/src/com/vaadin/client/Profiler.java +++ b/client/src/com/vaadin/client/Profiler.java @@ -362,4 +362,61 @@ public class Profiler { return false; } + /** + * Outputs the time passed since various events recored in + * performance.timing if supported by the browser. + */ + public static void logBootstrapTimings() { + if (isEnabled()) { + double now = Duration.currentTimeMillis(); + + StringBuilder stringBuilder = new StringBuilder( + "Time since window.performance.timing events"); + SimpleTree tree = new SimpleTree(stringBuilder.toString()); + + String[] keys = new String[] { "navigationStart", + "unloadEventStart", "unloadEventEnd", "redirectStart", + "redirectEnd", "fetchStart", "domainLookupStart", + "domainLookupEnd", "connectStart", "connectEnd", + "requestStart", "responseStart", "responseEnd", + "domLoading", "domInteractive", + "domContentLoadedEventStart", "domContentLoadedEventEnd", + "domComplete", "loadEventStart", "loadEventEnd" }; + + for (String key : keys) { + double value = getPerformanceTiming(key); + if (value == 0) { + // Ignore missing value + continue; + } + String text = key + ": " + (now - value); + tree.add(new Label(text)); + stringBuilder.append("\n * "); + stringBuilder.append(text); + } + + if (tree.getWidgetCount() == 0) { + VConsole.log("Bootstrap timings not supported, please ensure your browser supports performance.timing"); + return; + } + + Console implementation = VConsole.getImplementation(); + if (implementation instanceof VDebugConsole) { + VDebugConsole console = (VDebugConsole) implementation; + console.showTree(tree, stringBuilder.toString()); + } else { + VConsole.log(stringBuilder.toString()); + } + } + } + + private static final native double getPerformanceTiming(String name) + /*-{ + if ($wnd.performance && $wnd.performance.timing && $wnd.performance.timing[name]) { + return $wnd.performance.timing[name]; + } else { + return 0; + } + }-*/; + } -- 2.39.5