Web Inspector: Timeline: lazily create the agent
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Mar 2019 00:31:24 +0000 (00:31 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Mar 2019 00:31:24 +0000 (00:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195865
<rdar://problem/48965403>

Reviewed by Joseph Pecoraro.

No change in functionality.

* inspector/agents/InspectorTimelineAgent.h:
* inspector/agents/InspectorTimelineAgent.cpp:
(WebCore::InspectorTimelineAgent::InspectorTimelineAgent):
(WebCore::InspectorTimelineAgent::toggleScriptProfilerInstrument):
(WebCore::InspectorTimelineAgent::toggleHeapInstrument):
(WebCore::InspectorTimelineAgent::setFrameIdentifier):

* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::startProfiling):
(WebCore::InspectorInstrumentation::stopProfiling):
(WebCore::InspectorInstrumentation::didRequestAnimationFrame):
(WebCore::InspectorInstrumentation::didCancelAnimationFrame):

* inspector/InstrumentingAgents.h:
(WebCore::InstrumentingAgents::inspectorScriptProfilerAgent const): Added.
(WebCore::InstrumentingAgents::setInspectorScriptProfilerAgent): Added.
* inspector/InstrumentingAgents.cpp:
(WebCore::InstrumentingAgents::reset):

* inspector/InspectorController.cpp:
(WebCore::InspectorController::InspectorController):
(WebCore::InspectorController::createLazyAgents):

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

Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorController.cpp
Source/WebCore/inspector/InspectorInstrumentation.h
Source/WebCore/inspector/InstrumentingAgents.cpp
Source/WebCore/inspector/InstrumentingAgents.h
Source/WebCore/inspector/agents/InspectorTimelineAgent.cpp
Source/WebCore/inspector/agents/InspectorTimelineAgent.h

index 79f6b46..9ebf4ff 100644 (file)
@@ -1,3 +1,36 @@
+2019-03-18  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Timeline: lazily create the agent
+        https://bugs.webkit.org/show_bug.cgi?id=195865
+        <rdar://problem/48965403>
+
+        Reviewed by Joseph Pecoraro.
+
+        No change in functionality.
+
+        * inspector/agents/InspectorTimelineAgent.h:
+        * inspector/agents/InspectorTimelineAgent.cpp:
+        (WebCore::InspectorTimelineAgent::InspectorTimelineAgent):
+        (WebCore::InspectorTimelineAgent::toggleScriptProfilerInstrument):
+        (WebCore::InspectorTimelineAgent::toggleHeapInstrument):
+        (WebCore::InspectorTimelineAgent::setFrameIdentifier):
+
+        * inspector/InspectorInstrumentation.h:
+        (WebCore::InspectorInstrumentation::startProfiling):
+        (WebCore::InspectorInstrumentation::stopProfiling):
+        (WebCore::InspectorInstrumentation::didRequestAnimationFrame):
+        (WebCore::InspectorInstrumentation::didCancelAnimationFrame):
+
+        * inspector/InstrumentingAgents.h:
+        (WebCore::InstrumentingAgents::inspectorScriptProfilerAgent const): Added.
+        (WebCore::InstrumentingAgents::setInspectorScriptProfilerAgent): Added.
+        * inspector/InstrumentingAgents.cpp:
+        (WebCore::InstrumentingAgents::reset):
+
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::InspectorController):
+        (WebCore::InspectorController::createLazyAgents):
+
 2019-03-18  Darin Adler  <darin@apple.com>
 
         Cut down on use of StringBuffer, possibly leading toward removing it entirely
