Title: [115503] trunk
Revision
115503
Author
[email protected]
Date
2012-04-27 15:34:46 -0700 (Fri, 27 Apr 2012)

Log Message

Source/WebCore: Implement high-resolution time via window.performance.webkitNow()
https://bugs.webkit.org/show_bug.cgi?id=66684

This implements the high resolution time spec from
http://www.w3.org/TR/hr-time/, giving _javascript_ access to
sub-millisecond timestamps that increase over time instead of being
subject to skewing, for example when the host machine's clock changes.

Reviewed by Tony Gentilcore.

Test: fast/performance/performance-now-timestamps.html

* page/Performance.cpp:
(WebCore::Performance::now):
(WebCore):
* page/Performance.h:
(Performance):
* page/Performance.idl:

LayoutTests: Implement high-resolution time via window.performance.now()
https://bugs.webkit.org/show_bug.cgi?id=66684

This implements the high resolution time spec from
http://www.w3.org/TR/hr-time/, giving _javascript_ access to
sub-millisecond timestamps that increase over time instead of being
subject to skewing, for example when the host machine's clock changes.

Reviewed by Tony Gentilcore.

* fast/dom/Window/window-properties-performance-expected.txt:
* fast/performance/performance-now-timestamps-expected.txt: Added.
* fast/performance/performance-now-timestamps.html: Added.
* fast/performance/script-tests/TEMPLATE.html: Added.
* fast/performance/script-tests/performance-now-timestamps.js: Added.
(busyWait):
* platform/qt/fast/dom/Window/window-properties-performance-expected.txt:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (115502 => 115503)


--- trunk/LayoutTests/ChangeLog	2012-04-27 22:30:39 UTC (rev 115502)
+++ trunk/LayoutTests/ChangeLog	2012-04-27 22:34:46 UTC (rev 115503)
@@ -1,3 +1,23 @@
+2012-04-27  Nat Duca  <[email protected]>
+
+        Implement high-resolution time via window.performance.now()
+        https://bugs.webkit.org/show_bug.cgi?id=66684
+
+        This implements the high resolution time spec from
+        http://www.w3.org/TR/hr-time/, giving _javascript_ access to
+        sub-millisecond timestamps that increase over time instead of being
+        subject to skewing, for example when the host machine's clock changes.
+
+        Reviewed by Tony Gentilcore.
+
+        * fast/dom/Window/window-properties-performance-expected.txt:
+        * fast/performance/performance-now-timestamps-expected.txt: Added.
+        * fast/performance/performance-now-timestamps.html: Added.
+        * fast/performance/script-tests/TEMPLATE.html: Added.
+        * fast/performance/script-tests/performance-now-timestamps.js: Added.
+        (busyWait):
+        * platform/qt/fast/dom/Window/window-properties-performance-expected.txt:
+
 2012-04-27  Tony Chang  <[email protected]>
 
         remove LayoutTests/platform/mac-leopard

Modified: trunk/LayoutTests/fast/dom/Window/window-properties-performance-expected.txt (115502 => 115503)


--- trunk/LayoutTests/fast/dom/Window/window-properties-performance-expected.txt	2012-04-27 22:30:39 UTC (rev 115502)
+++ trunk/LayoutTests/fast/dom/Window/window-properties-performance-expected.txt	2012-04-27 22:34:46 UTC (rev 115503)
@@ -34,6 +34,7 @@
 window.performance.timing.secureConnectionStart [number]
 window.performance.timing.unloadEventEnd [number]
 window.performance.timing.unloadEventStart [number]
+window.performance.webkitNow [function]
 window.performance.timing [printed above as window.performance.timing]
 window.performance.navigation [printed above as window.performance.navigation]
 window.performance [string]

Added: trunk/LayoutTests/fast/performance/performance-now-timestamps-expected.txt (0 => 115503)


--- trunk/LayoutTests/fast/performance/performance-now-timestamps-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/performance/performance-now-timestamps-expected.txt	2012-04-27 22:34:46 UTC (rev 115503)
@@ -0,0 +1,16 @@
+Tests the timestamps from performance.webkitNow increase and are in milliseconds
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS firstTimestamp is defined.
+PASS firstTimestamp is >= 0
+PASS firstTimestamp < 5000 is true
+PASS secondTimestamp is defined.
+PASS secondTimestamp is >= firstTimestamp + (waitTime / 2)
+PASS elapsed is >= 1
+PASS elapsed < 100 is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/performance/performance-now-timestamps.html (0 => 115503)


