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

Reviewed by Joseph Pecoraro.

Source/JavaScriptCore:

* inspector/JSGlobalObjectConsoleClient.h:
(Inspector::JSGlobalObjectConsoleClient::setInspectorScriptProfilerAgent): Added.
* inspector/JSGlobalObjectConsoleClient.cpp:
(Inspector::JSGlobalObjectConsoleClient::JSGlobalObjectConsoleClient):
(Inspector::JSGlobalObjectConsoleClient::startConsoleProfile):
(Inspector::JSGlobalObjectConsoleClient::stopConsoleProfile):

* inspector/JSGlobalObjectInspectorController.cpp:
(Inspector::JSGlobalObjectInspectorController::JSGlobalObjectInspectorController):
(Inspector::JSGlobalObjectInspectorController::createLazyAgents):

Source/WebCore:

No change in functionality.

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

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/JSGlobalObjectConsoleClient.cpp
Source/JavaScriptCore/inspector/JSGlobalObjectConsoleClient.h
Source/JavaScriptCore/inspector/JSGlobalObjectInspectorController.cpp
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorController.cpp

index 6b21256..9595002 100644 (file)
@@ -1,5 +1,24 @@
 2019-03-19  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: ScriptProfiler: lazily create the agent
+        https://bugs.webkit.org/show_bug.cgi?id=195591
+        <rdar://problem/48791756>
+
+        Reviewed by Joseph Pecoraro.
+
+        * inspector/JSGlobalObjectConsoleClient.h:
+        (Inspector::JSGlobalObjectConsoleClient::setInspectorScriptProfilerAgent): Added.
+        * inspector/JSGlobalObjectConsoleClient.cpp:
+        (Inspector::JSGlobalObjectConsoleClient::JSGlobalObjectConsoleClient):
+        (Inspector::JSGlobalObjectConsoleClient::startConsoleProfile):
+        (Inspector::JSGlobalObjectConsoleClient::stopConsoleProfile):
+
+        * inspector/JSGlobalObjectInspectorController.cpp:
+        (Inspector::JSGlobalObjectInspectorController::JSGlobalObjectInspectorController):
+        (Inspector::JSGlobalObjectInspectorController::createLazyAgents):
+
+2019-03-19  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: Heap: lazily create the agent
         https://bugs.webkit.org/show_bug.cgi?id=195590
         <rdar://problem/48791750>
index 79e0275..c1e8581 100644 (file)
@@ -54,11 +54,10 @@ void JSGlobalObjectConsoleClient::setLogToSystemConsole(bool shouldLog)
     sLogToSystemConsole = shouldLog;
 }
 
-JSGlobalObjectConsoleClient::JSGlobalObjectConsoleClient(InspectorConsoleAgent* consoleAgent, InspectorDebuggerAgent* debuggerAgent, InspectorScriptProfilerAgent* scriptProfilerAgent)
+JSGlobalObjectConsoleClient::JSGlobalObjectConsoleClient(InspectorConsoleAgent* consoleAgent, InspectorDebuggerAgent* debuggerAgent)
     : ConsoleClient()
     , m_consoleAgent(consoleAgent)
     , m_debuggerAgent(debuggerAgent)
-    , m_scriptProfilerAgent(scriptProfilerAgent)
 {
 }
 
