Title: [248286] trunk
Revision
248286
Author
[email protected]
Date
2019-08-05 19:21:59 -0700 (Mon, 05 Aug 2019)

Log Message

Web Inspector: Timelines: disable related agents when the tab is closed
https://bugs.webkit.org/show_bug.cgi?id=200118

Reviewed by Joseph Pecoraro.

Source/_javascript_Core:

Rework how `enable`/`disable` is used for timeline-related agents so that events are not sent
and data isn't kept alive when the Timelines tab isn't enabled.

* inspector/protocol/Timeline.json:
Add `enable`/`disable` commands.

* inspector/agents/InspectorHeapAgent.cpp:
(Inspector::InspectorHeapAgent::willDestroyFrontendAndBackend):
(Inspector::InspectorHeapAgent::enable):
(Inspector::InspectorHeapAgent::disable):

Source/WebCore:

Rework how `enable`/`disable` is used for timeline-related agents so that events are not sent
and data isn't kept alive when the Timelines tab isn't enabled.

* inspector/agents/InspectorTimelineAgent.h:
* inspector/agents/InspectorTimelineAgent.cpp:
(WebCore::InspectorTimelineAgent::didCreateFrontendAndBackend):
(WebCore::InspectorTimelineAgent::willDestroyFrontendAndBackend):
(WebCore::InspectorTimelineAgent::enable):
(WebCore::InspectorTimelineAgent::disable):
(WebCore::InspectorTimelineAgent::start):
(WebCore::InspectorTimelineAgent::stop):
(WebCore::InspectorTimelineAgent::internalStart):
(WebCore::InspectorTimelineAgent::internalStop):
(WebCore::InspectorTimelineAgent::startFromConsole):
(WebCore::InspectorTimelineAgent::stopFromConsole):
(WebCore::InspectorTimelineAgent::mainFrameStartedLoading):
(WebCore::InspectorTimelineAgent::startProgrammaticCapture):
(WebCore::InspectorTimelineAgent::stopProgrammaticCapture):
Rename `m_enabled*` to `m_tracking*` to match other timeline-related agents.

* inspector/agents/InspectorMemoryAgent.h:
* inspector/agents/InspectorMemoryAgent.cpp:
(WebCore::InspectorMemoryAgent::didCreateFrontendAndBackend):
(WebCore::InspectorMemoryAgent::willDestroyFrontendAndBackend):
(WebCore::InspectorMemoryAgent::enable):
(WebCore::InspectorMemoryAgent::disable):
(WebCore::InspectorMemoryAgent::didHandleMemoryPressure):

* inspector/InstrumentingAgents.h:
(WebCore::InstrumentingAgents::trackingInspectorTimelineAgent): Added.
(WebCore::InstrumentingAgents::setTrackingInspectorTimelineAgent): Added.
(WebCore::InstrumentingAgents::persistentInspectorTimelineAgent): Added.
(WebCore::InstrumentingAgents::setPersistentInspectorTimelineAgent): Added.
* inspector/InstrumentingAgents.cpp:
(WebCore::InstrumentingAgents::reset):
* inspector/InspectorInstrumentation.h:
* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::didInstallTimerImpl):
(WebCore::InspectorInstrumentation::didRemoveTimerImpl):
(WebCore::InspectorInstrumentation::willCallFunctionImpl):
(WebCore::InspectorInstrumentation::willDispatchEventImpl):
(WebCore::InspectorInstrumentation::willDispatchEventOnWindowImpl):
(WebCore::InspectorInstrumentation::willEvaluateScriptImpl):
(WebCore::InspectorInstrumentation::willFireTimerImpl):
(WebCore::InspectorInstrumentation::didInvalidateLayoutImpl):
(WebCore::InspectorInstrumentation::willLayoutImpl):
(WebCore::InspectorInstrumentation::willCompositeImpl):
(WebCore::InspectorInstrumentation::didCompositeImpl):
(WebCore::InspectorInstrumentation::willPaintImpl):
(WebCore::InspectorInstrumentation::didPaintImpl):
(WebCore::InspectorInstrumentation::willRecalculateStyleImpl):
(WebCore::InspectorInstrumentation::didScheduleStyleRecalculationImpl):
(WebCore::InspectorInstrumentation::didCommitLoadImpl):
(WebCore::InspectorInstrumentation::frameStartedLoadingImpl):
(WebCore::InspectorInstrumentation::startConsoleTimingImpl):
(WebCore::InspectorInstrumentation::stopConsoleTimingImpl):
(WebCore::InspectorInstrumentation::consoleTimeStampImpl):
(WebCore::InspectorInstrumentation::startProfilingImpl):
(WebCore::InspectorInstrumentation::stopProfilingImpl):
(WebCore::InspectorInstrumentation::timelineAgentTracking): Added.
(WebCore::InspectorInstrumentation::didRequestAnimationFrameImpl):
(WebCore::InspectorInstrumentation::didCancelAnimationFrameImpl):
(WebCore::InspectorInstrumentation::willFireAnimationFrameImpl):
(WebCore::InspectorInstrumentation::willFireObserverCallbackImpl):
(WebCore::InspectorInstrumentation::retrieveTimelineAgent):
(WebCore::InspectorInstrumentation::timelineAgentEnabled): Deleted.
* bindings/js/JSExecStateInstrumentation.h:
(WebCore::JSExecState::instrumentFunctionInternal):
Rename for clarity/correctness:
 - `inspectorTimelineAgent` => `trackingInspectorTimelineAgent`
 - `persistentInspectorTimelineAgent` => `inspectorTimelineAgent`

Source/WebInspectorUI:

Rework how `enable`/`disable` is used for timeline-related agents so that events are not sent
and data isn't kept alive when the Timelines tab isn't enabled.

* UserInterface/Controllers/TimelineManager.js:
(WI.TimelineManager):
(WI.TimelineManager.prototype.get domains): Added.
(WI.TimelineManager.prototype.activateExtraDomain): Added.
(WI.TimelineManager.prototype.initializeTarget):
(WI.TimelineManager.prototype.reset):
(WI.TimelineManager.prototype.set autoCaptureOnPageLoad):
(WI.TimelineManager.prototype.enable): Added.
(WI.TimelineManager.prototype.disable): Added.
(WI.TimelineManager.prototype.startCapturing):
(WI.TimelineManager.prototype.stopCapturing):
(WI.TimelineManager.prototype.async processJSON):
(WI.TimelineManager.prototype.capturingStarted):
(WI.TimelineManager.prototype.capturingStopped):
(WI.TimelineManager.prototype.autoCaptureStarted):
(WI.TimelineManager.prototype.eventRecorded):
(WI.TimelineManager.prototype.pageDOMContentLoadedEventFired):
(WI.TimelineManager.prototype.pageLoadEventFired):
(WI.TimelineManager.prototype.cpuProfilerTrackingUpdated):
(WI.TimelineManager.prototype.memoryTrackingUpdated):
(WI.TimelineManager.prototype.heapTrackingStarted):
(WI.TimelineManager.prototype.heapTrackingCompleted):
(WI.TimelineManager.prototype.heapSnapshotAdded):
(WI.TimelineManager.prototype._loadNewRecording):
(WI.TimelineManager.prototype._legacyAttemptStartAutoCapturingForFrame):
(WI.TimelineManager.prototype._provisionalLoadStarted):
(WI.TimelineManager.prototype._mainResourceDidChange):
(WI.TimelineManager.prototype._resourceWasAdded):
(WI.TimelineManager.prototype._garbageCollected):
(WI.TimelineManager.prototype._memoryPressure):
(WI.TimelineManager.prototype.scriptProfilerTrackingUpdated):
(WI.TimelineManager.prototype.scriptProfilerTrackingCompleted):
(WI.TimelineManager.prototype._updateAutoCaptureInstruments):
(WI.TimelineManager.prototype._handleDOMNodeDidFireEvent):
(WI.TimelineManager.prototype._handleDOMNodePowerEfficientPlaybackStateChanged):
* UserInterface/Models/Instrument.js:
(WI.Instrument.startLegacyTimelineAgent):
(WI.Instrument.stopLegacyTimelineAgent):

* UserInterface/Controllers/HeapManager.js:
(WI.HeapManager): Added.
(WI.HeapManager.prototype.get domains): Added.
(WI.HeapManager.prototype.activateExtraDomain): Added.
(WI.HeapManager.prototype.initializeTarget):
(WI.HeapManager.prototype.enable): Added.
(WI.HeapManager.prototype.disable): Added.
(WI.HeapManager.prototype.snapshot): Added.
(WI.HeapManager.prototype.getPreview): Added.
(WI.HeapManager.prototype.getRemoteObject): Added.
(WI.HeapManager.prototype.garbageCollected):

* UserInterface/Controllers/MemoryManager.js:
(WI.MemoryManager): Added.
(WI.MemoryManager.prototype.get domains): Added.
(WI.MemoryManager.prototype.activateExtraDomain): Added.
(WI.MemoryManager.prototype.initializeTarget):
(WI.MemoryManager.prototype.enable): Added.
(WI.MemoryManager.prototype.disable): Added.
(WI.MemoryManager.prototype.memoryPressure):

* UserInterface/Views/TimelineTabContentView.js:
(WI.TimelineTabContentView):
(WI.TimelineTabContentView.prototype.closed):

* UserInterface/Models/HeapAllocationsInstrument.js:
(WI.HeapAllocationsInstrument):
(WI.HeapAllocationsInstrument.prototype._takeHeapSnapshot):
* UserInterface/Views/HeapAllocationsTimelineView.js:
(WI.HeapAllocationsTimelineView.prototype._takeHeapSnapshotClicked):
* UserInterface/Views/HeapSnapshotInstanceDataGridNode.js:
(WI.HeapSnapshotInstanceDataGridNode.logHeapSnapshotNode):
(WI.HeapSnapshotInstanceDataGridNode.prototype._populatePreview):
(WI.HeapSnapshotInstanceDataGridNode.prototype._mouseoverHandler.appendPathRow):
Go through the `HeapManager` for `HeapAgent` commands so it can better manage state.

* UserInterface/Test/Test.js:
(WI.contentLoaded):

LayoutTests:

* inspector/timeline/line-column.html:
* inspector/timeline/setInstruments-errors.html:
* inspector/timeline/setInstruments-programmatic-capture.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (248285 => 248286)