--- trunk/LayoutTests/fast/performance/performance-now-timestamps.html	                        (rev 0)
+++ trunk/LayoutTests/fast/performance/performance-now-timestamps.html	2012-04-27 22:34:46 UTC (rev 115503)
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<span id="e"></span>
+<span id="f"></span>
+<script src=""
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/performance/script-tests/TEMPLATE.html (0 => 115503)


--- trunk/LayoutTests/fast/performance/script-tests/TEMPLATE.html	                        (rev 0)
+++ trunk/LayoutTests/fast/performance/script-tests/TEMPLATE.html	2012-04-27 22:34:46 UTC (rev 115503)
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<span id="e"></span>
+<span id="f"></span>
+<script src=""
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/performance/script-tests/performance-now-timestamps.js (0 => 115503)


--- trunk/LayoutTests/fast/performance/script-tests/performance-now-timestamps.js	                        (rev 0)
+++ trunk/LayoutTests/fast/performance/script-tests/performance-now-timestamps.js	2012-04-27 22:34:46 UTC (rev 115503)
@@ -0,0 +1,28 @@
+description("Tests the timestamps from performance.webkitNow increase and are in milliseconds");
+
+function busyWait(millis) {
+    var start = Date.now();
+    while (Date.now() - start < millis) {}
+}
+
+var firstTimestamp = window.performance.webkitNow();
+shouldBeDefined("firstTimestamp");
+shouldBeGreaterThanOrEqual("firstTimestamp", "0");
+
+// Verify returned value is in milliseconds since navigationStart. This
+// generously assumes this JS will run within the first 5 seconds while ruling
+// out the possibility that the returned value is in milliseconds since epoch.
+shouldBeTrue("firstTimestamp < 5000");
+
+var waitTime = 10;
+busyWait(waitTime);
+
+var secondTimestamp = window.performance.webkitNow();
+shouldBeDefined("secondTimestamp");
+shouldBeGreaterThanOrEqual("secondTimestamp", "firstTimestamp + (waitTime / 2)");
+
+// Verify that the difference is in the milliseconds range, keeping
+// the range test broad to avoid issues on overloaded bots.
+var elapsed = secondTimestamp - firstTimestamp;
+shouldBeGreaterThanOrEqual("elapsed", "1");
+shouldBeTrue("elapsed < 100");
\ No newline at end of file

Modified: trunk/LayoutTests/platform/qt/fast/dom/Window/window-properties-performance-expected.txt (115502 => 115503)


--- trunk/LayoutTests/platform/qt/fast/dom/Window/window-properties-performance-expected.txt	2012-04-27 22:30:39 UTC (rev 115502)
+++ trunk/LayoutTests/platform/qt/fast/dom/Window/window-properties-performance-expected.txt	2012-04-27 22:34:46 UTC (rev 115503)
@@ -34,6 +34,7 @@
 window.performance.timing.secureConnectionStart [number]
 window.performance.timing.unloadEventEnd [number]
 window.performance.timing.unloadEventStart [number]
+window.performance.webkitNow [function]
 window.performance.timing [printed above as window.performance.timing]
 window.performance.navigation [printed above as window.performance.navigation]
 window.performance [string]

Modified: trunk/Source/WebCore/ChangeLog (115502 => 115503)


--- trunk/Source/WebCore/ChangeLog	2012-04-27 22:30:39 UTC (rev 115502)
+++ trunk/Source/WebCore/ChangeLog	2012-04-27 22:34:46 UTC (rev 115503)
@@ -1,3 +1,24 @@
+2012-04-27  Nat Duca  <[email protected]>
+
+        Implement high-resolution time via window.performance.webkitNow()
+        https://bugs.webkit.org/show_bug.cgi?id=66684
+
+        This implements the high resolution time spec from
+        http://www.w3.org/TR/hr-time/, giving _javascript_ access to
+        sub-millisecond timestamps that increase over time instead of being
+        subject to skewing, for example when the host machine's clock changes.
+
+        Reviewed by Tony Gentilcore.
+
+        Test: fast/performance/performance-now-timestamps.html
+
+        * page/Performance.cpp:
+        (WebCore::Performance::now):
+        (WebCore):
+        * page/Performance.h:
+        (Performance):
+        * page/Performance.idl:
+
 2012-04-27  Filip Pizlo  <[email protected]>
 
         If you get a list of DOMWrapperWorld*'s and then plan to allocate in the heap, you should ref

