Web Inspector: CPU Usage: Worker thread that dies might stay at a high value forever
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Mar 2019 00:48:07 +0000 (00:48 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Mar 2019 00:48:07 +0000 (00:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195148

Reviewed by Matt Baker.

* UserInterface/Views/CPUTimelineView.js:
(CPUTimelineView.prototype.layout):
Handle workers dieing or at least zeroing out between records.

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Views/CPUTimelineView.js

index 429194e..8be99a6 100644 (file)
@@ -1,5 +1,16 @@
 2019-02-28  Joseph Pecoraro  <pecoraro@apple.com>
 
+        Web Inspector: CPU Usage: Worker thread that dies might stay at a high value forever
+        https://bugs.webkit.org/show_bug.cgi?id=195148
+
+        Reviewed by Matt Baker.
+
+        * UserInterface/Views/CPUTimelineView.js:
+        (CPUTimelineView.prototype.layout):
+        Handle workers dieing or at least zeroing out between records.
+
+2019-02-28  Joseph Pecoraro  <pecoraro@apple.com>
+
         Web Inspector: CPU Usage Timeline - Make Threads section expandable / collapsable
         https://bugs.webkit.org/show_bug.cgi?id=195085
 
index 60a1693..1a1c4ee 100644 (file)
@@ -301,6 +301,7 @@ WI.CPUTimelineView = class CPUTimelineView extends WI.TimelineView
 
         let dataPoints = [];
         let workersDataMap = new Map;
+        let workersSeenInCurrentRecord = new Set;
 
         let max = -Infinity;
         let mainThreadMax = -Infinity;
@@ -361,8 +362,12 @@ WI.CPUTimelineView = class CPUTimelineView extends WI.TimelineView
             webkitThreadAverage += webkitThreadUsage;
             unknownThreadAverage += unknownThreadUsage;
 
+            let workersSeenInLastRecord = workersSeenInCurrentRecord;
+            workersSeenInCurrentRecord = new Set;
+
             if (record.workersData && record.workersData.length) {
                 for (let {targetId, usage} of record.workersData) {
+                    workersSeenInCurrentRecord.add(targetId);
                     let workerData = workersDataMap.get(targetId);
                     if (!workerData) {
                         workerData = {
@@ -402,6 +407,16 @@ WI.CPUTimelineView = class CPUTimelineView extends WI.TimelineView
                     workerData.average += usage;
                 }
             }
+
+            // Close any worker that died by dropping to zero.
+            if (workersSeenInLastRecord.size) {
+                let deadWorkers = workersSeenInLastRecord.difference(workersSeenInCurrentRecord);
+                for (let workerId of deadWorkers) {
+                    let workerData = workersDataMap.get(workerId);
+                    if (workerData.dataPoints.lastValue.usage !== 0)
+                        workerData.dataPoints.push({time, usage: 0});
+                }
+            }
         }
 
         average /= visibleRecords.length;