--- trunk/LayoutTests/ChangeLog	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/LayoutTests/ChangeLog	2019-08-06 02:21:59 UTC (rev 248286)
@@ -1,3 +1,14 @@
+2019-08-05  Devin Rousso  <[email protected]>
+
+        Web Inspector: Timelines: disable related agents when the tab is closed
+        https://bugs.webkit.org/show_bug.cgi?id=200118
+
+        Reviewed by Joseph Pecoraro.
+
+        * inspector/timeline/line-column.html:
+        * inspector/timeline/setInstruments-errors.html:
+        * inspector/timeline/setInstruments-programmatic-capture.html:
+
 2019-08-05  Fujii Hironori  <[email protected]>
 
         [Win] Specifying huge font-size causes crashing

Modified: trunk/LayoutTests/inspector/timeline/line-column.html (248285 => 248286)


--- trunk/LayoutTests/inspector/timeline/line-column.html	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/LayoutTests/inspector/timeline/line-column.html	2019-08-06 02:21:59 UTC (rev 248286)
@@ -33,13 +33,13 @@
     console.profileEnd();
 }
 
-function test() {
-    ProtocolTest.debug();
+function test()
+{
+    let suite = ProtocolTest.createAsyncSuite("Timeline.LineColumn");
 
     InspectorProtocol.sendCommand("Page.enable");
+    InspectorProtocol.sendCommand("Timeline.enable");
 
-    let suite = ProtocolTest.createAsyncSuite("Timeline.LineColumn");
-
     function replacer(key, value) {
         if (key === "startTime" || key === "endTime" || key === "scriptId" || key === "frameId")
             return "<filtered>";

Modified: trunk/LayoutTests/inspector/timeline/setInstruments-errors.html (248285 => 248286)


--- trunk/LayoutTests/inspector/timeline/setInstruments-errors.html	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/LayoutTests/inspector/timeline/setInstruments-errors.html	2019-08-06 02:21:59 UTC (rev 248286)
@@ -7,6 +7,10 @@
 {
     let suite = ProtocolTest.createAsyncSuite("Timeline.setInstruments.errors");
 
+    InspectorProtocol.sendCommand("Heap.enable");
+    InspectorProtocol.sendCommand("Memory.enable");
+    InspectorProtocol.sendCommand("Timeline.enable");
+
     suite.addTestCase({
         name: "MissingRequiredArgument",
         test(resolve, reject) {

Modified: trunk/LayoutTests/inspector/timeline/setInstruments-programmatic-capture.html (248285 => 248286)


--- trunk/LayoutTests/inspector/timeline/setInstruments-programmatic-capture.html	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/LayoutTests/inspector/timeline/setInstruments-programmatic-capture.html	2019-08-06 02:21:59 UTC (rev 248286)
@@ -17,6 +17,7 @@
     let captureStopped = null;
 
     InspectorProtocol.sendCommand("Heap.enable");
+    InspectorProtocol.sendCommand("Timeline.enable");
 
     InspectorProtocol.eventHandler["Timeline.recordingStarted"] = () => {
         ProtocolTest.pass("Timeline.recordingStarted");

Modified: trunk/Source/_javascript_Core/ChangeLog (248285 => 248286)


--- trunk/Source/_javascript_Core/ChangeLog	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-08-06 02:21:59 UTC (rev 248286)
@@ -1,5 +1,23 @@
 2019-08-05  Devin Rousso  <[email protected]>
 
+        Web Inspector: Timelines: disable related agents when the tab is closed
+        https://bugs.webkit.org/show_bug.cgi?id=200118
+
+        Reviewed by Joseph Pecoraro.
+
+        Rework how `enable`/`disable` is used for timeline-related agents so that events are not sent
+        and data isn't kept alive when the Timelines tab isn't enabled.
+
+        * inspector/protocol/Timeline.json:
+        Add `enable`/`disable` commands.
+
+        * inspector/agents/InspectorHeapAgent.cpp:
+        (Inspector::InspectorHeapAgent::willDestroyFrontendAndBackend):
+        (Inspector::InspectorHeapAgent::enable):
+        (Inspector::InspectorHeapAgent::disable):
+
+2019-08-05  Devin Rousso  <[email protected]>
+
         Web Inspector: rename "Stylesheet" to "Style Sheet" to match spec text
         https://bugs.webkit.org/show_bug.cgi?id=200422
 

Modified: trunk/Source/_javascript_Core/inspector/agents/InspectorHeapAgent.cpp (248285 => 248286)


--- trunk/Source/_javascript_Core/inspector/agents/InspectorHeapAgent.cpp	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/_javascript_Core/inspector/agents/InspectorHeapAgent.cpp	2019-08-06 02:21:59 UTC (rev 248286)
@@ -54,17 +54,16 @@
 
 void InspectorHeapAgent::willDestroyFrontendAndBackend(DisconnectReason)
 {
-    // Stop tracking without taking a snapshot.
-    m_tracking = false;
-
     ErrorString ignored;
     disable(ignored);
 }
 
-void InspectorHeapAgent::enable(ErrorString&)
+void InspectorHeapAgent::enable(ErrorString& errorString)
 {
-    if (m_enabled)
+    if (m_enabled) {
+        errorString = "HeapAgent already enabled"_s;
         return;
+    }
 
     m_enabled = true;
 
@@ -71,12 +70,15 @@
     m_environment.vm().heap.addObserver(this);
 }
 
-void InspectorHeapAgent::disable(ErrorString&)
+void InspectorHeapAgent::disable(ErrorString& errorString)
 {
-    if (!m_enabled)
+    if (!m_enabled) {
+        errorString = "HeapAgent already disabled"_s;
         return;
+    }
 
     m_enabled = false;
+    m_tracking = false;
 
     m_environment.vm().heap.removeObserver(this);
 

Modified: trunk/Source/_javascript_Core/inspector/protocol/Timeline.json (248285 => 248286)


--- trunk/Source/_javascript_Core/inspector/protocol/Timeline.json	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/_javascript_Core/inspector/protocol/Timeline.json	2019-08-06 02:21:59 UTC (rev 248286)
@@ -57,6 +57,14 @@
     ],
     "commands": [
         {
+            "name": "enable",
+            "description": "Enables Timeline domain events."
+        },
+        {
+            "name": "disable",
+            "description": "Disables Timeline domain events."
+        },
+        {
             "name": "start",
             "description": "Starts capturing instrumentation events.",
             "parameters": [

Modified: trunk/Source/WebCore/ChangeLog (248285 => 248286)


--- trunk/Source/WebCore/ChangeLog	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebCore/ChangeLog	2019-08-06 02:21:59 UTC (rev 248286)
@@ -1,3 +1,82 @@
+2019-08-05  Devin Rousso  <[email protected]>
+
+        Web Inspector: Timelines: disable related agents when the tab is closed
+        https://bugs.webkit.org/show_bug.cgi?id=200118
+
+        Reviewed by Joseph Pecoraro.
+
+        Rework how `enable`/`disable` is used for timeline-related agents so that events are not sent
+        and data isn't kept alive when the Timelines tab isn't enabled.
+
+        * inspector/agents/InspectorTimelineAgent.h:
+        * inspector/agents/InspectorTimelineAgent.cpp:
+        (WebCore::InspectorTimelineAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorTimelineAgent::willDestroyFrontendAndBackend):
+        (WebCore::InspectorTimelineAgent::enable):
+        (WebCore::InspectorTimelineAgent::disable):
+        (WebCore::InspectorTimelineAgent::start):
+        (WebCore::InspectorTimelineAgent::stop):
+        (WebCore::InspectorTimelineAgent::internalStart):
+        (WebCore::InspectorTimelineAgent::internalStop):
+        (WebCore::InspectorTimelineAgent::startFromConsole):
+        (WebCore::InspectorTimelineAgent::stopFromConsole):
+        (WebCore::InspectorTimelineAgent::mainFrameStartedLoading):
+        (WebCore::InspectorTimelineAgent::startProgrammaticCapture):
+        (WebCore::InspectorTimelineAgent::stopProgrammaticCapture):
+        Rename `m_enabled*` to `m_tracking*` to match other timeline-related agents.
+
+        * inspector/agents/InspectorMemoryAgent.h:
+        * inspector/agents/InspectorMemoryAgent.cpp:
+        (WebCore::InspectorMemoryAgent::didCreateFrontendAndBackend):
+        (WebCore::InspectorMemoryAgent::willDestroyFrontendAndBackend):
+        (WebCore::InspectorMemoryAgent::enable):
+        (WebCore::InspectorMemoryAgent::disable):
+        (WebCore::InspectorMemoryAgent::didHandleMemoryPressure):
+
+        * inspector/InstrumentingAgents.h:
+        (WebCore::InstrumentingAgents::trackingInspectorTimelineAgent): Added.
+        (WebCore::InstrumentingAgents::setTrackingInspectorTimelineAgent): Added.
+        (WebCore::InstrumentingAgents::persistentInspectorTimelineAgent): Added.
+        (WebCore::InstrumentingAgents::setPersistentInspectorTimelineAgent): Added.
+        * inspector/InstrumentingAgents.cpp:
+        (WebCore::InstrumentingAgents::reset):
+        * inspector/InspectorInstrumentation.h:
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::didInstallTimerImpl):
+        (WebCore::InspectorInstrumentation::didRemoveTimerImpl):
+        (WebCore::InspectorInstrumentation::willCallFunctionImpl):
+        (WebCore::InspectorInstrumentation::willDispatchEventImpl):
+        (WebCore::InspectorInstrumentation::willDispatchEventOnWindowImpl):
+        (WebCore::InspectorInstrumentation::willEvaluateScriptImpl):
+        (WebCore::InspectorInstrumentation::willFireTimerImpl):
+        (WebCore::InspectorInstrumentation::didInvalidateLayoutImpl):
+        (WebCore::InspectorInstrumentation::willLayoutImpl):
+        (WebCore::InspectorInstrumentation::willCompositeImpl):
+        (WebCore::InspectorInstrumentation::didCompositeImpl):
+        (WebCore::InspectorInstrumentation::willPaintImpl):
+        (WebCore::InspectorInstrumentation::didPaintImpl):
+        (WebCore::InspectorInstrumentation::willRecalculateStyleImpl):
+        (WebCore::InspectorInstrumentation::didScheduleStyleRecalculationImpl):
+        (WebCore::InspectorInstrumentation::didCommitLoadImpl):
+        (WebCore::InspectorInstrumentation::frameStartedLoadingImpl):
+        (WebCore::InspectorInstrumentation::startConsoleTimingImpl):
+        (WebCore::InspectorInstrumentation::stopConsoleTimingImpl):
+        (WebCore::InspectorInstrumentation::consoleTimeStampImpl):
+        (WebCore::InspectorInstrumentation::startProfilingImpl):
+        (WebCore::InspectorInstrumentation::stopProfilingImpl):
+        (WebCore::InspectorInstrumentation::timelineAgentTracking): Added.
+        (WebCore::InspectorInstrumentation::didRequestAnimationFrameImpl):
+        (WebCore::InspectorInstrumentation::didCancelAnimationFrameImpl):
+        (WebCore::InspectorInstrumentation::willFireAnimationFrameImpl):
+        (WebCore::InspectorInstrumentation::willFireObserverCallbackImpl):
+        (WebCore::InspectorInstrumentation::retrieveTimelineAgent):
+        (WebCore::InspectorInstrumentation::timelineAgentEnabled): Deleted.
+        * bindings/js/JSExecStateInstrumentation.h:
+        (WebCore::JSExecState::instrumentFunctionInternal):
+        Rename for clarity/correctness:
+         - `inspectorTimelineAgent` => `trackingInspectorTimelineAgent`
+         - `persistentInspectorTimelineAgent` => `inspectorTimelineAgent`
+
 2019-08-05  Fujii Hironori  <[email protected]>
 
         [Win] Specifying huge font-size causes crashing

Modified: trunk/Source/WebCore/bindings/js/JSExecStateInstrumentation.h (248285 => 248286)


--- trunk/Source/WebCore/bindings/js/JSExecStateInstrumentation.h	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebCore/bindings/js/JSExecStateInstrumentation.h	2019-08-06 02:21:59 UTC (rev 248286)
@@ -35,7 +35,7 @@
 template<typename Type, Type jsType, class DataType>
 inline InspectorInstrumentationCookie JSExecState::instrumentFunctionInternal(ScriptExecutionContext* context, Type callType, const DataType& callData)
 {
-    if (!InspectorInstrumentation::timelineAgentEnabled(context))
+    if (!InspectorInstrumentation::timelineAgentTracking(context))
         return InspectorInstrumentationCookie();
     String resourceName;
     int lineNumber = 1;

Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp (248285 => 248286)


--- trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp	2019-08-06 02:21:59 UTC (rev 248286)
@@ -316,7 +316,7 @@
     if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents.inspectorDebuggerAgent())
         debuggerAgent->didScheduleAsyncCall(context.execState(), InspectorDebuggerAgent::AsyncCallType::DOMTimer, timerId, singleShot);
 
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent())
         timelineAgent->didInstallTimer(timerId, timeout, singleShot, frameForScriptExecutionContext(context));
 }
 
@@ -324,7 +324,7 @@
 {
     if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents.inspectorDebuggerAgent())
         debuggerAgent->didCancelAsyncCall(InspectorDebuggerAgent::AsyncCallType::DOMTimer, timerId);
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent())
         timelineAgent->didRemoveTimer(timerId, frameForScriptExecutionContext(context));
 }
 
@@ -378,7 +378,7 @@
 InspectorInstrumentationCookie InspectorInstrumentation::willCallFunctionImpl(InstrumentingAgents& instrumentingAgents, const String& scriptName, int scriptLine, int scriptColumn, ScriptExecutionContext* context)
 {
     int timelineAgentId = 0;
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent()) {
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent()) {
         timelineAgent->willCallFunction(scriptName, scriptLine, scriptColumn, frameForScriptExecutionContext(context));
         timelineAgentId = timelineAgent->id();
     }
@@ -394,7 +394,7 @@
 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventImpl(InstrumentingAgents& instrumentingAgents, Document& document, const Event& event, bool hasEventListeners)
 {
     int timelineAgentId = 0;
-    InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent();
+    InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent();
     if (timelineAgent && hasEventListeners) {
         timelineAgent->willDispatchEvent(event, document.frame());
         timelineAgentId = timelineAgent->id();
@@ -430,7 +430,7 @@
 InspectorInstrumentationCookie InspectorInstrumentation::willDispatchEventOnWindowImpl(InstrumentingAgents& instrumentingAgents, const Event& event, DOMWindow& window)
 {
     int timelineAgentId = 0;
-    InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent();
+    InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent();
     if (timelineAgent && window.hasEventListeners(event.type())) {
         timelineAgent->willDispatchEvent(event, window.frame());
         timelineAgentId = timelineAgent->id();
@@ -454,7 +454,7 @@
 InspectorInstrumentationCookie InspectorInstrumentation::willEvaluateScriptImpl(InstrumentingAgents& instrumentingAgents, Frame& frame, const String& url, int lineNumber, int columnNumber)
 {
     int timelineAgentId = 0;
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent()) {
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent()) {
         timelineAgent->willEvaluateScript(url, lineNumber, columnNumber, frame);
         timelineAgentId = timelineAgent->id();
     }
@@ -476,7 +476,7 @@
         domDebuggerAgent->willFireTimer(oneShot);
 
     int timelineAgentId = 0;
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent()) {
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent()) {
         timelineAgent->willFireTimer(timerId, frameForScriptExecutionContext(context));
         timelineAgentId = timelineAgent->id();
     }
@@ -493,7 +493,7 @@
 
 void InspectorInstrumentation::didInvalidateLayoutImpl(InstrumentingAgents& instrumentingAgents, Frame& frame)
 {
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent())
         timelineAgent->didInvalidateLayout(frame);
 }
 
@@ -500,7 +500,7 @@
 InspectorInstrumentationCookie InspectorInstrumentation::willLayoutImpl(InstrumentingAgents& instrumentingAgents, Frame& frame)
 {
     int timelineAgentId = 0;
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent()) {
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent()) {
         timelineAgent->willLayout(frame);
         timelineAgentId = timelineAgent->id();
     }
@@ -518,25 +518,25 @@
 
 void InspectorInstrumentation::willCompositeImpl(InstrumentingAgents& instrumentingAgents, Frame& frame)
 {
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent())
         timelineAgent->willComposite(frame);
 }
 
 void InspectorInstrumentation::didCompositeImpl(InstrumentingAgents& instrumentingAgents)
 {
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent())
         timelineAgent->didComposite();
 }
 
 void InspectorInstrumentation::willPaintImpl(InstrumentingAgents& instrumentingAgents, RenderObject& renderer)
 {
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent())
         timelineAgent->willPaint(renderer.frame());
 }
 
 void InspectorInstrumentation::didPaintImpl(InstrumentingAgents& instrumentingAgents, RenderObject& renderer, const LayoutRect& rect)
 {
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent())
         timelineAgent->didPaint(renderer, rect);
 
     if (InspectorPageAgent* pageAgent = instrumentingAgents.inspectorPageAgent())
@@ -546,7 +546,7 @@
 InspectorInstrumentationCookie InspectorInstrumentation::willRecalculateStyleImpl(InstrumentingAgents& instrumentingAgents, Document& document)
 {
     int timelineAgentId = 0;
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent()) {
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent()) {
         timelineAgent->willRecalculateStyle(document.frame());
         timelineAgentId = timelineAgent->id();
     }
@@ -572,7 +572,7 @@
 
 void InspectorInstrumentation::didScheduleStyleRecalculationImpl(InstrumentingAgents& instrumentingAgents, Document& document)
 {
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent())
         timelineAgent->didScheduleStyleRecalculation(document.frame());
     if (InspectorNetworkAgent* networkAgent = instrumentingAgents.inspectorNetworkAgent())
         networkAgent->didScheduleStyleRecalculation(document);
@@ -754,7 +754,7 @@
         pageAgent->frameNavigated(frame);
 
     if (frame.isMainFrame()) {
-        if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
+        if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent())
             timelineAgent->mainFrameNavigated();
     }
 }
@@ -779,7 +779,7 @@
     if (frame.isMainFrame()) {
         if (PageDebuggerAgent* pageDebuggerAgent = instrumentingAgents.pageDebuggerAgent())
             pageDebuggerAgent->mainFrameStartedLoading();
-        if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.persistentInspectorTimelineAgent())
+        if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
             timelineAgent->mainFrameStartedLoading();
     }
 
@@ -874,7 +874,7 @@
     if (!instrumentingAgents.inspectorEnvironment().developerExtrasEnabled())
         return;
 
-    if (auto* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
+    if (auto* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent())
         timelineAgent->time(frame, label);
     if (auto* consoleAgent = instrumentingAgents.webConsoleAgent())
         consoleAgent->startTiming(exec, label);
@@ -905,7 +905,7 @@
 
     if (auto* consoleAgent = instrumentingAgents.webConsoleAgent())
         consoleAgent->stopTiming(exec, label);
-    if (auto* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
+    if (auto* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent())
         timelineAgent->timeEnd(frame, label);
 }
 
@@ -920,7 +920,7 @@
 
 void InspectorInstrumentation::consoleTimeStampImpl(InstrumentingAgents& instrumentingAgents, Frame& frame, Ref<ScriptArguments>&& arguments)
 {
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent()) {
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent()) {
         String message;
         arguments->getFirstArgumentAsString(message);
         timelineAgent->didTimeStamp(frame, message);
@@ -929,13 +929,13 @@
 
 void InspectorInstrumentation::startProfilingImpl(InstrumentingAgents& instrumentingAgents, JSC::ExecState* exec, const String& title)
 {
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.persistentInspectorTimelineAgent())
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
         timelineAgent->startFromConsole(exec, title);
 }
 
 void InspectorInstrumentation::stopProfilingImpl(InstrumentingAgents& instrumentingAgents, JSC::ExecState* exec, const String& title)
 {
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.persistentInspectorTimelineAgent())
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
         timelineAgent->stopFromConsole(exec, title);
 }
 
@@ -1112,11 +1112,11 @@
     return false;
 }
 
-bool InspectorInstrumentation::timelineAgentEnabled(ScriptExecutionContext* scriptExecutionContext)
+bool InspectorInstrumentation::timelineAgentTracking(ScriptExecutionContext* scriptExecutionContext)
 {
     FAST_RETURN_IF_NO_FRONTENDS(false);
     if (auto* instrumentingAgents = instrumentingAgentsForContext(scriptExecutionContext))
-        return instrumentingAgents->inspectorTimelineAgent();
+        return instrumentingAgents->trackingInspectorTimelineAgent();
     return false;
 }
 
@@ -1124,7 +1124,7 @@
 {
     if (PageDebuggerAgent* pageDebuggerAgent = instrumentingAgents.pageDebuggerAgent())
         pageDebuggerAgent->didRequestAnimationFrame(callbackId, document);
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent())
         timelineAgent->didRequestAnimationFrame(callbackId, document.frame());
 }
 
