Title: [188946] trunk/Source/WebInspectorUI
Revision
188946
Author
bb...@apple.com
Date
2015-08-25 23:29:48 -0700 (Tue, 25 Aug 2015)

Log Message

Web Inspector: message dispatch metrics should use high-resolution timing data
https://bugs.webkit.org/show_bug.cgi?id=135467

Reviewed by Timothy Hatcher.

Use performance.now if it's available, otherwise fallback to Date.now().
Format timestamps with fixed decimal point, and sprinkle some ES6.

* UserInterface/Base/Utilities.js:
(timestamp): Added.
* UserInterface/Protocol/InspectorBackend.js:
(InspectorBackendClass):
(InspectorBackendClass.prototype._sendCommandToBackendWithCallback):
(InspectorBackendClass.prototype._dispatchEvent):
* UserInterface/Protocol/MessageDispatcher.js:
(WebInspector.dispatchNextQueuedMessageFromBackend):
(WebInspector.dispatchMessageFromBackend): Be consistent about using `this`.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (188945 => 188946)


--- trunk/Source/WebInspectorUI/ChangeLog	2015-08-26 05:47:59 UTC (rev 188945)
+++ trunk/Source/WebInspectorUI/ChangeLog	2015-08-26 06:29:48 UTC (rev 188946)
@@ -1,3 +1,23 @@
+2015-08-25  Brian Burg  <bb...@apple.com>
+
+        Web Inspector: message dispatch metrics should use high-resolution timing data
+        https://bugs.webkit.org/show_bug.cgi?id=135467
+
+        Reviewed by Timothy Hatcher.
+
+        Use performance.now if it's available, otherwise fallback to Date.now().
+        Format timestamps with fixed decimal point, and sprinkle some ES6.
+
+        * UserInterface/Base/Utilities.js:
+        (timestamp): Added.
+        * UserInterface/Protocol/InspectorBackend.js:
+        (InspectorBackendClass):
+        (InspectorBackendClass.prototype._sendCommandToBackendWithCallback):
+        (InspectorBackendClass.prototype._dispatchEvent):
+        * UserInterface/Protocol/MessageDispatcher.js:
+        (WebInspector.dispatchNextQueuedMessageFromBackend):
+        (WebInspector.dispatchMessageFromBackend): Be consistent about using `this`.
+
 2015-08-25  Matt Baker  <mattba...@apple.com>
 
         Web Inspector: Rendering Frames pie chart should use the needsLayout/updateLayout idiom

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js (188945 => 188946)


--- trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2015-08-26 05:47:59 UTC (rev 188945)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2015-08-26 06:29:48 UTC (rev 188946)
@@ -1124,3 +1124,9 @@
 
     return new Blob(byteArrays, {type: mimeType});
 }
+
+// FIXME: This can be removed when WEB_TIMING is enabled for all platforms.
+function timestamp()
+{
+    return window.performance ? performance.now() : Date.now();
+}

Modified: trunk/Source/WebInspectorUI/UserInterface/Protocol/InspectorBackend.js (188945 => 188946)


--- trunk/Source/WebInspectorUI/UserInterface/Protocol/InspectorBackend.js	2015-08-26 05:47:59 UTC (rev 188945)
+++ trunk/Source/WebInspectorUI/UserInterface/Protocol/InspectorBackend.js	2015-08-26 06:29:48 UTC (rev 188946)
@@ -135,9 +135,8 @@
 
         let responseData = {command, callback};
 
-        // FIXME: <https://webkit.org/b/135467> use performance.now() where available.
         if (this.dumpInspectorTimeStats)
-            responseData.sendRequestTime = Date.now();
+            responseData.sendRequestTimestamp = timestamp();
 
         this._pendingResponses.set(sequenceId, responseData);
         this._sendMessageToBackend(messageObject);
@@ -157,9 +156,8 @@
 
         let responseData = {command};
 
-        // FIXME: <https://webkit.org/b/135467> use performance.now() where available.
         if (this.dumpInspectorTimeStats)
