WebInspector: Confusingly nested events in the timeline for Mutation Observers
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Jan 2019 19:29:18 +0000 (19:29 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Jan 2019 19:29:18 +0000 (19:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192884
<rdar://problem/46854178>

Reviewed by Joseph Pecoraro.

If a microtask event (e.g. `ObserverCallback`) is contained within a `EvaluatedScript`
event, move that microtask event to be a sibling of the `EvaluateScript`, subtracting the
microtask's time taken from the `EvaluateScript`'s time. If there are no other children
after this move, then remove the `EvaluateScript` altogether.

* UserInterface/Controllers/TimelineManager.js:
(WI.TimelineManager.prototype.eventRecorded.fixMicrotaskPlacement): Added.
(WI.TimelineManager.prototype.eventRecorded):
(WI.TimelineManager.prototype._mergeScriptProfileRecords):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240351 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Controllers/TimelineManager.js

index e6a7cc0..2c0371f 100644 (file)
@@ -1,3 +1,21 @@
+2019-01-23  Devin Rousso  <drousso@apple.com>
+
+        WebInspector: Confusingly nested events in the timeline for Mutation Observers
+        https://bugs.webkit.org/show_bug.cgi?id=192884
+        <rdar://problem/46854178>
+
+        Reviewed by Joseph Pecoraro.
+
+        If a microtask event (e.g. `ObserverCallback`) is contained within a `EvaluatedScript`
+        event, move that microtask event to be a sibling of the `EvaluateScript`, subtracting the
+        microtask's time taken from the `EvaluateScript`'s time. If there are no other children
+        after this move, then remove the `EvaluateScript` altogether.
+
+        * UserInterface/Controllers/TimelineManager.js:
+        (WI.TimelineManager.prototype.eventRecorded.fixMicrotaskPlacement): Added.
+        (WI.TimelineManager.prototype.eventRecorded):
+        (WI.TimelineManager.prototype._mergeScriptProfileRecords):
+
 2019-01-23  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Network Waterfall column should redraw when adding/removing new columns
index df8d04f..61b745d 100644 (file)
@@ -356,6 +356,28 @@ WI.TimelineManager = class TimelineManager extends WI.Object
         if (!this._isCapturing)
             return;
 
+        function fixMicrotaskPlacement(children)
+        {
+            let newChildren = [];
+            for (let child of children) {
+                if (child.type === TimelineAgent.EventType.EvaluateScript) {
+                    let [microtasks, events] = child.children.partition((grandchild) => {
+                        return grandchild.type === TimelineAgent.EventType.ObserverCallback;
+                    });
+
+                    if (events.length) {
+                        child.children = events;
+                        child.endTime = events.lastValue.endTime;
+                        newChildren.push(child);
+                    }
+
+                    newChildren = newChildren.concat(microtasks);
+                } else
+                    newChildren.push(child);
+            }
+            return newChildren;
+        }
+
         var records = [];
 
         // Iterate over the records tree using a stack. Doing this recursively has
@@ -376,7 +398,7 @@ WI.TimelineManager = class TimelineManager extends WI.Object
                 }
 
                 if (recordPayload.children && recordPayload.children.length)
-                    stack.push({array: recordPayload.children, parent: recordPayload, parentRecord: record || entry.parentRecord, index: 0});
+                    stack.push({array: fixMicrotaskPlacement(recordPayload.children), parent: recordPayload, parentRecord: record || entry.parentRecord, index: 0});
                 ++entry.index;
             } else
                 stack.pop();
@@ -1055,15 +1077,23 @@ WI.TimelineManager = class TimelineManager extends WI.Object
                 webRecord.profilePayload = profilerRecord.profilePayload;
                 profilerRecord = nextScriptProfilerRecord();
 
+                let firstProfilerRecordForWebRecord = null;
+
                 // If there are more script profile records in the same time interval, add them
                 // as individual script evaluated records with profiles. This can happen with
                 // web microtask checkpoints that are technically inside of other web records.
                 // FIXME: <https://webkit.org/b/152903> Web Inspector: Timeline Cleanup: Better Timeline Record for Microtask Checkpoints
                 while (profilerRecord && recordEnclosesRecord(webRecord, profilerRecord)) {
+                    if (!firstProfilerRecordForWebRecord)
+                        firstProfilerRecordForWebRecord = profilerRecord;
+
                     this._addRecord(profilerRecord);
                     profilerRecord = nextScriptProfilerRecord();
                 }
 
+                if (firstProfilerRecordForWebRecord)
+                    webRecord.endTime = firstProfilerRecordForWebRecord.startTime;
+
                 webRecord = nextWebTimelineRecord();
                 continue;
             }