Modified: trunk/Source/WebCore/loader/DocumentLoadTiming.cpp (115502 => 115503)


--- trunk/Source/WebCore/loader/DocumentLoadTiming.cpp	2012-04-27 22:30:39 UTC (rev 115502)
+++ trunk/Source/WebCore/loader/DocumentLoadTiming.cpp	2012-04-27 22:34:46 UTC (rev 115503)
@@ -96,4 +96,11 @@
     return m_referenceWallTime + monotonicTime - m_referenceMonotonicTime;
 }
 
+double DocumentLoadTiming::convertMonotonicTimeToZeroBasedDocumentTime(double monotonicTime) const
+{
+    if (!monotonicTime)
+        return 0.0;
+    return monotonicTime - m_referenceMonotonicTime;
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/loader/DocumentLoadTiming.h (115502 => 115503)


--- trunk/Source/WebCore/loader/DocumentLoadTiming.h	2012-04-27 22:30:39 UTC (rev 115502)
+++ trunk/Source/WebCore/loader/DocumentLoadTiming.h	2012-04-27 22:34:46 UTC (rev 115503)
@@ -40,8 +40,13 @@
     void markNavigationStart(Frame*);
     void setNavigationStart(double);
     void addRedirect(const KURL& redirectingUrl, const KURL& redirectedUrl);
-    double convertMonotonicTimeToDocumentTime(double monotonicTime) const;
+    double convertMonotonicTimeToDocumentTime(double) const;
 
+    // FIXME: Once convertMonotonicTimeToDocumentTime is zero-based, then this
+    // function and convertMonotonicTimeToDocumentTime can be merged. See
+    // https://bugs.webkit.org/show_bug.cgi?id=84912 for more details.
+    double convertMonotonicTimeToZeroBasedDocumentTime(double) const;
+
     void markUnloadEventStart() { m_unloadEventStart = monotonicallyIncreasingTime(); }
     void markUnloadEventEnd() { m_unloadEventEnd = monotonicallyIncreasingTime(); }
     void markRedirectStart() { m_redirectStart = monotonicallyIncreasingTime(); }

Modified: trunk/Source/WebCore/page/Performance.cpp (115502 => 115503)


--- trunk/Source/WebCore/page/Performance.cpp	2012-04-27 22:30:39 UTC (rev 115502)
+++ trunk/Source/WebCore/page/Performance.cpp	2012-04-27 22:34:46 UTC (rev 115503)
@@ -31,9 +31,12 @@
 #include "config.h"
 #include "Performance.h"
 
+#include "Document.h"
+#include "DocumentLoader.h"
 #include "MemoryInfo.h"
 #include "PerformanceNavigation.h"
 #include "PerformanceTiming.h"
+#include <wtf/CurrentTime.h>
 
 #if ENABLE(WEB_TIMING)
 
@@ -89,6 +92,11 @@
 
 #endif // ENABLE(PERFORMANCE_TIMELINE)
 
+double Performance::webkitNow() const
+{
+    return 1000.0 * m_frame->document()->loader()->timing()->convertMonotonicTimeToZeroBasedDocumentTime(monotonicallyIncreasingTime());
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEB_TIMING)

Modified: trunk/Source/WebCore/page/Performance.h (115502 => 115503)


--- trunk/Source/WebCore/page/Performance.h	2012-04-27 22:30:39 UTC (rev 115502)
+++ trunk/Source/WebCore/page/Performance.h	2012-04-27 22:34:46 UTC (rev 115503)
@@ -52,6 +52,7 @@
     PassRefPtr<MemoryInfo> memory() const;
     PerformanceNavigation* navigation() const;
     PerformanceTiming* timing() const;
+    double webkitNow() const;
 
 #if ENABLE(PERFORMANCE_TIMELINE)
     PassRefPtr<PerformanceEntryList> webkitGetEntries() const;

Modified: trunk/Source/WebCore/page/Performance.idl (115502 => 115503)


--- trunk/Source/WebCore/page/Performance.idl	2012-04-27 22:30:39 UTC (rev 115502)
+++ trunk/Source/WebCore/page/Performance.idl	2012-04-27 22:34:46 UTC (rev 115503)
@@ -44,6 +44,8 @@
         PerformanceEntryList webkitGetEntriesByType(in DOMString entryType);
         PerformanceEntryList webkitGetEntriesByName(in DOMString name, in [Optional=DefaultIsNullString] DOMString entryType);
 #endif
+        // See http://www.w3.org/TR/hr-time/ for details.
+        double webkitNow();
     };
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to