@@ -1132,7 +1132,7 @@
 {
     if (PageDebuggerAgent* pageDebuggerAgent = instrumentingAgents.pageDebuggerAgent())
         pageDebuggerAgent->didCancelAnimationFrame(callbackId);
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent())
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent())
         timelineAgent->didCancelAnimationFrame(callbackId, document.frame());
 }
 
@@ -1145,7 +1145,7 @@
         domDebuggerAgent->willFireAnimationFrame();
 
     int timelineAgentId = 0;
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent()) {
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent()) {
         timelineAgent->willFireAnimationFrame(callbackId, document.frame());
         timelineAgentId = timelineAgent->id();
     }
@@ -1163,7 +1163,7 @@
 InspectorInstrumentationCookie InspectorInstrumentation::willFireObserverCallbackImpl(InstrumentingAgents& instrumentingAgents, const String& callbackType, ScriptExecutionContext& context)
 {
     int timelineAgentId = 0;
-    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.inspectorTimelineAgent()) {
+    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents.trackingInspectorTimelineAgent()) {
         timelineAgent->willFireObserverCallback(callbackType, frameForScriptExecutionContext(&context));
         timelineAgentId = timelineAgent->id();
     }
@@ -1201,7 +1201,7 @@
     if (!cookie.isValid())
         return nullptr;
 