@@ -121,27 +120,33 @@ void JSGlobalObjectConsoleClient::profileEnd(JSC::ExecState*, const String& titl
 
 void JSGlobalObjectConsoleClient::startConsoleProfile()
 {
+    ErrorString unused;
+
     // FIXME: <https://webkit.org/b/158753> Generalize the concept of Instruments on the backend to work equally for JSContext and Web inspection
-    m_scriptProfilerAgent->programmaticCaptureStarted();
+    if (m_scriptProfilerAgent)
+        m_scriptProfilerAgent->programmaticCaptureStarted();
 
     m_profileRestoreBreakpointActiveValue = m_debuggerAgent->breakpointsActive();
-
-    ErrorString unused;
     m_debuggerAgent->setBreakpointsActive(unused, false);
 
-    const bool includeSamples = true;
-    m_scriptProfilerAgent->startTracking(unused, &includeSamples);
+    if (m_scriptProfilerAgent) {
+        const bool includeSamples = true;
+        m_scriptProfilerAgent->startTracking(unused, &includeSamples);
+    }
 }
 
 void JSGlobalObjectConsoleClient::stopConsoleProfile()
 {
     ErrorString unused;
-    m_scriptProfilerAgent->stopTracking(unused);
+
+    if (m_scriptProfilerAgent)
+        m_scriptProfilerAgent->stopTracking(unused);
 
     m_debuggerAgent->setBreakpointsActive(unused, m_profileRestoreBreakpointActiveValue);
 
     // FIXME: <https://webkit.org/b/158753> Generalize the concept of Instruments on the backend to work equally for JSContext and Web inspection
-    m_scriptProfilerAgent->programmaticCaptureStopped();
+    if (m_scriptProfilerAgent)
+        m_scriptProfilerAgent->programmaticCaptureStopped();
 }
 
 void JSGlobalObjectConsoleClient::takeHeapSnapshot(JSC::ExecState*, const String& title)
index 2e169c2..7401889 100644 (file)
@@ -38,12 +38,14 @@ class InspectorScriptProfilerAgent;
 class JSGlobalObjectConsoleClient final : public JSC::ConsoleClient {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    explicit JSGlobalObjectConsoleClient(InspectorConsoleAgent*, InspectorDebuggerAgent*, InspectorScriptProfilerAgent*);
+    explicit JSGlobalObjectConsoleClient(InspectorConsoleAgent*, InspectorDebuggerAgent*);
     virtual ~JSGlobalObjectConsoleClient() { }
 
     static bool logToSystemConsole();
     static void setLogToSystemConsole(bool);
 
+    void setInspectorScriptProfilerAgent(InspectorScriptProfilerAgent* agent) { m_scriptProfilerAgent = agent; }
+
 protected:
     void messageWithTypeAndLevel(MessageType, MessageLevel, JSC::ExecState*, Ref<ScriptArguments>&&) override;
     void count(JSC::ExecState*, Ref<ScriptArguments>&&) override;
@@ -66,7 +68,7 @@ private:
 
     InspectorConsoleAgent* m_consoleAgent;
     InspectorDebuggerAgent* m_debuggerAgent;
-    InspectorScriptProfilerAgent* m_scriptProfilerAgent;
+    InspectorScriptProfilerAgent* m_scriptProfilerAgent { nullptr };
     Vector<String> m_profiles;
     bool m_profileRestoreBreakpointActiveValue { false };
 };
index 7844ef7..7ff3646 100644 (file)
@@ -75,18 +75,16 @@ JSGlobalObjectInspectorController::JSGlobalObjectInspectorController(JSGlobalObj
     auto runtimeAgent = std::make_unique<JSGlobalObjectRuntimeAgent>(context);
     auto consoleAgent = std::make_unique<InspectorConsoleAgent>(context);
     auto debuggerAgent = std::make_unique<JSGlobalObjectDebuggerAgent>(context, consoleAgent.get());
-    auto scriptProfilerAgent = std::make_unique<InspectorScriptProfilerAgent>(context);
 
     m_inspectorAgent = inspectorAgent.get();
     m_debuggerAgent = debuggerAgent.get();
     m_consoleAgent = consoleAgent.get();
-    m_consoleClient = std::make_unique<JSGlobalObjectConsoleClient>(m_consoleAgent, m_debuggerAgent, scriptProfilerAgent.get());
+    m_consoleClient = std::make_unique<JSGlobalObjectConsoleClient>(m_consoleAgent, m_debuggerAgent);
 
     m_agents.append(WTFMove(inspectorAgent));
     m_agents.append(WTFMove(runtimeAgent));
     m_agents.append(WTFMove(consoleAgent));
     m_agents.append(WTFMove(debuggerAgent));
-    m_agents.append(WTFMove(scriptProfilerAgent));
 
     m_executionStopwatch->start();
 }
@@ -312,6 +310,10 @@ void JSGlobalObjectInspectorController::createLazyAgents()
 
     auto context = jsAgentContext();
 
+    auto scriptProfilerAgentPtr = std::make_unique<InspectorScriptProfilerAgent>(context);
+    m_consoleClient->setInspectorScriptProfilerAgent(scriptProfilerAgentPtr.get());
+    m_agents.append(WTFMove(scriptProfilerAgentPtr));
+
     auto heapAgent = std::make_unique<InspectorHeapAgent>(context);
     if (m_consoleAgent)
         m_consoleAgent->setInspectorHeapAgent(heapAgent.get());
index 9fca32e..ece62e8 100644 (file)
@@ -1,5 +1,19 @@
 2019-03-19  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: ScriptProfiler: lazily create the agent
+        https://bugs.webkit.org/show_bug.cgi?id=195591
+        <rdar://problem/48791756>
+
+        Reviewed by Joseph Pecoraro.
+
+        No change in functionality.
+
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::InspectorController):
+        (WebCore::InspectorController::createLazyAgents):
+
+2019-03-19  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: DOMStorage: lazily create the agent
         https://bugs.webkit.org/show_bug.cgi?id=195588
         <rdar://problem/48791878>
index ce62107..bf16237 100644 (file)
@@ -127,10 +127,6 @@ InspectorController::InspectorController(Page& page, InspectorClient* inspectorC
     InspectorDatabaseAgent* databaseAgent = databaseAgentPtr.get();
     m_agents.append(WTFMove(databaseAgentPtr));
 
-    auto scriptProfilerAgentPtr = std::make_unique<InspectorScriptProfilerAgent>(pageContext);
-    m_instrumentingAgents->setInspectorScriptProfilerAgent(scriptProfilerAgentPtr.get());
-    m_agents.append(WTFMove(scriptProfilerAgentPtr));
-
     auto consoleAgentPtr = std::make_unique<PageConsoleAgent>(pageContext, m_domAgent);
     WebConsoleAgent* consoleAgent = consoleAgentPtr.get();
     m_instrumentingAgents->setWebConsoleAgent(consoleAgentPtr.get());
@@ -192,6 +188,11 @@ void InspectorController::createLazyAgents()
 #if ENABLE(INDEXED_DATABASE)
     m_agents.append(std::make_unique<InspectorIndexedDBAgent>(pageContext, m_pageAgent));
 #endif
+
+    auto scriptProfilerAgentPtr = std::make_unique<InspectorScriptProfilerAgent>(pageContext);
+    m_instrumentingAgents->setInspectorScriptProfilerAgent(scriptProfilerAgentPtr.get());
+    m_agents.append(WTFMove(scriptProfilerAgentPtr));
+
 #if ENABLE(RESOURCE_USAGE)
     m_agents.append(std::make_unique<InspectorCPUProfilerAgent>(pageContext));
     m_agents.append(std::make_unique<InspectorMemoryAgent>(pageContext));