Changeset 188946 in webkit


Ignore:
Timestamp:
Aug 25, 2015 11:29:48 PM (9 years ago)
Author:
BJ Burg
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.

Location:
trunk/Source/WebInspectorUI
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r188916 r188946  
     12015-08-25  Brian Burg  <bburg@apple.com>
     2
     3        Web Inspector: message dispatch metrics should use high-resolution timing data
     4        https://bugs.webkit.org/show_bug.cgi?id=135467
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        Use performance.now if it's available, otherwise fallback to Date.now().
     9        Format timestamps with fixed decimal point, and sprinkle some ES6.
     10
     11        * UserInterface/Base/Utilities.js:
     12        (timestamp): Added.
     13        * UserInterface/Protocol/InspectorBackend.js:
     14        (InspectorBackendClass):
     15        (InspectorBackendClass.prototype._sendCommandToBackendWithCallback):
     16        (InspectorBackendClass.prototype._dispatchEvent):
     17        * UserInterface/Protocol/MessageDispatcher.js:
     18        (WebInspector.dispatchNextQueuedMessageFromBackend):
     19        (WebInspector.dispatchMessageFromBackend): Be consistent about using `this`.
     20
    1212015-08-25  Matt Baker  <mattbaker@apple.com>
    222
  • trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js

    r188750 r188946  
    11251125    return new Blob(byteArrays, {type: mimeType});
    11261126}
     1127
     1128// FIXME: This can be removed when WEB_TIMING is enabled for all platforms.
     1129function timestamp()
     1130{
     1131    return window.performance ? performance.now() : Date.now();
     1132}
  • trunk/Source/WebInspectorUI/UserInterface/Protocol/InspectorBackend.js

    r188283 r188946  
    136136        let responseData = {command, callback};
    137137
    138         // FIXME: <https://webkit.org/b/135467> use performance.now() where available.
    139138        if (this.dumpInspectorTimeStats)
    140             responseData.sendRequestTime = Date.now();
     139            responseData.sendRequestTimestamp = timestamp();
    141140
    142141        this._pendingResponses.set(sequenceId, responseData);
     
    158157        let responseData = {command};
    159158
    160         // FIXME: <https://webkit.org/b/135467> use performance.now() where available.
    161159        if (this.dumpInspectorTimeStats)
    162             responseData.sendRequestTime = Date.now();
     160            responseData.sendRequestTimestamp = timestamp();
    163161
    164162        let responsePromise = new Promise(function(resolve, reject) {
     
    196194        let {command, callback, promise} = responseData;
    197195
    198         var processingStartTime;
     196        var processingStartTimestamp;
    199197        if (this.dumpInspectorTimeStats)
    200             processingStartTime = Date.now();
     198            processingStartTimestamp = timestamp();
    201199
    202200        if (typeof callback === "function")
     
    207205            console.error("Received a command response without a corresponding callback or promise.", messageObject, command);
    208206
    209         var processingDuration = Date.now() - processingStartTime;
     207        let processingDuration = (timestamp() - processingStartTimestamp).toFixed(3);
    210208        if (this.warnForLongMessageHandling && processingDuration > this.longMessageHandlingThreshold)
    211             console.warn("InspectorBackend: took " + processingDuration + "ms to handle response for command: " + command.qualifiedName);
    212 
    213         if (this.dumpInspectorTimeStats)
    214             console.log("time-stats: Handling: " + processingDuration + "ms; RTT: " + (processingStartTime - responseData.sendRequestTime) + "ms; (command " + command.qualifiedName + ")");
     209            console.warn(`InspectorBackend: took ${processingDuration}ms to handle response for command: ${command.qualifiedName}`);
     210
     211        if (this.dumpInspectorTimeStats) {
     212            let roundTripDuration = (processingStartTimestamp - responseData.sendRequestTimestamp).toFixed(3);
     213            console.log(`time-stats: Handling: ${processingDuration}ms; RTT: ${roundTripDuration}ms; (command ${command.qualifiedName})`);
     214        }
    215215
    216216        if (this._deferredScripts.length && !this._pendingResponses.size)
     
    272272        }
    273273
    274         var processingStartTime;
     274        var processingStartTimestamp;
    275275        if (this.dumpInspectorTimeStats)
    276             processingStartTime = Date.now();
     276            processingStartTimestamp = timestamp();
    277277
    278278        try {
     
    282282        }
    283283
    284         var processingDuration = Date.now() - processingStartTime;
     284        let processingDuration = (timestamp() - processingStartTimestamp).toFixed(3);
    285285        if (this.warnForLongMessageHandling && processingDuration > this.longMessageHandlingThreshold)
    286             console.warn("InspectorBackend: took " + processingDuration + "ms to handle event: " + messageObject["method"]);
     286            console.warn(`InspectorBackend: took ${processingDuration}ms to handle event: ${messageObject.method}`);
    287287
    288288        if (this.dumpInspectorTimeStats)
    289             console.log("time-stats: Handling: " + processingDuration + "ms (event " + messageObject["method"] + ")");
     289            console.log(`time-stats: Handling: ${processingDuration}ms (event ${messageObject.method})`);
    290290    }
    291291
  • trunk/Source/WebInspectorUI/UserInterface/Protocol/MessageDispatcher.js

    r182039 r188946  
    2929WebInspector.dispatchNextQueuedMessageFromBackend = function()
    3030{
    31     var startCount = WebInspector._messagesToDispatch.length;
    32     var startTime = Date.now();
    33     var timeLimitPerRunLoop = 10; // milliseconds
     31    const startCount = WebInspector._messagesToDispatch.length;
     32    const startTimestamp = timestamp();
     33    const timeLimitPerRunLoop = 10; // milliseconds
    3434
    35     var i = 0;
     35    let i = 0;
    3636    for (; i < WebInspector._messagesToDispatch.length; ++i) {
    3737        // Defer remaining messages if we have taken too long. In practice, single
    3838        // messages like Page.getResourceContent blow through the time budget.
    39         if (Date.now() - startTime > timeLimitPerRunLoop)
     39        if (timestamp() - startTimestamp > timeLimitPerRunLoop)
    4040            break;
    4141
     
    5151    }
    5252
    53     if (InspectorBackend.dumpInspectorTimeStats)
    54         console.log("time-stats: --- RunLoop duration: " + (Date.now() - startTime) + "ms; dispatched: " + (startCount - WebInspector._messagesToDispatch.length) + "; remaining: " + WebInspector._messagesToDispatch.length);
     53    if (InspectorBackend.dumpInspectorTimeStats) {
     54        let messageDuration = (timestamp() - startTimestamp).toFixed(3);
     55        let dispatchedCount = startCount - WebInspector._messagesToDispatch.length;
     56        let remainingCount = WebInspector._messagesToDispatch.length;
     57        console.log(`time-stats: --- RunLoop duration: ${messageDuration}ms; dispatched: ${dispatchedCount}; remaining: ${remainingCount}`);
     58    }
    5559};
    5660
     
    6064    // The messages are dequeued on a zero delay timeout.
    6165
    62     WebInspector._messagesToDispatch.push(message);
     66    this._messagesToDispatch.push(message);
    6367
    6468    if (this._dispatchTimeout)
    6569        return;
    6670
    67     this._dispatchTimeout = setTimeout(WebInspector.dispatchNextQueuedMessageFromBackend, 0);
     71    this._dispatchTimeout = setTimeout(this.dispatchNextQueuedMessageFromBackend, 0);
    6872};
Note: See TracChangeset for help on using the changeset viewer.