Web Inspector: discontinuous recordings should have discontinuities in the timeline...
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Views / MemoryTimelineView.js
index 549adc1..3c95739 100644 (file)
@@ -29,6 +29,8 @@ WebInspector.MemoryTimelineView = class MemoryTimelineView extends WebInspector.
     {
         super(timeline, extraArguments);
 
+        this._recording = extraArguments.recording;
+
         console.assert(timeline.type === WebInspector.TimelineRecord.Type.Memory, timeline);
 
         this.element.classList.add("memory");
@@ -175,7 +177,13 @@ WebInspector.MemoryTimelineView = class MemoryTimelineView extends WebInspector.
         let graphCurrentTime = this.currentTime;
         let visibleEndTime = Math.min(this.endTime, this.currentTime);
 
-        let visibleRecords = this._visibleRecords(graphStartTime, visibleEndTime);
+        let discontinuities = this._recording.discontinuitiesInTimeRange(graphStartTime, visibleEndTime);
+
+        // Don't include the record before the graph start if the graph start is within a gap.
+        let includeRecordBeforeStart = !discontinuities.length || discontinuities[0].startTime > graphStartTime;
+
+        // FIXME: <https://webkit.org/b/153759> Web Inspector: Memory Timelines should better extend to future data
+        let visibleRecords = this.representedObject.recordsInTimeRange(graphStartTime, visibleEndTime, includeRecordBeforeStart);
         if (!visibleRecords.length)
             return;
 
@@ -205,14 +213,35 @@ WebInspector.MemoryTimelineView = class MemoryTimelineView extends WebInspector.
 
         for (let record of visibleRecords) {
             let time = record.startTime;
+            let discontinuity = null;
+            if (discontinuities.length && discontinuities[0].endTime < time)
+                discontinuity = discontinuities.shift();
+
             for (let category of record.categories) {
                 let categoryData = categoryDataMap[category.type];
+
+                if (discontinuity) {
+                    if (categoryData.dataPoints.length) {
+                        let previousDataPoint = categoryData.dataPoints.lastValue;
+                        categoryData.dataPoints.push({time: discontinuity.startTime, size: previousDataPoint.size});
+                    }
+
+                    categoryData.dataPoints.push({time: discontinuity.startTime, size: 0});
+                    categoryData.dataPoints.push({time: discontinuity.endTime, size: 0});
+                    categoryData.dataPoints.push({time: discontinuity.endTime, size: category.size});
+                }
+
                 categoryData.dataPoints.push({time, size: category.size});
                 categoryData.max = Math.max(categoryData.max, category.size);
                 categoryData.min = Math.min(categoryData.min, category.size);
             }
         }
 
+        // If the graph end time is inside a gap, the last data point should
+        // only be extended to the start of the discontinuity.
+        if (discontinuities.length)
+            visibleEndTime = discontinuities[0].startTime;
+
         function layoutCategoryView(categoryView, categoryData) {
             let {dataPoints, min, max} = categoryData;
 
@@ -314,22 +343,6 @@ WebInspector.MemoryTimelineView = class MemoryTimelineView extends WebInspector.
         totalElement.textContent = (percent === 100 ? percent : (percent - 0.05).toFixed(1)) + "%";
     }
 
-    _visibleRecords(startTime, endTime)
-    {
-        let records = this.representedObject.records;
-        let lowerIndex = records.lowerBound(startTime, (time, record) => time - record.timestamp);
-        let upperIndex = records.upperBound(endTime, (time, record) => time - record.timestamp);
-
-        // Include the record right before the start time in case it extends into this range.
-        if (lowerIndex > 0)
-            lowerIndex--;
-        // FIXME: <https://webkit.org/b/153759> Web Inspector: Memory Timelines should better extend to future data
-        // if (upperIndex !== records.length)
-        //     upperIndex++;
-
-        return records.slice(lowerIndex, upperIndex);
-    }
-
     _initializeCategoryViews(record)
     {
         console.assert(!this._didInitializeCategories, "Should only initialize category views once");