-    InspectorTimelineAgent* timelineAgent = cookie.instrumentingAgents()->inspectorTimelineAgent();
+    InspectorTimelineAgent* timelineAgent = cookie.instrumentingAgents()->trackingInspectorTimelineAgent();
     if (timelineAgent && cookie.hasMatchingTimelineAgentId(timelineAgent->id()))
         return timelineAgent;
     return nullptr;

Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.h (248285 => 248286)


--- trunk/Source/WebCore/inspector/InspectorInstrumentation.h	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.h	2019-08-06 02:21:59 UTC (rev 248286)
@@ -294,7 +294,7 @@
     static void lastFrontendDeleted();
 
     static bool consoleAgentEnabled(ScriptExecutionContext*);
-    static bool timelineAgentEnabled(ScriptExecutionContext*);
+    static bool timelineAgentTracking(ScriptExecutionContext*);
 
     static InstrumentingAgents* instrumentingAgentsForPage(Page*);
 

Modified: trunk/Source/WebCore/inspector/InstrumentingAgents.cpp (248285 => 248286)


--- trunk/Source/WebCore/inspector/InstrumentingAgents.cpp	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebCore/inspector/InstrumentingAgents.cpp	2019-08-06 02:21:59 UTC (rev 248286)
@@ -55,7 +55,7 @@
     m_pageRuntimeAgent = nullptr;
     m_inspectorScriptProfilerAgent = nullptr;
     m_inspectorTimelineAgent = nullptr;
-    m_persistentInspectorTimelineAgent = nullptr;
+    m_trackingInspectorTimelineAgent = nullptr;
     m_inspectorDOMStorageAgent = nullptr;
 #if ENABLE(RESOURCE_USAGE)
     m_inspectorCPUProfilerAgent = nullptr;

Modified: trunk/Source/WebCore/inspector/InstrumentingAgents.h (248285 => 248286)


--- trunk/Source/WebCore/inspector/InstrumentingAgents.h	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebCore/inspector/InstrumentingAgents.h	2019-08-06 02:21:59 UTC (rev 248286)
@@ -109,8 +109,8 @@
     InspectorTimelineAgent* inspectorTimelineAgent() const { return m_inspectorTimelineAgent; }
     void setInspectorTimelineAgent(InspectorTimelineAgent* agent) { m_inspectorTimelineAgent = agent; }
 
-    InspectorTimelineAgent* persistentInspectorTimelineAgent() const { return m_persistentInspectorTimelineAgent; }
-    void setPersistentInspectorTimelineAgent(InspectorTimelineAgent* agent) { m_persistentInspectorTimelineAgent = agent; }
+    InspectorTimelineAgent* trackingInspectorTimelineAgent() const { return m_trackingInspectorTimelineAgent; }
+    void setTrackingInspectorTimelineAgent(InspectorTimelineAgent* agent) { m_trackingInspectorTimelineAgent = agent; }
 
     InspectorDOMStorageAgent* inspectorDOMStorageAgent() const { return m_inspectorDOMStorageAgent; }
     void setInspectorDOMStorageAgent(InspectorDOMStorageAgent* agent) { m_inspectorDOMStorageAgent = agent; }
@@ -163,7 +163,7 @@
     PageRuntimeAgent* m_pageRuntimeAgent { nullptr };
     Inspector::InspectorScriptProfilerAgent* m_inspectorScriptProfilerAgent { nullptr };
     InspectorTimelineAgent* m_inspectorTimelineAgent { nullptr };
-    InspectorTimelineAgent* m_persistentInspectorTimelineAgent { nullptr };
+    InspectorTimelineAgent* m_trackingInspectorTimelineAgent { nullptr };
     InspectorDOMStorageAgent* m_inspectorDOMStorageAgent { nullptr };
 #if ENABLE(RESOURCE_USAGE)
     InspectorCPUProfilerAgent* m_inspectorCPUProfilerAgent { nullptr };

Modified: trunk/Source/WebCore/inspector/agents/InspectorMemoryAgent.cpp (248285 => 248286)


--- trunk/Source/WebCore/inspector/agents/InspectorMemoryAgent.cpp	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebCore/inspector/agents/InspectorMemoryAgent.cpp	2019-08-06 02:21:59 UTC (rev 248286)
@@ -47,26 +47,36 @@
 
 void InspectorMemoryAgent::didCreateFrontendAndBackend(FrontendRouter*, BackendDispatcher*)
 {
-    m_instrumentingAgents.setInspectorMemoryAgent(this);
 }
 
 void InspectorMemoryAgent::willDestroyFrontendAndBackend(DisconnectReason)
 {
-    m_instrumentingAgents.setInspectorMemoryAgent(nullptr);
-
     ErrorString ignored;
-    stopTracking(ignored);
     disable(ignored);
 }
 
-void InspectorMemoryAgent::enable(ErrorString&)
+void InspectorMemoryAgent::enable(ErrorString& errorString)
 {
-    m_enabled = true;
+    if (m_instrumentingAgents.inspectorMemoryAgent() == this) {
+        errorString = "MemoryAgent already enabled"_s;
+        return;
+    }
+
+    m_instrumentingAgents.setInspectorMemoryAgent(this);
 }
 
-void InspectorMemoryAgent::disable(ErrorString&)
+void InspectorMemoryAgent::disable(ErrorString& errorString)
 {
-    m_enabled = false;
+    if (m_instrumentingAgents.inspectorMemoryAgent() != this) {
+        errorString = "MemoryAgent already disabled"_s;
+        return;
+    }
+
+    m_instrumentingAgents.setInspectorMemoryAgent(nullptr);
+
+    m_tracking = false;
+
+    ResourceUsageThread::removeObserver(this);
 }
 
 void InspectorMemoryAgent::startTracking(ErrorString&)
@@ -97,9 +107,6 @@
 
 void InspectorMemoryAgent::didHandleMemoryPressure(Critical critical)
 {
-    if (!m_enabled)
-        return;
-
     MemoryFrontendDispatcher::Severity severity = critical == Critical::Yes ? MemoryFrontendDispatcher::Severity::Critical : MemoryFrontendDispatcher::Severity::NonCritical;
     m_frontendDispatcher->memoryPressure(m_environment.executionStopwatch()->elapsedTime().seconds(), severity);
 }

Modified: trunk/Source/WebCore/inspector/agents/InspectorMemoryAgent.h (248285 => 248286)


--- trunk/Source/WebCore/inspector/agents/InspectorMemoryAgent.h	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebCore/inspector/agents/InspectorMemoryAgent.h	2019-08-06 02:21:59 UTC (rev 248286)
@@ -61,7 +61,6 @@
 
     std::unique_ptr<Inspector::MemoryFrontendDispatcher> m_frontendDispatcher;
     RefPtr<Inspector::MemoryBackendDispatcher> m_backendDispatcher;
-    bool m_enabled { false };
     bool m_tracking { false };
 };
 

Modified: trunk/Source/WebCore/inspector/agents/InspectorTimelineAgent.cpp (248285 => 248286)


--- trunk/Source/WebCore/inspector/agents/InspectorTimelineAgent.cpp	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebCore/inspector/agents/InspectorTimelineAgent.cpp	2019-08-06 02:21:59 UTC (rev 248286)
@@ -96,13 +96,31 @@
 
 void InspectorTimelineAgent::didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*)
 {
-    m_instrumentingAgents.setPersistentInspectorTimelineAgent(this);
 }
 
 void InspectorTimelineAgent::willDestroyFrontendAndBackend(Inspector::DisconnectReason)
 {
-    m_instrumentingAgents.setPersistentInspectorTimelineAgent(nullptr);
+}
 
