Fixes a bug in the profiler where call and apply would show up
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 May 2008 13:57:41 +0000 (13:57 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 May 2008 13:57:41 +0000 (13:57 +0000)
and double the time spent in a function. We don't want to show call
and apply at all in the profiles. This change excludes them.

Reviewed by Kevin McCullough.

* profiler/ProfileNode.cpp:
(KJS::ProfileNode::stopProfiling): Remove a second for loop and
calculate self time in the existing loop.
* profiler/Profiler.cpp:
(KJS::shouldExcludeFunction): Helper inline function that returns
true in the current function in an InternalFunctionImp and it is
has the functionName call or apply.
(KJS::Profiler::willExecute): Call shouldExcludeFunction and return
early if if returns true.
(KJS::Profiler::didExecute): Ditto.

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

JavaScriptCore/ChangeLog
JavaScriptCore/profiler/ProfileNode.cpp
JavaScriptCore/profiler/Profiler.cpp

index 9d7274f..b2f0734 100644 (file)
@@ -1,3 +1,22 @@
+2008-05-19  Timothy Hatcher  <timothy@apple.com>
+
+        Fixes a bug in the profiler where call and apply would show up
+        and double the time spent in a function. We don't want to show call
+        and apply at all in the profiles. This change excludes them.
+
+        Reviewed by Kevin McCullough.
+
+        * profiler/ProfileNode.cpp:
+        (KJS::ProfileNode::stopProfiling): Remove a second for loop and
+        calculate self time in the existing loop.
+        * profiler/Profiler.cpp:
+        (KJS::shouldExcludeFunction): Helper inline function that returns
+        true in the current function in an InternalFunctionImp and it is 
+        has the functionName call or apply.
+        (KJS::Profiler::willExecute): Call shouldExcludeFunction and return
+        early if if returns true.
+        (KJS::Profiler::didExecute): Ditto.
+
 2008-05-19  Kevin McCullough  <kmccullough@apple.com>
 
         Reviewed by Tim.
index f8acf3d..8a60da8 100644 (file)
@@ -96,13 +96,15 @@ void ProfileNode::stopProfiling()
     if (m_startTime)
         endAndRecordCall();
 
-    StackIterator endOfChildren = m_children.end();
-    for (StackIterator it = m_children.begin(); it != endOfChildren; ++it)
-        (*it)->stopProfiling();
+    ASSERT(m_selfTime == 0.0);
 
     // Calculate Self time and the percentages once we stop profiling.
-    for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild)
+    StackIterator endOfChildren = m_children.end();
+    for (StackIterator currentChild = m_children.begin(); currentChild != endOfChildren; ++currentChild) {
+        (*currentChild)->stopProfiling();
         m_selfTime += (*currentChild)->totalTime();
+    }
+
     ASSERT(m_selfTime <= m_totalTime);
     m_selfTime = m_totalTime - m_selfTime;
 
index 9c2e9da..8d6e347 100644 (file)
@@ -81,11 +81,26 @@ void Profiler::stopProfiling()
     m_currentProfile = 0;
 }
 
+static inline bool shouldExcludeFunction(ExecState* exec, JSObject* calledFunction)
+{
+    if (!calledFunction->inherits(&InternalFunctionImp::info))
+        return false;
+    // Don't record a call for function.call and function.apply.
+    if (static_cast<InternalFunctionImp*>(calledFunction)->functionName() == exec->propertyNames().call)
+        return true;
+    if (static_cast<InternalFunctionImp*>(calledFunction)->functionName() == exec->propertyNames().apply)
+        return true;
+    return false;
+}
+
 void Profiler::willExecute(ExecState* exec, JSObject* calledFunction)
 {
     if (!m_profiling || exec->lexicalGlobalObject()->pageGroupIdentifier() != m_pageGroupIdentifier)
         return;
 
+    if (shouldExcludeFunction(exec, calledFunction))
+        return;
+
     Vector<UString> callStackNames;
     getStackNames(callStackNames, exec, calledFunction);
     m_currentProfile->willExecute(callStackNames);
@@ -106,6 +121,9 @@ void Profiler::didExecute(ExecState* exec, JSObject* calledFunction)
     if (!m_profiling || exec->lexicalGlobalObject()->pageGroupIdentifier() != m_pageGroupIdentifier)
         return;
 
+    if (shouldExcludeFunction(exec, calledFunction))
+        return;
+
     Vector<UString> callStackNames;
     getStackNames(callStackNames, exec, calledFunction);
     m_currentProfile->didExecute(callStackNames);