-            responseData.sendRequestTime = Date.now();
+            responseData.sendRequestTimestamp = timestamp();
 
         let responsePromise = new Promise(function(resolve, reject) {
             responseData.promise = {resolve, reject};
@@ -195,9 +193,9 @@
         let responseData = this._pendingResponses.take(sequenceId);
         let {command, callback, promise} = responseData;
 
-        var processingStartTime;
+        var processingStartTimestamp;
         if (this.dumpInspectorTimeStats)
-            processingStartTime = Date.now();
+            processingStartTimestamp = timestamp();
 
         if (typeof callback === "function")
             this._dispatchResponseToCallback(command, messageObject, callback);
@@ -206,12 +204,14 @@
         else
             console.error("Received a command response without a corresponding callback or promise.", messageObject, command);
 
-        var processingDuration = Date.now() - processingStartTime;
+        let processingDuration = (timestamp() - processingStartTimestamp).toFixed(3);
         if (this.warnForLongMessageHandling && processingDuration > this.longMessageHandlingThreshold)
-            console.warn("InspectorBackend: took " + processingDuration + "ms to handle response for command: " + command.qualifiedName);
+            console.warn(`InspectorBackend: took ${processingDuration}ms to handle response for command: ${command.qualifiedName}`);
 
-        if (this.dumpInspectorTimeStats)
-            console.log("time-stats: Handling: " + processingDuration + "ms; RTT: " + (processingStartTime - responseData.sendRequestTime) + "ms; (command " + command.qualifiedName + ")");
+        if (this.dumpInspectorTimeStats) {
+            let roundTripDuration = (processingStartTimestamp - responseData.sendRequestTimestamp).toFixed(3);
+            console.log(`time-stats: Handling: ${processingDuration}ms; RTT: ${roundTripDuration}ms; (command ${command.qualifiedName})`);
+        }
 
         if (this._deferredScripts.length && !this._pendingResponses.size)
             this._flushPendingScripts();
@@ -271,9 +271,9 @@
                 eventArguments.push(messageObject["params"][parameterNames[i]]);
         }
 
-        var processingStartTime;
+        var processingStartTimestamp;
         if (this.dumpInspectorTimeStats)
-            processingStartTime = Date.now();
+            processingStartTimestamp = timestamp();
 
         try {
             agent.dispatchEvent(eventName, eventArguments);
@@ -281,12 +281,12 @@
             console.error("Uncaught exception in inspector page while handling event " + qualifiedName + ": ", e, e.stack);
         }
 
-        var processingDuration = Date.now() - processingStartTime;
+        let processingDuration = (timestamp() - processingStartTimestamp).toFixed(3);
         if (this.warnForLongMessageHandling && processingDuration > this.longMessageHandlingThreshold)
-            console.warn("InspectorBackend: took " + processingDuration + "ms to handle event: " + messageObject["method"]);
+            console.warn(`InspectorBackend: took ${processingDuration}ms to handle event: ${messageObject.method}`);
 
         if (this.dumpInspectorTimeStats)
-            console.log("time-stats: Handling: " + processingDuration + "ms (event " + messageObject["method"] + ")");
+            console.log(`time-stats: Handling: ${processingDuration}ms (event ${messageObject.method})`);
     }
 
     _reportProtocolError(messageObject)

Modified: trunk/Source/WebInspectorUI/UserInterface/Protocol/MessageDispatcher.js (188945 => 188946)


--- trunk/Source/WebInspectorUI/UserInterface/Protocol/MessageDispatcher.js	2015-08-26 05:47:59 UTC (rev 188945)
+++ trunk/Source/WebInspectorUI/UserInterface/Protocol/MessageDispatcher.js	2015-08-26 06:29:48 UTC (rev 188946)
@@ -28,15 +28,15 @@
 
 WebInspector.dispatchNextQueuedMessageFromBackend = function()
 {
-    var startCount = WebInspector._messagesToDispatch.length;
-    var startTime = Date.now();
-    var timeLimitPerRunLoop = 10; // milliseconds
+    const startCount = WebInspector._messagesToDispatch.length;
+    const startTimestamp = timestamp();
+    const timeLimitPerRunLoop = 10; // milliseconds
 
-    var i = 0;
+    let i = 0;
     for (; i < WebInspector._messagesToDispatch.length; ++i) {
         // Defer remaining messages if we have taken too long. In practice, single
         // messages like Page.getResourceContent blow through the time budget.
-        if (Date.now() - startTime > timeLimitPerRunLoop)
+        if (timestamp() - startTimestamp > timeLimitPerRunLoop)
             break;
 
         InspectorBackend.dispatch(WebInspector._messagesToDispatch[i]);
@@ -50,8 +50,12 @@
         WebInspector._dispatchTimeout = setTimeout(WebInspector.dispatchNextQueuedMessageFromBackend, 0);
     }
 
-    if (InspectorBackend.dumpInspectorTimeStats)
-        console.log("time-stats: --- RunLoop duration: " + (Date.now() - startTime) + "ms; dispatched: " + (startCount - WebInspector._messagesToDispatch.length) + "; remaining: " + WebInspector._messagesToDispatch.length);
+    if (InspectorBackend.dumpInspectorTimeStats) {
+        let messageDuration = (timestamp() - startTimestamp).toFixed(3);
+        let dispatchedCount = startCount - WebInspector._messagesToDispatch.length;
+        let remainingCount = WebInspector._messagesToDispatch.length;
+        console.log(`time-stats: --- RunLoop duration: ${messageDuration}ms; dispatched: ${dispatchedCount}; remaining: ${remainingCount}`);
+    }
 };
 
 WebInspector.dispatchMessageFromBackend = function(message)
@@ -59,10 +63,10 @@
     // Enforce asynchronous interaction between the backend and the frontend by queueing messages.
     // The messages are dequeued on a zero delay timeout.
 
-    WebInspector._messagesToDispatch.push(message);
+    this._messagesToDispatch.push(message);
 
     if (this._dispatchTimeout)
         return;
 
-    this._dispatchTimeout = setTimeout(WebInspector.dispatchNextQueuedMessageFromBackend, 0);
+    this._dispatchTimeout = setTimeout(this.dispatchNextQueuedMessageFromBackend, 0);
 };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to