+void InspectorTimelineAgent::enable(ErrorString& errorString)
+{
+    if (m_instrumentingAgents.inspectorTimelineAgent() == this) {
+        errorString = "TimelineAgent already enabled"_s;
+        return;
+    }
+
+    m_instrumentingAgents.setInspectorTimelineAgent(this);
+}
+
+void InspectorTimelineAgent::disable(ErrorString& errorString)
+{
+    if (m_instrumentingAgents.inspectorTimelineAgent() != this) {
+        errorString = "TimelineAgent already disabled"_s;
+        return;
+    }
+
+    m_instrumentingAgents.setInspectorTimelineAgent(nullptr);
+
     ErrorString unused;
     stop(unused);
 
@@ -112,7 +130,7 @@
 
 void InspectorTimelineAgent::start(ErrorString&, const int* maxCallStackDepth)
 {
-    m_enabledFromFrontend = true;
+    m_trackingFromFrontend = true;
 
     internalStart(maxCallStackDepth);
 }
@@ -121,7 +139,7 @@
 {
     internalStop();
 
-    m_enabledFromFrontend = false;
+    m_trackingFromFrontend = false;
 }
 
 void InspectorTimelineAgent::setAutoCaptureEnabled(ErrorString&, bool enabled)
@@ -155,7 +173,7 @@
 
 void InspectorTimelineAgent::internalStart(const int* maxCallStackDepth)
 {
-    if (m_enabled)
+    if (m_tracking)
         return;
 
     if (maxCallStackDepth && *maxCallStackDepth > 0)
@@ -163,17 +181,17 @@
     else
         m_maxCallStackDepth = 5;
 
-    m_instrumentingAgents.setInspectorTimelineAgent(this);
+    m_instrumentingAgents.setTrackingInspectorTimelineAgent(this);
 
     m_environment.scriptDebugServer().addListener(this);
 
-    m_enabled = true;
+    m_tracking = true;
 
     // FIXME: Abstract away platform-specific code once https://bugs.webkit.org/show_bug.cgi?id=142748 is fixed.
 
 #if PLATFORM(COCOA)
     m_frameStartObserver = std::make_unique<RunLoopObserver>(static_cast<CFIndex>(RunLoopObserver::WellKnownRunLoopOrders::InspectorFrameBegin), [this]() {
-        if (!m_enabled || m_environment.scriptDebugServer().isPaused())
+        if (!m_tracking || m_environment.scriptDebugServer().isPaused())
             return;
 
         if (!m_runLoopNestingLevel)
@@ -182,7 +200,7 @@
     });
 
     m_frameStopObserver = std::make_unique<RunLoopObserver>(static_cast<CFIndex>(RunLoopObserver::WellKnownRunLoopOrders::InspectorFrameEnd), [this]() {
-        if (!m_enabled || m_environment.scriptDebugServer().isPaused())
+        if (!m_tracking || m_environment.scriptDebugServer().isPaused())
             return;
 
         ASSERT(m_runLoopNestingLevel > 0);
@@ -214,10 +232,10 @@
 
 void InspectorTimelineAgent::internalStop()
 {
-    if (!m_enabled)
+    if (!m_tracking)
         return;
 
-    m_instrumentingAgents.setInspectorTimelineAgent(nullptr);
+    m_instrumentingAgents.setTrackingInspectorTimelineAgent(nullptr);
 
     m_environment.scriptDebugServer().removeListener(this, true);
 
@@ -233,7 +251,7 @@
 
     clearRecordStack();
 
-    m_enabled = false;
+    m_tracking = false;
     m_startedComposite = false;
     m_autoCapturePhase = AutoCapturePhase::None;
 
@@ -266,7 +284,7 @@
         }
     }
 
-    if (!m_enabled && m_pendingConsoleProfileRecords.isEmpty())
+    if (!m_tracking && m_pendingConsoleProfileRecords.isEmpty())
         startProgrammaticCapture();
 
     m_pendingConsoleProfileRecords.append(createRecordEntry(TimelineRecordFactory::createConsoleProfileData(title), TimelineRecordType::ConsoleProfile, true, frameFromExecState(exec)));
@@ -285,7 +303,7 @@
             didCompleteRecordEntry(record);
             m_pendingConsoleProfileRecords.remove(i);
 
-            if (!m_enabledFromFrontend && m_pendingConsoleProfileRecords.isEmpty())
+            if (!m_trackingFromFrontend && m_pendingConsoleProfileRecords.isEmpty())
                 stopProgrammaticCapture();
 
             return;
@@ -439,7 +457,7 @@
 
 void InspectorTimelineAgent::mainFrameStartedLoading()
 {
-    if (m_enabled)
+    if (m_tracking)
         return;
 
     if (!m_autoCaptureEnabled)
@@ -473,7 +491,7 @@
 
 void InspectorTimelineAgent::startProgrammaticCapture()
 {
-    ASSERT(!m_enabled);
+    ASSERT(!m_tracking);
 
     // Disable breakpoints during programmatic capture.
     if (InspectorDebuggerAgent* debuggerAgent = m_instrumentingAgents.inspectorDebuggerAgent()) {
@@ -492,8 +510,8 @@
 
 void InspectorTimelineAgent::stopProgrammaticCapture()
 {
-    ASSERT(m_enabled);
-    ASSERT(!m_enabledFromFrontend);
+    ASSERT(m_tracking);
+    ASSERT(!m_trackingFromFrontend);
 
     toggleInstruments(InstrumentState::Stop);
     toggleTimelineInstrument(InstrumentState::Stop);

Modified: trunk/Source/WebCore/inspector/agents/InspectorTimelineAgent.h (248285 => 248286)


--- trunk/Source/WebCore/inspector/agents/InspectorTimelineAgent.h	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebCore/inspector/agents/InspectorTimelineAgent.h	2019-08-06 02:21:59 UTC (rev 248286)
@@ -94,6 +94,9 @@
     void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) final;
     void willDestroyFrontendAndBackend(Inspector::DisconnectReason) final;
 
+    // TimelineBackendDispatcherHandler
+    void enable(ErrorString&) final;
+    void disable(ErrorString&) final;
     void start(ErrorString&, const int* maxCallStackDepth = nullptr) final;
     void stop(ErrorString&) final;
     void setAutoCaptureEnabled(ErrorString&, bool) final;
@@ -214,8 +217,8 @@
     int m_id { 1 };
     int m_maxCallStackDepth { 5 };
 
-    bool m_enabled { false };
-    bool m_enabledFromFrontend { false };
+    bool m_tracking { false };
+    bool m_trackingFromFrontend { false };
     bool m_programmaticCaptureRestoreBreakpointActiveValue { false };
 
     bool m_autoCaptureEnabled { false };

Modified: trunk/Source/WebInspectorUI/ChangeLog (248285 => 248286)


--- trunk/Source/WebInspectorUI/ChangeLog	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebInspectorUI/ChangeLog	2019-08-06 02:21:59 UTC (rev 248286)
@@ -1,3 +1,91 @@
+2019-08-05  Devin Rousso  <[email protected]>
+
+        Web Inspector: Timelines: disable related agents when the tab is closed
+        https://bugs.webkit.org/show_bug.cgi?id=200118
+
+        Reviewed by Joseph Pecoraro.
+
+        Rework how `enable`/`disable` is used for timeline-related agents so that events are not sent
+        and data isn't kept alive when the Timelines tab isn't enabled.
+
+        * UserInterface/Controllers/TimelineManager.js:
+        (WI.TimelineManager):
+        (WI.TimelineManager.prototype.get domains): Added.
+        (WI.TimelineManager.prototype.activateExtraDomain): Added.
+        (WI.TimelineManager.prototype.initializeTarget):
+        (WI.TimelineManager.prototype.reset):
+        (WI.TimelineManager.prototype.set autoCaptureOnPageLoad):
+        (WI.TimelineManager.prototype.enable): Added.
+        (WI.TimelineManager.prototype.disable): Added.
+        (WI.TimelineManager.prototype.startCapturing):
+        (WI.TimelineManager.prototype.stopCapturing):
+        (WI.TimelineManager.prototype.async processJSON):
+        (WI.TimelineManager.prototype.capturingStarted):
+        (WI.TimelineManager.prototype.capturingStopped):
+        (WI.TimelineManager.prototype.autoCaptureStarted):
+        (WI.TimelineManager.prototype.eventRecorded):
+        (WI.TimelineManager.prototype.pageDOMContentLoadedEventFired):
+        (WI.TimelineManager.prototype.pageLoadEventFired):
+        (WI.TimelineManager.prototype.cpuProfilerTrackingUpdated):
+        (WI.TimelineManager.prototype.memoryTrackingUpdated):
+        (WI.TimelineManager.prototype.heapTrackingStarted):
+        (WI.TimelineManager.prototype.heapTrackingCompleted):
+        (WI.TimelineManager.prototype.heapSnapshotAdded):
+        (WI.TimelineManager.prototype._loadNewRecording):
+        (WI.TimelineManager.prototype._legacyAttemptStartAutoCapturingForFrame):
+        (WI.TimelineManager.prototype._provisionalLoadStarted):
+        (WI.TimelineManager.prototype._mainResourceDidChange):
+        (WI.TimelineManager.prototype._resourceWasAdded):
+        (WI.TimelineManager.prototype._garbageCollected):
+        (WI.TimelineManager.prototype._memoryPressure):
+        (WI.TimelineManager.prototype.scriptProfilerTrackingUpdated):
+        (WI.TimelineManager.prototype.scriptProfilerTrackingCompleted):
+        (WI.TimelineManager.prototype._updateAutoCaptureInstruments):
+        (WI.TimelineManager.prototype._handleDOMNodeDidFireEvent):
+        (WI.TimelineManager.prototype._handleDOMNodePowerEfficientPlaybackStateChanged):
+        * UserInterface/Models/Instrument.js:
+        (WI.Instrument.startLegacyTimelineAgent):
+        (WI.Instrument.stopLegacyTimelineAgent):
+
+        * UserInterface/Controllers/HeapManager.js:
+        (WI.HeapManager): Added.
+        (WI.HeapManager.prototype.get domains): Added.
+        (WI.HeapManager.prototype.activateExtraDomain): Added.
+        (WI.HeapManager.prototype.initializeTarget):
+        (WI.HeapManager.prototype.enable): Added.
+        (WI.HeapManager.prototype.disable): Added.
+        (WI.HeapManager.prototype.snapshot): Added.
+        (WI.HeapManager.prototype.getPreview): Added.
+        (WI.HeapManager.prototype.getRemoteObject): Added.
+        (WI.HeapManager.prototype.garbageCollected):
+
+        * UserInterface/Controllers/MemoryManager.js:
+        (WI.MemoryManager): Added.
+        (WI.MemoryManager.prototype.get domains): Added.
+        (WI.MemoryManager.prototype.activateExtraDomain): Added.
+        (WI.MemoryManager.prototype.initializeTarget):
+        (WI.MemoryManager.prototype.enable): Added.
+        (WI.MemoryManager.prototype.disable): Added.
+        (WI.MemoryManager.prototype.memoryPressure):
+
+        * UserInterface/Views/TimelineTabContentView.js:
+        (WI.TimelineTabContentView):
+        (WI.TimelineTabContentView.prototype.closed):
+
+        * UserInterface/Models/HeapAllocationsInstrument.js:
+        (WI.HeapAllocationsInstrument):
+        (WI.HeapAllocationsInstrument.prototype._takeHeapSnapshot):
+        * UserInterface/Views/HeapAllocationsTimelineView.js:
+        (WI.HeapAllocationsTimelineView.prototype._takeHeapSnapshotClicked):
+        * UserInterface/Views/HeapSnapshotInstanceDataGridNode.js:
+        (WI.HeapSnapshotInstanceDataGridNode.logHeapSnapshotNode):
+        (WI.HeapSnapshotInstanceDataGridNode.prototype._populatePreview):
+        (WI.HeapSnapshotInstanceDataGridNode.prototype._mouseoverHandler.appendPathRow):
+        Go through the `HeapManager` for `HeapAgent` commands so it can better manage state.
+
+        * UserInterface/Test/Test.js:
+        (WI.contentLoaded):
+
 2019-08-05  Nikita Vasilyev  <[email protected]>
 
         Web Inspector: brotli-compressed resources have "Compressed: No" in Resources details sidebar

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/HeapManager.js (248285 => 248286)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/HeapManager.js	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/HeapManager.js	2019-08-06 02:21:59 UTC (rev 248286)
@@ -23,12 +23,36 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+// FIXME: HeapManager lacks advanced multi-target support. (Instruments/Profilers per-target)
+
 WI.HeapManager = class HeapManager extends WI.Object
 {
+    constructor()
+    {
+        super();
+
+        this._enabled = false;
+    }
+
+    // Agent
+
+    get domains() { return ["Heap"]; }
+
+    activateExtraDomain(domain)
+    {
+        console.assert(domain === "Heap");
+
+        for (let target of WI.targets)
+            this.initializeTarget(target);
+    }
+
     // Target
 
     initializeTarget(target)
     {
+        if (!this._enabled)
+            return;
+
         if (target.HeapAgent)
             target.HeapAgent.enable();
     }
@@ -35,9 +59,71 @@
 
     // Public
 
+    enable()
+    {
+        if (this._enabled)
+            return;
+
+        this._enabled = true;
+
+        for (let target of WI.targets)
+            this.initializeTarget(target);
+    }
+
+    disable()
+    {
+        if (!this._enabled)
+            return;
+
+        for (let target of WI.targets) {
+            if (target.HeapAgent)
+                target.HeapAgent.disable();
+        }
+
+        this._enabled = false;
+    }
+
+    snapshot(callback)
+    {
+        console.assert(this._enabled);
+        console.assert(window.HeapAgent);
+        HeapAgent.snapshot((error, timestamp, snapshotStringData) => {
+            if (error)
+                WI.reportInternalError(error);
+            callback(error, timestamp, snapshotStringData);
+        });
+    }
+
+    getPreview(node, callback)
+    {
+        console.assert(this._enabled);
+        console.assert(window.HeapAgent);
+        console.assert(node instanceof WI.HeapSnapshotNodeProxy);
+        HeapAgent.getPreview(node.id, (error, string, functionDetails, preview) => {
+            if (error)
+                WI.reportInternalError(error);
+            callback(error, string, functionDetails, preview);
+        });
+    }
+
+    getRemoteObject(node, objectGroup, callback)
+    {
+        console.assert(this._enabled);
+        console.assert(window.HeapAgent);
+        console.assert(node instanceof WI.HeapSnapshotNodeProxy);
+        HeapAgent.getRemoteObject(node.id, objectGroup, (error, result) => {
+            if (error)
+                WI.reportInternalError(error);
+            callback(error, result);
+        });
+    }
+
+    // HeapObserver
+
     garbageCollected(target, payload)
     {
-        // Called from WI.HeapObserver.
+        if (!this._enabled)
+            return;
 
         // FIXME: <https://webkit.org/b/167323> Web Inspector: Enable Memory profiling in Workers
         if (target !== WI.mainTarget)

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/MemoryManager.js (248285 => 248286)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/MemoryManager.js	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/MemoryManager.js	2019-08-06 02:21:59 UTC (rev 248286)
@@ -25,10 +25,32 @@
 
 WI.MemoryManager = class MemoryManager extends WI.Object
 {
+    constructor()
+    {
+        super();
+
+        this._enabled = false;
+    }
+
+    // Agent
+
+    get domains() { return ["Memory"]; }
+
+    activateExtraDomain(domain)
+    {
+        console.assert(domain === "Memory");
+
+        for (let target of WI.targets)
+            this.initializeTarget(target);
+    }
+
     // Target
 
     initializeTarget(target)
     {
+        if (!this._enabled)
+            return;
+
         if (target.MemoryAgent)
             target.MemoryAgent.enable();
     }
@@ -35,9 +57,36 @@
 
     // Public
 
+    enable()
+    {
+        if (this._enabled)
+            return;
+
+        this._enabled = true;
+
+        for (let target of WI.targets)
+            this.initializeTarget(target);
+    }
+
+    disable()
+    {
+        if (!this._enabled)
+            return;
+
+        for (let target of WI.targets) {
+            if (target.MemoryAgent)
+                target.MemoryAgent.disable();
+        }
+
+        this._enabled = false;
+    }
+
+    // MemoryObserver
+
     memoryPressure(timestamp, protocolSeverity)
     {
-        // Called from WI.MemoryObserver.
+        if (!this._enabled)
+            return;
 
         let memoryPressureEvent = WI.MemoryPressureEvent.fromPayload(timestamp, protocolSeverity);
         this.dispatchEventToListeners(WI.MemoryManager.Event.MemoryPressure, {memoryPressureEvent});

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/TimelineManager.js (248285 => 248286)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/TimelineManager.js	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/TimelineManager.js	2019-08-06 02:21:59 UTC (rev 248286)
@@ -31,6 +31,8 @@
     {
         super();
 
+        this._enabled = false;
+
         WI.Frame.addEventListener(WI.Frame.Event.ProvisionalLoadStarted, this._provisionalLoadStarted, this);
         WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
 
@@ -61,11 +63,30 @@
         this.reset();
     }
 
+    // Agent
+
+    get domains() { return ["Timeline"]; }
+
+    activateExtraDomain(domain)
+    {
+        console.assert(domain === "Timeline");
+
+        for (let target of WI.targets)
+            this.initializeTarget(target);
+    }
+
     // Target
 
     initializeTarget(target)
     {
+        if (!this._enabled)
+            return;
+
         if (target.TimelineAgent) {
+            // COMPATIBILITY (iOS 13.1): Timeline.enable did not exist.
+            if (target.TimelineAgent.enable)
+                target.TimelineAgent.enable();
+
             this._updateAutoCaptureInstruments([target]);
 
             // COMPATIBILITY (iOS 9): Timeline.setAutoCaptureEnabled did not exist.
@@ -154,7 +175,7 @@
 
     reset()
     {
-        if (this.isCapturing())
+        if (this._capturingState === TimelineManager.CapturingState.Starting || this._capturingState === TimelineManager.CapturingState.Active)
             this.stopCapturing();
 
         this._recordings = [];
@@ -183,6 +204,8 @@
 
     set autoCaptureOnPageLoad(autoCapture)
     {
+        console.assert(this._enabled);
+
         autoCapture = !!autoCapture;
 
         if (this._autoCaptureOnPageLoad === autoCapture)
@@ -237,8 +260,39 @@
         }
     }
 
+    enable()
+    {
+        if (this._enabled)
+            return;
+
+        this._enabled = true;
+
+        this.reset();
+
+        for (let target of WI.targets)
+            this.initializeTarget(target);
+    }
+
+    disable()
+    {
+        if (!this._enabled)
+            return;
+
+        this.reset();
+
+        for (let target of WI.targets) {
+            // COMPATIBILITY (iOS 13.1): Timeline.disable did not exist.
+            if (target.TimelineAgent && target.TimelineAgent.disable)
+                target.TimelineAgent.disable();
+        }
+
+        this._enabled = false;
+    }
+
     startCapturing(shouldCreateRecording)
     {
+        console.assert(this._enabled);
+
         console.assert(this._capturingState === TimelineManager.CapturingState.Stopping || this._capturingState === TimelineManager.CapturingState.Inactive, "TimelineManager is already capturing.");
         if (this._capturingState !== TimelineManager.CapturingState.Stopping && this._capturingState !== TimelineManager.CapturingState.Inactive)
             return;
@@ -254,6 +308,8 @@
 
     stopCapturing()
     {
+        console.assert(this._enabled);
+
         console.assert(this._capturingState === TimelineManager.CapturingState.Starting || this._capturingState === TimelineManager.CapturingState.Active, "TimelineManager is not capturing.");
         if (this._capturingState !== TimelineManager.CapturingState.Starting && this._capturingState !== TimelineManager.CapturingState.Active)
             return;
@@ -295,7 +351,7 @@
 
         this.dispatchEventToListeners(WI.TimelineManager.Event.RecordingCreated, {recording: newRecording});
 
-        if (this.isCapturing())
+        if (this._capturingState === TimelineManager.CapturingState.Starting || this._capturingState === TimelineManager.CapturingState.Active)
             this.stopCapturing();
 
         let oldRecording = this._activeRecording;
@@ -323,12 +379,18 @@
         return this._scriptProfilerRecords !== null;
     }
 
-    // Protected
+    heapSnapshotAdded(timestamp, snapshot)
+    {
+        if (!this._enabled)
+            return;
 
+        this._addRecord(new WI.HeapAllocationsTimelineRecord(timestamp, snapshot));
+    }
+
+    // TimelineObserver
+
     capturingStarted(startTime)
     {
-        // Called from WI.TimelineObserver.
-
         // The frontend didn't start capturing, so this was a programmatic start.
         if (this._capturingState === TimelineManager.CapturingState.Inactive) {
             this._initiatedByBackendStart = true;
@@ -374,8 +436,6 @@
 
     capturingStopped(endTime)
     {
-        // Called from WI.TimelineObserver.
-
         // The frontend didn't stop capturing, so this was a programmatic stop.
         if (this._capturingState === TimelineManager.CapturingState.Active) {
             this._initiatedByBackendStop = true;
@@ -417,11 +477,11 @@
 
     autoCaptureStarted()
     {
-        // Called from WI.TimelineObserver.
+        console.assert(this._enabled);
 
         let waitingForCapturingStartedEvent = this._capturingState === TimelineManager.CapturingState.Starting;
 
-        if (this.isCapturing())
+        if (this._capturingState === TimelineManager.CapturingState.Starting || this._capturingState === TimelineManager.CapturingState.Active)
             this.stopCapturing();
 
         this._initiatedByBackendStart = true;
@@ -439,7 +499,8 @@
 
     eventRecorded(recordPayload)
     {
-        // Called from WI.TimelineObserver.
+        if (!this._enabled)
+            return;
 
         console.assert(this.isCapturing());
         if (!this.isCapturing())
@@ -482,9 +543,12 @@
         }
     }
 
+    // PageObserver
+
     pageDOMContentLoadedEventFired(timestamp)
     {
-        // Called from WI.PageObserver.
+        if (!this._enabled)
+            return;
 
         console.assert(this._activeRecording);
         console.assert(isNaN(WI.networkManager.mainFrame.domContentReadyEventTimestamp));
@@ -499,7 +563,8 @@
 
     pageLoadEventFired(timestamp)
     {
-        // Called from WI.PageObserver.
+        if (!this._enabled)
+            return;
 
         console.assert(this._activeRecording);
         console.assert(isNaN(WI.networkManager.mainFrame.loadEventTimestamp));
@@ -514,16 +579,17 @@
         this._stopAutoRecordingSoon();
     }
 
+    // CPUProfilerObserver
+
     cpuProfilerTrackingStarted(timestamp)
     {
-        // Called from WI.CPUProfilerObserver.
-
         this.capturingStarted(timestamp);
     }
 
     cpuProfilerTrackingUpdated(event)
     {
-        // Called from WI.CPUProfilerObserver.
+        if (!this._enabled)
+            return;
 
         console.assert(this.isCapturing());
         if (!this.isCapturing())
@@ -534,21 +600,20 @@
 
     cpuProfilerTrackingCompleted(timestamp)
     {
-        // Called from WI.CPUProfilerObserver.
-
         this.capturingStopped(timestamp);
     }
 
+    // MemoryObserver
+
     memoryTrackingStarted(timestamp)
     {
-        // Called from WI.MemoryObserver.
-
         this.capturingStarted(timestamp);
     }
 
     memoryTrackingUpdated(event)
     {
-        // Called from WI.MemoryObserver.
+        if (!this._enabled)
+            return;
 
         console.assert(this.isCapturing());
         if (!this.isCapturing())
@@ -559,36 +624,27 @@
 
     memoryTrackingCompleted(timestamp)
     {
-        // Called from WI.MemoryObserver.
-
         this.capturingStopped(timestamp);
     }
 
+    // HeapObserver
+
     heapTrackingStarted(timestamp, snapshot)
     {
-        // Called from WI.HeapObserver.
-
         this.capturingStarted(timestamp);
 
-        this._addRecord(new WI.HeapAllocationsTimelineRecord(timestamp, snapshot));
+        if (this._enabled)
+            this._addRecord(new WI.HeapAllocationsTimelineRecord(timestamp, snapshot));
     }
 
     heapTrackingCompleted(timestamp, snapshot)
     {
-        // Called from WI.HeapObserver.
+        if (this._enabled)
+            this._addRecord(new WI.HeapAllocationsTimelineRecord(timestamp, snapshot));
 
-        this._addRecord(new WI.HeapAllocationsTimelineRecord(timestamp, snapshot));
-
         this.capturingStopped();
     }
 
-    heapSnapshotAdded(timestamp, snapshot)
-    {
-        // Called from WI.HeapAllocationsInstrument.
-
-        this._addRecord(new WI.HeapAllocationsTimelineRecord(timestamp, snapshot));
-    }
-
     // Private
 
     _updateCapturingState(state, data = ""
@@ -827,7 +883,7 @@
         this._recordings.push(newRecording);
         this.dispatchEventToListeners(WI.TimelineManager.Event.RecordingCreated, {recording: newRecording});
 
-        if (this.isCapturing())
+        if (this._capturingState === TimelineManager.CapturingState.Starting || this._capturingState === TimelineManager.CapturingState.Active)
             this.stopCapturing();
 
         var oldRecording = this._activeRecording;
@@ -917,7 +973,7 @@
         let oldMainResource = frame.mainResource || null;
         this._isCapturingPageReload = oldMainResource !== null && oldMainResource.url ="" mainResource.url;
 
-        if (this.isCapturing())
+        if (this._capturingState === TimelineManager.CapturingState.Starting || this._capturingState === TimelineManager.CapturingState.Active)
             this.stopCapturing();
 
         this._mainResourceForAutoCapturing = mainResource;
@@ -979,11 +1035,17 @@
 
     _provisionalLoadStarted(event)
     {
+        if (!this._enabled)
+            return;
+
         this._attemptAutoCapturingForFrame(event.target);
     }
 
     _mainResourceDidChange(event)
     {
+        if (!this._enabled)
+            return;
+
         // Ignore resource events when there isn't a main frame yet. Those events are triggered by
         // loading the cached resources when the inspector opens, and they do not have timing information.
         if (!WI.networkManager.mainFrame)
@@ -1016,6 +1078,9 @@
 
     _resourceWasAdded(event)
     {
+        if (!this._enabled)
+            return;
+
         // Ignore resource events when there isn't a main frame yet. Those events are triggered by
         // loading the cached resources when the inspector opens, and they do not have timing information.
         if (!WI.networkManager.mainFrame)
@@ -1026,6 +1091,9 @@
 
     _garbageCollected(event)
     {
+        if (!this._enabled)
+            return;
+
         let {collection} = event.data;
         this._addRecord(new WI.ScriptTimelineRecord(WI.ScriptTimelineRecord.EventType.GarbageCollected, collection.startTime, collection.endTime, null, null, collection));
     }
@@ -1032,6 +1100,9 @@
 
     _memoryPressure(event)
     {
+        if (!this._enabled)
+            return;
+
         this._activeRecording.addMemoryPressureEvent(event.data.memoryPressureEvent);
     }
 
@@ -1068,6 +1139,9 @@
 
     scriptProfilerTrackingUpdated(event)
     {
+        if (!this._enabled)
+            return;
+
         let {startTime, endTime, type} = event;
         let scriptRecordType = this._scriptProfilerTypeToScriptTimelineRecordType(type);
         let record = new WI.ScriptTimelineRecord(scriptRecordType, startTime, endTime, null, null, null, null);
@@ -1084,66 +1158,68 @@
 
     scriptProfilerTrackingCompleted(timestamp, samples)
     {
-        console.assert(!this._webTimelineScriptRecordsExpectingScriptProfilerEvents || this._scriptProfilerRecords.length >= this._webTimelineScriptRecordsExpectingScriptProfilerEvents.length);
+        if (this._enabled) {
+            console.assert(!this._webTimelineScriptRecordsExpectingScriptProfilerEvents || this._scriptProfilerRecords.length >= this._webTimelineScriptRecordsExpectingScriptProfilerEvents.length);
 
-        if (samples) {
-            let {stackTraces} = samples;
-            let topDownCallingContextTree = this._activeRecording.topDownCallingContextTree;
+            if (samples) {
+                let {stackTraces} = samples;
+                let topDownCallingContextTree = this._activeRecording.topDownCallingContextTree;
 
-            // Calculate a per-sample duration.
-            let timestampIndex = 0;
-            let timestampCount = stackTraces.length;
-            let sampleDurations = new Array(timestampCount);
-            let sampleDurationIndex = 0;
-            const defaultDuration = 1 / 1000; // 1ms.
-            for (let i = 0; i < this._scriptProfilerRecords.length; ++i) {
-                let record = this._scriptProfilerRecords[i];
+                // Calculate a per-sample duration.
+                let timestampIndex = 0;
+                let timestampCount = stackTraces.length;
+                let sampleDurations = new Array(timestampCount);
+                let sampleDurationIndex = 0;
+                const defaultDuration = 1 / 1000; // 1ms.
+                for (let i = 0; i < this._scriptProfilerRecords.length; ++i) {
+                    let record = this._scriptProfilerRecords[i];
 
-                // Use a default duration for timestamps recorded outside of ScriptProfiler events.
-                while (timestampIndex < timestampCount && stackTraces[timestampIndex].timestamp < record.startTime) {
-                    sampleDurations[sampleDurationIndex++] = defaultDuration;
-                    timestampIndex++;
-                }
+                    // Use a default duration for timestamps recorded outside of ScriptProfiler events.
+                    while (timestampIndex < timestampCount && stackTraces[timestampIndex].timestamp < record.startTime) {
+                        sampleDurations[sampleDurationIndex++] = defaultDuration;
+                        timestampIndex++;
+                    }
 
-                // Average the duration per sample across all samples during the record.
-                let samplesInRecord = 0;
-                while (timestampIndex < timestampCount && stackTraces[timestampIndex].timestamp < record.endTime) {
-                    timestampIndex++;
-                    samplesInRecord++;
+                    // Average the duration per sample across all samples during the record.
+                    let samplesInRecord = 0;
+                    while (timestampIndex < timestampCount && stackTraces[timestampIndex].timestamp < record.endTime) {
+                        timestampIndex++;
+                        samplesInRecord++;
+                    }
+                    if (samplesInRecord) {
+                        let averageDuration = (record.endTime - record.startTime) / samplesInRecord;
+                        sampleDurations.fill(averageDuration, sampleDurationIndex, sampleDurationIndex + samplesInRecord);
+                        sampleDurationIndex += samplesInRecord;
+                    }
                 }
-                if (samplesInRecord) {
-                    let averageDuration = (record.endTime - record.startTime) / samplesInRecord;
-                    sampleDurations.fill(averageDuration, sampleDurationIndex, sampleDurationIndex + samplesInRecord);
-                    sampleDurationIndex += samplesInRecord;
-                }
-            }
 
-            // Use a default duration for timestamps recorded outside of ScriptProfiler events.
-            if (timestampIndex < timestampCount)
-                sampleDurations.fill(defaultDuration, sampleDurationIndex);
+                // Use a default duration for timestamps recorded outside of ScriptProfiler events.
+                if (timestampIndex < timestampCount)
+                    sampleDurations.fill(defaultDuration, sampleDurationIndex);
 
-            this._activeRecording.initializeCallingContextTrees(stackTraces, sampleDurations);
+                this._activeRecording.initializeCallingContextTrees(stackTraces, sampleDurations);
 
-            // FIXME: This transformation should not be needed after introducing ProfileView.
-            // Once we eliminate ProfileNodeTreeElements and ProfileNodeDataGridNodes.
-            // <https://webkit.org/b/154973> Web Inspector: Timelines UI redesign: Remove TimelineSidebarPanel
-            for (let i = 0; i < this._scriptProfilerRecords.length; ++i) {
-                let record = this._scriptProfilerRecords[i];
-                record.profilePayload = topDownCallingContextTree.toCPUProfilePayload(record.startTime, record.endTime);
+                // FIXME: This transformation should not be needed after introducing ProfileView.
+                // Once we eliminate ProfileNodeTreeElements and ProfileNodeDataGridNodes.
+                // <https://webkit.org/b/154973> Web Inspector: Timelines UI redesign: Remove TimelineSidebarPanel
+                for (let i = 0; i < this._scriptProfilerRecords.length; ++i) {
+                    let record = this._scriptProfilerRecords[i];
+                    record.profilePayload = topDownCallingContextTree.toCPUProfilePayload(record.startTime, record.endTime);
+                }
             }
-        }
 
-        // Associate the ScriptProfiler created records with Web Timeline records.
-        // Filter out the already added ScriptProfiler events which should not have been wrapped.
-        if (WI.sharedApp.debuggableType !== WI.DebuggableType._javascript_) {
-            this._scriptProfilerRecords = this._scriptProfilerRecords.filter((x) => x.__scriptProfilerType === ScriptProfilerAgent.EventType.Other);
-            this._mergeScriptProfileRecords();
-        }
+            // Associate the ScriptProfiler created records with Web Timeline records.
+            // Filter out the already added ScriptProfiler events which should not have been wrapped.
+            if (WI.sharedApp.debuggableType !== WI.DebuggableType._javascript_) {
+                this._scriptProfilerRecords = this._scriptProfilerRecords.filter((x) => x.__scriptProfilerType === ScriptProfilerAgent.EventType.Other);
+                this._mergeScriptProfileRecords();
+            }
 
-        this._scriptProfilerRecords = null;
+            this._scriptProfilerRecords = null;
 
-        let timeline = this._activeRecording.timelineForRecordType(WI.TimelineRecord.Type.Script);
-        timeline.refresh();
+            let timeline = this._activeRecording.timelineForRecordType(WI.TimelineRecord.Type.Script);
+            timeline.refresh();
+        }
 
         this.capturingStopped(timestamp);
     }
@@ -1206,6 +1282,8 @@
 
     _updateAutoCaptureInstruments(targets)
     {
+        console.assert(this._enabled);
+
         let enabledTimelineTypes = this.enabledTimelineTypes;
 
         for (let target of targets) {
@@ -1244,6 +1322,9 @@
 
     _handleDOMNodeDidFireEvent(event)
     {
+        if (!this._enabled)
+            return;
+
         let {domEvent} = event.data;
 
         this._addRecord(new WI.MediaTimelineRecord(WI.MediaTimelineRecord.EventType.DOMEvent, domEvent.timestamp, {
@@ -1254,6 +1335,9 @@
 
     _handleDOMNodePowerEfficientPlaybackStateChanged(event)
     {
+        if (!this._enabled)
+            return;
+
         let {timestamp, isPowerEfficient} = event.data;
 
         this._addRecord(new WI.MediaTimelineRecord(WI.MediaTimelineRecord.EventType.PowerEfficientPlaybackStateChanged, timestamp, {

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/HeapAllocationsInstrument.js (248285 => 248286)


--- trunk/Source/WebInspectorUI/UserInterface/Models/HeapAllocationsInstrument.js	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/HeapAllocationsInstrument.js	2019-08-06 02:21:59 UTC (rev 248286)
@@ -75,7 +75,7 @@
 
     _takeHeapSnapshot()
     {
-        HeapAgent.snapshot(function(error, timestamp, snapshotStringData) {
+        WI.heapManager.snapshot((error, timestamp, snapshotStringData) => {
             let workerProxy = WI.HeapSnapshotWorkerProxy.singleton();
             workerProxy.createSnapshot(snapshotStringData, ({objectId, snapshot: serializedSnapshot}) => {
                 let snapshot = WI.HeapSnapshotProxy.deserialize(objectId, serializedSnapshot);

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/Instrument.js (248285 => 248286)


--- trunk/Source/WebInspectorUI/UserInterface/Models/Instrument.js	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/Instrument.js	2019-08-06 02:21:59 UTC (rev 248286)
@@ -54,6 +54,7 @@
 
     static startLegacyTimelineAgent(initiatedByBackend)
     {
+        console.assert(WI.timelineManager._enabled);
         console.assert(window.TimelineAgent, "Attempted to start legacy timeline agent without TimelineAgent.");
 
         if (WI.Instrument._legacyTimelineAgentStarted)
@@ -69,6 +70,9 @@
 
     static stopLegacyTimelineAgent(initiatedByBackend)
     {
+        console.assert(WI.timelineManager._enabled);
+        console.assert(window.TimelineAgent, "Attempted to stop legacy timeline agent without TimelineAgent.");
+
         if (!WI.Instrument._legacyTimelineAgentStarted)
             return;
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Test/Test.js (248285 => 248286)


--- trunk/Source/WebInspectorUI/UserInterface/Test/Test.js	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebInspectorUI/UserInterface/Test/Test.js	2019-08-06 02:21:59 UTC (rev 248286)
@@ -134,9 +134,12 @@
     // Things that would normally get called by the UI, that we still want to do in tests.
     WI.applicationCacheManager.enable();
     WI.canvasManager.enable();
+    WI.databaseManager.enable();
     WI.domStorageManager.enable();
-    WI.databaseManager.enable();
+    WI.heapManager.enable();
     WI.indexedDBManager.enable();
+    WI.memoryManager.enable();
+    WI.timelineManager.enable();
 
     // Signal that the frontend is now ready to receive messages.
     InspectorFrontendAPI.loadCompleted();

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/HeapAllocationsTimelineView.js (248285 => 248286)


--- trunk/Source/WebInspectorUI/UserInterface/Views/HeapAllocationsTimelineView.js	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/HeapAllocationsTimelineView.js	2019-08-06 02:21:59 UTC (rev 248286)
@@ -408,7 +408,7 @@
 
     _takeHeapSnapshotClicked()
     {
-        HeapAgent.snapshot((error, timestamp, snapshotStringData) => {
+        WI.heapManager.snapshot((error, timestamp, snapshotStringData) => {
             let workerProxy = WI.HeapSnapshotWorkerProxy.singleton();
             workerProxy.createSnapshot(snapshotStringData, ({objectId, snapshot: serializedSnapshot}) => {
                 let snapshot = WI.HeapSnapshotProxy.deserialize(objectId, serializedSnapshot);

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/HeapSnapshotInstanceDataGridNode.js (248285 => 248286)


--- trunk/Source/WebInspectorUI/UserInterface/Views/HeapSnapshotInstanceDataGridNode.js	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/HeapSnapshotInstanceDataGridNode.js	2019-08-06 02:21:59 UTC (rev 248286)
@@ -81,12 +81,12 @@
             const shouldRevealConsole = true;
 
             if (node.className === "string") {
-                HeapAgent.getPreview(node.id, function(error, string, functionDetails, objectPreviewPayload) {
+                WI.heapManager.getPreview(node, function(error, string, functionDetails, objectPreviewPayload) {
                     let remoteObject = error ? WI.RemoteObject.fromPrimitiveValue(undefined) : WI.RemoteObject.fromPrimitiveValue(string);
                     WI.consoleLogViewController.appendImmediateExecutionWithResult(text, remoteObject, addSpecialUserLogClass, shouldRevealConsole);
                 });
             } else {
-                HeapAgent.getRemoteObject(node.id, WI.RuntimeManager.ConsoleObjectGroup, function(error, remoteObjectPayload) {
+                WI.heapManager.getRemoteObject(node, WI.RuntimeManager.ConsoleObjectGroup, function(error, remoteObjectPayload) {
                     let remoteObject = error ? WI.RemoteObject.fromPrimitiveValue(undefined) : WI.RemoteObject.fromPayload(remoteObjectPayload, WI.assumingMainTarget());
                     WI.consoleLogViewController.appendImmediateExecutionWithResult(text, remoteObject, addSpecialUserLogClass, shouldRevealConsole);
                 });
@@ -265,7 +265,8 @@
 
     _populateWindowPreview(containerElement)
     {
-        HeapAgent.getRemoteObject(this._node.id, (error, remoteObjectPayload) => {
+        const objectGroup = undefined;
+        WI.heapManager.getRemoteObject(this._node, objectGroup, (error, remoteObjectPayload) => {
             if (error) {
                 this._populateError(containerElement);
                 return;
@@ -291,7 +292,7 @@
 
     _populatePreview(containerElement)
     {
-        HeapAgent.getPreview(this._node.id, (error, string, functionDetails, objectPreviewPayload) => {
+        WI.heapManager.getPreview(this._node, (error, string, functionDetails, objectPreviewPayload) => {
             if (error) {
                 this._populateError(containerElement);
                 return;
@@ -428,7 +429,7 @@
                 let goToArrowPlaceHolderElement = containerElement.appendChild(document.createElement("span"));
                 goToArrowPlaceHolderElement.style.display = "inline-block";
                 goToArrowPlaceHolderElement.style.width = "10px";
-                HeapAgent.getPreview(node.id, function(error, string, functionDetails, objectPreviewPayload) {
+                WI.heapManager.getPreview(node, function(error, string, functionDetails, objectPreviewPayload) {
                     if (functionDetails) {
                         let location = functionDetails.location;
                         let sourceCode = WI.debuggerManager.scriptForIdentifier(location.scriptId, WI.assumingMainTarget());

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/TimelineTabContentView.js (248285 => 248286)


--- trunk/Source/WebInspectorUI/UserInterface/Views/TimelineTabContentView.js	2019-08-06 02:07:06 UTC (rev 248285)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/TimelineTabContentView.js	2019-08-06 02:21:59 UTC (rev 248286)
@@ -91,6 +91,10 @@
 
         // Explicitly update the path for the navigation bar to prevent it from showing up as blank.
         this.contentBrowser.updateHierarchicalPathForCurrentContentView();
+
+        WI.heapManager.enable();
+        WI.memoryManager.enable();
+        WI.timelineManager.enable();
     }
 
     // Static
@@ -327,7 +331,9 @@
 
     closed()
     {
-        super.closed();
+        WI.timelineManager.disable();
+        WI.memoryManager.disable();
+        WI.heapManager.disable();
 
         if (WI.FPSInstrument.supported())
             this.contentBrowser.navigationBar.removeEventListener(null, null, this);
@@ -334,6 +340,8 @@
 
         WI.timelineManager.removeEventListener(null, null, this);
         WI.notifications.removeEventListener(null, null, this);
+
+        super.closed();
     }
 
     canShowRepresentedObject(representedObject)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to