Web Inspector: InjectedScripts should not be profiled or displayed in Timeline
authorburg@cs.washington.edu <burg@cs.washington.edu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Sep 2014 03:34:11 +0000 (03:34 +0000)
committerburg@cs.washington.edu <burg@cs.washington.edu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Sep 2014 03:34:11 +0000 (03:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=136806

Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

It doesn't make sense to show profile nodes for injected scripts when profiling user content.
For now, omit nodes by suspending profiling before and after executing injected scripts.

* profiler/LegacyProfiler.cpp:
(JSC::LegacyProfiler::suspendProfiling): Added.
(JSC::LegacyProfiler::unsuspendProfiling): Added.
* profiler/LegacyProfiler.h:
* profiler/ProfileGenerator.cpp: Add isSuspended() flag, remove unused typedef.
(JSC::ProfileGenerator::ProfileGenerator):
(JSC::ProfileGenerator::willExecute):
(JSC::ProfileGenerator::didExecute):
* profiler/ProfileGenerator.h:
(JSC::ProfileGenerator::setIsSuspended): Added.

Source/WebCore:

Instead of creating timeline records for injected scripts, suspend profiling
of the current page before and after calling injected script functions.

* inspector/InspectorController.cpp:
(WebCore::InspectorController::willCallInjectedScriptFunction):
(WebCore::InspectorController::didCallInjectedScriptFunction):

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/profiler/LegacyProfiler.cpp
Source/JavaScriptCore/profiler/LegacyProfiler.h
Source/JavaScriptCore/profiler/ProfileGenerator.cpp
Source/JavaScriptCore/profiler/ProfileGenerator.h
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorController.cpp

index 6d6335b..e15c353 100644 (file)
@@ -1,5 +1,26 @@
 2014-09-29  Brian J. Burg  <burg@cs.washington.edu>
 
+        Web Inspector: InjectedScripts should not be profiled or displayed in Timeline
+        https://bugs.webkit.org/show_bug.cgi?id=136806
+
+        Reviewed by Timothy Hatcher.
+
+        It doesn't make sense to show profile nodes for injected scripts when profiling user content.
+        For now, omit nodes by suspending profiling before and after executing injected scripts.
+
+        * profiler/LegacyProfiler.cpp:
+        (JSC::LegacyProfiler::suspendProfiling): Added.
+        (JSC::LegacyProfiler::unsuspendProfiling): Added.
+        * profiler/LegacyProfiler.h:
+        * profiler/ProfileGenerator.cpp: Add isSuspended() flag, remove unused typedef.
+        (JSC::ProfileGenerator::ProfileGenerator):
+        (JSC::ProfileGenerator::willExecute):
+        (JSC::ProfileGenerator::didExecute):
+        * profiler/ProfileGenerator.h:
+        (JSC::ProfileGenerator::setIsSuspended): Added.
+
+2014-09-29  Brian J. Burg  <burg@cs.washington.edu>
+
         Web Inspector: InspectorValues should use references for out parameters
         https://bugs.webkit.org/show_bug.cgi?id=137190
 
index 3a99cc4..4fe2ba6 100644 (file)
@@ -123,6 +123,22 @@ static inline void callFunctionForProfilesWithGroup(std::function<void(ProfileGe
     }
 }
 
+void LegacyProfiler::suspendProfiling(JSC::ExecState* exec)
+{
+    if (!exec)
+        return;
+
+    callFunctionForProfilesWithGroup(std::bind(&ProfileGenerator::setIsSuspended, std::placeholders::_1, true), m_currentProfiles, exec->lexicalGlobalObject()->profileGroup());
+}
+
+void LegacyProfiler::unsuspendProfiling(JSC::ExecState* exec)
+{
+    if (!exec)
+        return;
+
+    callFunctionForProfilesWithGroup(std::bind(&ProfileGenerator::setIsSuspended, std::placeholders::_1, false), m_currentProfiles, exec->lexicalGlobalObject()->profileGroup());
+}
+
 void LegacyProfiler::willExecute(ExecState* callerCallFrame, JSValue function)
 {
     ASSERT(!m_currentProfiles.isEmpty());
index 7e79cbc..1d6cb26 100644 (file)
@@ -55,6 +55,10 @@ public:
     JS_EXPORT_PRIVATE PassRefPtr<Profile> stopProfiling(ExecState*, const WTF::String& title);
     void stopProfiling(JSGlobalObject*);
 
+    // Used to ignore profile node subtrees rooted at InjectedScript calls.
+    JS_EXPORT_PRIVATE void suspendProfiling(ExecState*);
+    JS_EXPORT_PRIVATE void unsuspendProfiling(ExecState*);
+
     void willExecute(ExecState* callerCallFrame, JSValue function);
     void willExecute(ExecState* callerCallFrame, const WTF::String& sourceURL, unsigned startingLineNumber, unsigned startingColumnNumber);
     void didExecute(ExecState* callerCallFrame, JSValue function);
index 7e43446..32e8926 100644 (file)
@@ -50,6 +50,7 @@ ProfileGenerator::ProfileGenerator(ExecState* exec, const String& title, unsigne
     , m_profileGroup(exec ? exec->lexicalGlobalObject()->profileGroup() : 0)
     , m_debuggerPausedTimestamp(NAN)
     , m_foundConsoleStartParent(false)
+    , m_suspended(false)
 {
     if (Debugger* debugger = exec->lexicalGlobalObject()->debugger())
         m_debuggerPausedTimestamp = debugger->isPaused() ? currentTime() : NAN;
@@ -162,6 +163,9 @@ void ProfileGenerator::willExecute(ExecState* callerCallFrame, const CallIdentif
     if (!m_origin)
         return;
 
+    if (m_suspended)
+        return;
+
     RefPtr<ProfileNode> calleeNode = nullptr;
 
     // Find or create a node for the callee call frame.
@@ -190,6 +194,9 @@ void ProfileGenerator::didExecute(ExecState* callerCallFrame, const CallIdentifi
     if (!m_origin)
         return;
 
+    if (m_suspended)
+        return;
+
     // Make a new node if the caller node has never seen this callee call frame before.
     // This can happen if |console.profile()| is called several frames deep in the call stack.
     ASSERT(m_currentNode);
index 7c970d6..9f51a3d 100644 (file)
@@ -57,9 +57,9 @@ namespace JSC {
         void didPause(PassRefPtr<DebuggerCallFrame>, const CallIdentifier&);
         void didContinue(PassRefPtr<DebuggerCallFrame>, const CallIdentifier&);
 
-        void stopProfiling();
+        void setIsSuspended(bool suspended) { ASSERT(m_suspended != suspended); m_suspended = suspended; }
 
-        typedef void (ProfileGenerator::*ProfileFunction)(ExecState* callerOrHandlerCallFrame, const CallIdentifier& callIdentifier);
+        void stopProfiling();
 
     private:
         ProfileGenerator(ExecState*, const WTF::String& title, unsigned uid);
@@ -79,6 +79,7 @@ namespace JSC {
         RefPtr<ProfileNode> m_rootNode;
         RefPtr<ProfileNode> m_currentNode;
         bool m_foundConsoleStartParent;
+        bool m_suspended;
     };
 
 } // namespace JSC
index a6dc4fb..c07c3ea 100644 (file)
@@ -1,5 +1,19 @@
 2014-09-29  Brian J. Burg  <burg@cs.washington.edu>
 
+        Web Inspector: InjectedScripts should not be profiled or displayed in Timeline
+        https://bugs.webkit.org/show_bug.cgi?id=136806
+
+        Reviewed by Timothy Hatcher.
+
+        Instead of creating timeline records for injected scripts, suspend profiling
+        of the current page before and after calling injected script functions.
+
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::willCallInjectedScriptFunction):
+        (WebCore::InspectorController::didCallInjectedScriptFunction):
+
+2014-09-29  Brian J. Burg  <burg@cs.washington.edu>
+
         Web Inspector: InspectorValues should use references for out parameters
         https://bugs.webkit.org/show_bug.cgi?id=137190
 
index 5b6eb25..595fa81 100644 (file)
@@ -72,6 +72,7 @@
 #include <inspector/IdentifiersFactory.h>
 #include <inspector/InspectorBackendDispatcher.h>
 #include <inspector/agents/InspectorAgent.h>
+#include <profiler/LegacyProfiler.h>
 #include <runtime/JSLock.h>
 
 #if ENABLE(REMOTE_INSPECTOR)
@@ -432,19 +433,14 @@ InspectorEvaluateHandler InspectorController::evaluateHandler() const
     return WebCore::evaluateHandlerFromAnyThread;
 }
 
-void InspectorController::willCallInjectedScriptFunction(JSC::ExecState* scriptState, const String& scriptName, int scriptLine)
+void InspectorController::willCallInjectedScriptFunction(JSC::ExecState* scriptState, const String&, int)
 {
-    ScriptExecutionContext* scriptExecutionContext = scriptExecutionContextFromExecState(scriptState);
-    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willCallFunction(scriptExecutionContext, scriptName, scriptLine);
-    m_injectedScriptInstrumentationCookies.append(cookie);
+    LegacyProfiler::profiler()->suspendProfiling(scriptState);
 }
 
 void InspectorController::didCallInjectedScriptFunction(JSC::ExecState* scriptState)
 {
-    ASSERT(!m_injectedScriptInstrumentationCookies.isEmpty());
-    ScriptExecutionContext* scriptExecutionContext = scriptExecutionContextFromExecState(scriptState);
-    InspectorInstrumentationCookie cookie = m_injectedScriptInstrumentationCookies.takeLast();
-    InspectorInstrumentation::didCallFunction(cookie, scriptExecutionContext);
+    LegacyProfiler::profiler()->unsuspendProfiling(scriptState);
 }
 
 void InspectorController::frontendInitialized()