index 97f9480..498a3d7 100644 (file)
@@ -136,7 +136,7 @@ InspectorController::InspectorController(Page& page, InspectorClient* inspectorC
     m_agents.append(WTFMove(heapAgentPtr));
 
     auto scriptProfilerAgentPtr = std::make_unique<InspectorScriptProfilerAgent>(pageContext);
-    InspectorScriptProfilerAgent* scriptProfilerAgent = scriptProfilerAgentPtr.get();
+    m_instrumentingAgents->setInspectorScriptProfilerAgent(scriptProfilerAgentPtr.get());
     m_agents.append(WTFMove(scriptProfilerAgentPtr));
 
     auto consoleAgentPtr = std::make_unique<PageConsoleAgent>(pageContext, heapAgent, m_domAgent);
@@ -144,8 +144,6 @@ InspectorController::InspectorController(Page& page, InspectorClient* inspectorC
     m_instrumentingAgents->setWebConsoleAgent(consoleAgentPtr.get());
     m_agents.append(WTFMove(consoleAgentPtr));
 
-    m_agents.append(std::make_unique<InspectorTimelineAgent>(pageContext, scriptProfilerAgent, heapAgent, pageAgent));
-
     ASSERT(m_injectedScriptManager->commandLineAPIHost());
     if (CommandLineAPIHost* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost())
         commandLineAPIHost->init(m_inspectorAgent, consoleAgent, domStorageAgent, databaseAgent);
@@ -207,6 +205,7 @@ void InspectorController::createLazyAgents()
 #endif
     m_agents.append(std::make_unique<PageAuditAgent>(pageContext));
     m_agents.append(std::make_unique<InspectorCanvasAgent>(pageContext));
+    m_agents.append(std::make_unique<InspectorTimelineAgent>(pageContext));
 }
 
 void InspectorController::inspectedPageDestroyed()
index 885f3d0..e10285d 100644 (file)
@@ -1408,11 +1408,13 @@ inline void InspectorInstrumentation::consoleTimeStamp(Frame& frame, Ref<Inspect
 
 inline void InspectorInstrumentation::startProfiling(Page& page, JSC::ExecState* exec, const String &title)
 {
+    FAST_RETURN_IF_NO_FRONTENDS(void());
     startProfilingImpl(instrumentingAgentsForPage(page), exec, title);
 }
 
 inline void InspectorInstrumentation::stopProfiling(Page& page, JSC::ExecState* exec, const String &title)
 {
+    FAST_RETURN_IF_NO_FRONTENDS(void());
     stopProfilingImpl(instrumentingAgentsForPage(page), exec, title);
 }
 
@@ -1425,12 +1427,14 @@ inline void InspectorInstrumentation::consoleStartRecordingCanvas(CanvasRenderin
 
 inline void InspectorInstrumentation::didRequestAnimationFrame(Document& document, int callbackId)
 {
+    FAST_RETURN_IF_NO_FRONTENDS(void());
     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
         didRequestAnimationFrameImpl(*instrumentingAgents, callbackId, document);
 }
 
 inline void InspectorInstrumentation::didCancelAnimationFrame(Document& document, int callbackId)
 {
+    FAST_RETURN_IF_NO_FRONTENDS(void());
     if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
         didCancelAnimationFrameImpl(*instrumentingAgents, callbackId, document);
 }
index b5886c4..a0eae4b 100644 (file)
@@ -53,6 +53,7 @@ void InstrumentingAgents::reset()
     m_inspectorDOMAgent = nullptr;
     m_inspectorNetworkAgent = nullptr;
     m_pageRuntimeAgent = nullptr;
+    m_inspectorScriptProfilerAgent = nullptr;
     m_inspectorTimelineAgent = nullptr;
     m_persistentInspectorTimelineAgent = nullptr;
     m_inspectorDOMStorageAgent = nullptr;
index 5477732..9a9ce6c 100644 (file)
@@ -39,6 +39,7 @@
 namespace Inspector {
 class InspectorAgent;
 class InspectorDebuggerAgent;
+class InspectorScriptProfilerAgent;
 }
 
 namespace WebCore {
@@ -102,6 +103,9 @@ public:
     PageRuntimeAgent* pageRuntimeAgent() const { return m_pageRuntimeAgent; }
     void setPageRuntimeAgent(PageRuntimeAgent* agent) { m_pageRuntimeAgent = agent; }
 
+    Inspector::InspectorScriptProfilerAgent* inspectorScriptProfilerAgent() const { return m_inspectorScriptProfilerAgent; }
+    void setInspectorScriptProfilerAgent(Inspector::InspectorScriptProfilerAgent* agent) { m_inspectorScriptProfilerAgent = agent; }
+
     InspectorTimelineAgent* inspectorTimelineAgent() const { return m_inspectorTimelineAgent; }
     void setInspectorTimelineAgent(InspectorTimelineAgent* agent) { m_inspectorTimelineAgent = agent; }
 
@@ -157,6 +161,7 @@ private:
     InspectorDOMAgent* m_inspectorDOMAgent { nullptr };
     InspectorNetworkAgent* m_inspectorNetworkAgent { nullptr };
     PageRuntimeAgent* m_pageRuntimeAgent { nullptr };
+    Inspector::InspectorScriptProfilerAgent* m_inspectorScriptProfilerAgent { nullptr };
     InspectorTimelineAgent* m_inspectorTimelineAgent { nullptr };
     InspectorTimelineAgent* m_persistentInspectorTimelineAgent { nullptr };
     InspectorDOMStorageAgent* m_inspectorDOMStorageAgent { nullptr };
index 0505bd3..6b2b56a 100644 (file)
@@ -41,6 +41,7 @@
 #include "InspectorPageAgent.h"
 #include "InstrumentingAgents.h"
 #include "JSDOMWindow.h"
+#include "PageHeapAgent.h"
 #include "PageScriptDebugServer.h"
 #include "RenderView.h"
 #include "ScriptState.h"
@@ -48,7 +49,6 @@
 #include "WebConsoleAgent.h"
 #include <JavaScriptCore/ConsoleMessage.h>
 #include <JavaScriptCore/InspectorDebuggerAgent.h>
-#include <JavaScriptCore/InspectorHeapAgent.h>
 #include <JavaScriptCore/InspectorScriptProfilerAgent.h>
 #include <JavaScriptCore/ScriptBreakpoint.h>
 #include <wtf/Stopwatch.h>
@@ -83,13 +83,10 @@ static CFRunLoopRef currentRunLoop()
 }
 #endif
 
-InspectorTimelineAgent::InspectorTimelineAgent(WebAgentContext& context, InspectorScriptProfilerAgent* scriptProfileAgent, InspectorHeapAgent* heapAgent, InspectorPageAgent* pageAgent)
+InspectorTimelineAgent::InspectorTimelineAgent(WebAgentContext& context)
     : InspectorAgentBase("Timeline"_s, context)
     , m_frontendDispatcher(std::make_unique<Inspector::TimelineFrontendDispatcher>(context.frontendRouter))
     , m_backendDispatcher(Inspector::TimelineBackendDispatcher::create(context.backendDispatcher, this))
-    , m_scriptProfilerAgent(scriptProfileAgent)
-    , m_heapAgent(heapAgent)
-    , m_pageAgent(pageAgent)
 {
 }
 
@@ -532,25 +529,25 @@ void InspectorTimelineAgent::toggleInstruments(InstrumentState state)
 
 void InspectorTimelineAgent::toggleScriptProfilerInstrument(InstrumentState state)
 {
-    if (m_scriptProfilerAgent) {
+    if (auto* scriptProfilerAgent = m_instrumentingAgents.inspectorScriptProfilerAgent()) {
         ErrorString unused;
         if (state == InstrumentState::Start) {
             const bool includeSamples = true;
-            m_scriptProfilerAgent->startTracking(unused, &includeSamples);
+            scriptProfilerAgent->startTracking(unused, &includeSamples);
         } else
-            m_scriptProfilerAgent->stopTracking(unused);
+            scriptProfilerAgent->stopTracking(unused);
     }
 }
 
 void InspectorTimelineAgent::toggleHeapInstrument(InstrumentState state)
 {
-    if (m_heapAgent) {
+    if (auto* heapAgent = m_instrumentingAgents.pageHeapAgent()) {
         ErrorString unused;
         if (state == InstrumentState::Start) {
             if (m_autoCapturePhase == AutoCapturePhase::None || m_autoCapturePhase == AutoCapturePhase::FirstNavigation)
-                m_heapAgent->startTracking(unused);
+                heapAgent->startTracking(unused);
         } else
-            m_heapAgent->stopTracking(unused);
+            heapAgent->stopTracking(unused);
     }
 }
 
@@ -712,12 +709,14 @@ void InspectorTimelineAgent::addRecordToTimeline(RefPtr<JSON::Object>&& record,
 
 void InspectorTimelineAgent::setFrameIdentifier(JSON::Object* record, Frame* frame)
 {
-    if (!frame || !m_pageAgent)
+    if (!frame)
         return;
-    String frameId;
-    if (frame && m_pageAgent)
-        frameId = m_pageAgent->frameId(frame);
-    record->setString("frameId", frameId);
+
+    auto* pageAgent = m_instrumentingAgents.inspectorPageAgent();
+    if (!pageAgent)
+        return;
+
+    record->setString("frameId"_s, pageAgent->frameId(frame));
 }
 
 void InspectorTimelineAgent::didCompleteRecordEntry(const TimelineRecordEntry& entry)
index 82847c6..90a396f 100644 (file)
 #include <wtf/JSONValues.h>
 #include <wtf/Vector.h>
 
-namespace Inspector {
-class InspectorHeapAgent;
-class InspectorScriptProfilerAgent;
-}
-
 namespace WebCore {
 
 class Event;
 class FloatQuad;
 class Frame;
-class InspectorPageAgent;
 class RenderObject;
 class RunLoopObserver;
 
@@ -94,7 +88,7 @@ class InspectorTimelineAgent final
     WTF_MAKE_NONCOPYABLE(InspectorTimelineAgent);
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    InspectorTimelineAgent(WebAgentContext&, Inspector::InspectorScriptProfilerAgent*, Inspector::InspectorHeapAgent*, InspectorPageAgent*);
+    InspectorTimelineAgent(WebAgentContext&);
     virtual ~InspectorTimelineAgent();
 
     void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) final;
@@ -212,9 +206,6 @@ private:
 
     std::unique_ptr<Inspector::TimelineFrontendDispatcher> m_frontendDispatcher;
     RefPtr<Inspector::TimelineBackendDispatcher> m_backendDispatcher;
-    Inspector::InspectorScriptProfilerAgent* m_scriptProfilerAgent;
-    Inspector::InspectorHeapAgent* m_heapAgent;
-    InspectorPageAgent* m_pageAgent;
 
     Vector<TimelineRecordEntry> m_recordStack;
     Vector<TimelineRecordEntry> m_pendingConsoleProfileRecords;