JavaScriptCore:
authorkmccullough@apple.com <kmccullough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 May 2008 22:23:09 +0000 (22:23 +0000)
committerkmccullough@apple.com <kmccullough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 May 2008 22:23:09 +0000 (22:23 +0000)
2008-05-16  Kevin McCullough  <kmccullough@apple.com>

        Reviewed by Tim.

        <rdar://problem/5770054> JavaScript profiler (10928)
        Implement sorting for the profiler.
        I chose to sort the profileNodes in place since there is no reason they
        need to retain their original order.

        * JavaScriptCore.exp: Export the symbols.
        * profiler/Profile.h: Add the different ways a profile can be sorted.
        (KJS::Profile::sortTotalTimeDescending):
        (KJS::Profile::sortTotalTimeAscending):
        (KJS::Profile::sortSelfTimeDescending):
        (KJS::Profile::sortSelfTimeAscending):
        (KJS::Profile::sortCallsDescending):
        (KJS::Profile::sortCallsAscending):
        * profiler/ProfileNode.cpp: Implement those ways.
        (KJS::totalTimeDescendingComparator):
        (KJS::ProfileNode::sortTotalTimeDescending):
        (KJS::totalTimeAscendingComparator):
        (KJS::ProfileNode::sortTotalTimeAscending):
        (KJS::selfTimeDescendingComparator):
        (KJS::ProfileNode::sortSelfTimeDescending):
        (KJS::selfTimeAscendingComparator):
        (KJS::ProfileNode::sortSelfTimeAscending):
        (KJS::callsDescendingComparator):
        (KJS::ProfileNode::sortCallsDescending):
        (KJS::callsAscendingComparator):
        (KJS::ProfileNode::sortCallsAscending):
        * profiler/ProfileNode.h: No longer use a Deque since it cannot be
        sorted by std::sort and there was no reason not to use a Vector.  I
        previously had though I would do prepending but am not.
        (KJS::ProfileNode::selfTime):
        (KJS::ProfileNode::totalPercent):
        (KJS::ProfileNode::selfPercent):
        (KJS::ProfileNode::children):
        * profiler/Profiler.cpp: Removed these functions as they can be called
        directoy on the Profile object after getting the Vector of them.
        (KJS::getStackNames):
        * profiler/Profiler.h:

WebCore:

2008-05-16  Kevin McCullough  <kmccullough@apple.com>

        Reviewed by Tim.

        <rdar://problem/5770054> JavaScript profiler (10928)
        Use a Vector instead of a Deque since we don't use the extra capabilities
        of the Deque.

        * page/JavaScriptProfileNode.cpp:
        (WebCore::getChildren):
        (WebCore::toJS):

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

JavaScriptCore/ChangeLog
JavaScriptCore/JavaScriptCore.exp
JavaScriptCore/profiler/Profile.h
JavaScriptCore/profiler/ProfileNode.cpp
JavaScriptCore/profiler/ProfileNode.h
JavaScriptCore/profiler/Profiler.cpp
JavaScriptCore/profiler/Profiler.h
WebCore/ChangeLog
WebCore/page/JavaScriptProfileNode.cpp

index e486787..33fddb4 100644 (file)
@@ -1,3 +1,45 @@
+2008-05-16  Kevin McCullough  <kmccullough@apple.com>
+
+        Reviewed by Tim.
+
+        <rdar://problem/5770054> JavaScript profiler (10928)
+        Implement sorting for the profiler.
+        I chose to sort the profileNodes in place since there is no reason they
+        need to retain their original order.
+
+        * JavaScriptCore.exp: Export the symbols.
+        * profiler/Profile.h: Add the different ways a profile can be sorted.
+        (KJS::Profile::sortTotalTimeDescending):
+        (KJS::Profile::sortTotalTimeAscending):
+        (KJS::Profile::sortSelfTimeDescending):
+        (KJS::Profile::sortSelfTimeAscending):
+        (KJS::Profile::sortCallsDescending):
+        (KJS::Profile::sortCallsAscending):
+        * profiler/ProfileNode.cpp: Implement those ways.
+        (KJS::totalTimeDescendingComparator):
+        (KJS::ProfileNode::sortTotalTimeDescending):
+        (KJS::totalTimeAscendingComparator):
+        (KJS::ProfileNode::sortTotalTimeAscending):
+        (KJS::selfTimeDescendingComparator):
+        (KJS::ProfileNode::sortSelfTimeDescending):
+        (KJS::selfTimeAscendingComparator):
+        (KJS::ProfileNode::sortSelfTimeAscending):
+        (KJS::callsDescendingComparator):
+        (KJS::ProfileNode::sortCallsDescending):
+        (KJS::callsAscendingComparator):
+        (KJS::ProfileNode::sortCallsAscending):
+        * profiler/ProfileNode.h: No longer use a Deque since it cannot be
+        sorted by std::sort and there was no reason not to use a Vector.  I
+        previously had though I would do prepending but am not.
+        (KJS::ProfileNode::selfTime):
+        (KJS::ProfileNode::totalPercent):
+        (KJS::ProfileNode::selfPercent):
+        (KJS::ProfileNode::children):
+        * profiler/Profiler.cpp: Removed these functions as they can be called
+        directoy on the Profile object after getting the Vector of them.
+        (KJS::getStackNames):
+        * profiler/Profiler.h:
+
 2008-05-15  Ariya Hidayat  <ariya.hidayat@trolltech.com>
 
         Reviewed by Simon.
index da0b287..ccfb418 100644 (file)
@@ -91,6 +91,12 @@ __ZN3KJS11Interpreter8evaluateEPNS_9ExecStateERKNS_7UStringEiS5_PNS_7JSValueE
 __ZN3KJS11JSImmediate4typeEPKNS_7JSValueE
 __ZN3KJS11JSImmediate8toObjectEPKNS_7JSValueEPNS_9ExecStateE
 __ZN3KJS11JSImmediate8toStringEPKNS_7JSValueE
+__ZN3KJS11ProfileNode18sortCallsAscendingEv
+__ZN3KJS11ProfileNode19sortCallsDescendingEv
+__ZN3KJS11ProfileNode21sortSelfTimeAscendingEv
+__ZN3KJS11ProfileNode22sortSelfTimeDescendingEv
+__ZN3KJS11ProfileNode22sortTotalTimeAscendingEv
+__ZN3KJS11ProfileNode23sortTotalTimeDescendingEv
 __ZN3KJS11ProgramNode6createEPNS_14SourceElementsEPN3WTF6VectorISt4pairINS_10IdentifierEjELm16EEEPNS4_IPNS_12FuncDeclNodeELm16EEEbb
 __ZN3KJS11PropertyMap11getLocationERKNS_10IdentifierE
 __ZN3KJS11PropertyMap5clearEv
@@ -220,7 +226,7 @@ __ZN3WTF15ThreadConditionC1Ev
 __ZN3WTF15ThreadConditionD1Ev
 __ZN3WTF16callOnMainThreadEPFvPvES0_
 __ZN3WTF16fastZeroedMallocEm
-__ZN3WTF19initializeThreadingEv 
+__ZN3WTF19initializeThreadingEv
 __ZN3WTF23waitForThreadCompletionEjPPv
 __ZN3WTF28setMainThreadCallbacksPausedEb
 __ZN3WTF32atomicallyInitializedStaticMutexE
@@ -252,6 +258,7 @@ __ZNK3KJS6JSCell9getNumberEv
 __ZNK3KJS6JSCell9getStringERNS_7UStringE
 __ZNK3KJS6JSCell9getStringEv
 __ZNK3KJS6JSCell9getUInt32ERj
+__ZNK3KJS7Profile23printDataInspectorStyleEv
 __ZNK3KJS7JSValue15toInt32SlowCaseEPNS_9ExecStateERb
 __ZNK3KJS7JSValue16toUInt32SlowCaseEPNS_9ExecStateERb
 __ZNK3KJS7JSValue7toFloatEPNS_9ExecStateE
index 716f6bf..e53eda4 100644 (file)
@@ -49,6 +49,13 @@ namespace KJS {
 
         double totalTime() const { return m_callTree->totalTime(); }
 
+        void sortTotalTimeDescending() { m_callTree->sortTotalTimeDescending(); }
+        void sortTotalTimeAscending() { m_callTree->sortTotalTimeAscending(); }
+        void sortSelfTimeDescending() { m_callTree->sortSelfTimeDescending(); }
+        void sortSelfTimeAscending() { m_callTree->sortSelfTimeAscending(); }
+        void sortCallsDescending() { m_callTree->sortCallsDescending(); }
+        void sortCallsAscending() { m_callTree->sortCallsAscending(); }
+        
         void printDataInspectorStyle() const;
         void printDataSampleStyle() const;
 
index 7227018..6b34fc7 100644 (file)
@@ -110,6 +110,86 @@ void ProfileNode::stopProfiling()
     m_selfPercent = (selfTime() / Profiler::profiler()->currentProfile()->totalTime()) * 100.0;
 }
 
+#pragma mark Sorting methods
+
+static inline bool totalTimeDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b)
+{
+    return a->totalTime() > b->totalTime();
+}
+
+void ProfileNode::sortTotalTimeDescending()
+{
+    std::sort(m_children.begin(), m_children.end(), totalTimeDescendingComparator);
+
+    for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild)
+        (*currentChild)->sortTotalTimeDescending();
+}
+
+static inline bool totalTimeAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b)
+{
+    return a->totalTime() < b->totalTime();
+}
+
+void ProfileNode::sortTotalTimeAscending()
+{
+    std::sort(m_children.begin(), m_children.end(), totalTimeAscendingComparator);
+
+    for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild)
+        (*currentChild)->sortTotalTimeAscending();
+}
+
+static inline bool selfTimeDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b)
+{
+    return a->selfTime() > b->selfTime();
+}
+
+void ProfileNode::sortSelfTimeDescending()
+{
+    std::sort(m_children.begin(), m_children.end(), selfTimeDescendingComparator);
+
+    for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild)
+        (*currentChild)->sortSelfTimeDescending();
+}
+
+static inline bool selfTimeAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b)
+{
+    return a->selfTime() < b->selfTime();
+}
+
+void ProfileNode::sortSelfTimeAscending()
+{
+    std::sort(m_children.begin(), m_children.end(), selfTimeAscendingComparator);
+
+    for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild)
+        (*currentChild)->sortSelfTimeAscending();
+}
+
+static inline bool callsDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b)
+{
+    return a->numberOfCalls() > b->numberOfCalls();
+}
+
+void ProfileNode::sortCallsDescending()
+{
+    std::sort(m_children.begin(), m_children.end(), callsDescendingComparator);
+
+    for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild)
+        (*currentChild)->sortCallsDescending();
+}
+
+static inline bool callsAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b)
+{
+    return a->numberOfCalls() < b->numberOfCalls();
+}
+
+void ProfileNode::sortCallsAscending()
+{
+    std::sort(m_children.begin(), m_children.end(), callsAscendingComparator);
+
+    for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild)
+        (*currentChild)->sortCallsAscending();
+}
+
 void ProfileNode::printDataInspectorStyle(int indentLevel) const
 {
     // Print function names
index aed92cf..3cb426a 100644 (file)
@@ -30,7 +30,7 @@
 #define ProfileNode_h
 
 #include <kjs/ustring.h>
-#include <wtf/Deque.h>
+#include <wtf/Vector.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 #include <wtf/StrHash.h>
@@ -39,7 +39,7 @@ namespace KJS {
 
     class ProfileNode;
 
-    typedef Deque<RefPtr<ProfileNode> >::const_iterator StackIterator;
+    typedef Vector<RefPtr<ProfileNode> >::const_iterator StackIterator;
     typedef HashCountedSet<UString::Rep*> FunctionCallHashCount;
 
     class ProfileNode : public RefCounted<ProfileNode> {
@@ -56,11 +56,19 @@ namespace KJS {
 
         UString functionName() const { return m_functionName; }
         double totalTime() const { return m_totalTime; }
-        double selfTime() const { return m_selfTime;}
-        double totalPercent() const { return m_totalPercent;}
-        double selfPercent() const { return m_selfPercent;}
+        double selfTime() const { return m_selfTime; }
+        double totalPercent() const { return m_totalPercent; }
+        double selfPercent() const { return m_selfPercent; }
         unsigned numberOfCalls() const { return m_numberOfCalls; }
-        const Deque<RefPtr<ProfileNode> >& children() { return m_children; }
+        const Vector<RefPtr<ProfileNode> >& children() { return m_children; }
+
+        // Sorting functions
+        void sortTotalTimeDescending();
+        void sortTotalTimeAscending();
+        void sortSelfTimeDescending();
+        void sortSelfTimeAscending();
+        void sortCallsDescending();
+        void sortCallsAscending();
 
         void printDataInspectorStyle(int indentLevel) const;
         double printDataSampleStyle(int indentLevel, FunctionCallHashCount&) const;
@@ -78,7 +86,7 @@ namespace KJS {
         double m_selfPercent;
         unsigned m_numberOfCalls;
 
-        Deque<RefPtr<ProfileNode> > m_children;
+        Vector<RefPtr<ProfileNode> > m_children;
     };
 
 } // namespace KJS
index 2cdadaf..6296a24 100644 (file)
@@ -120,7 +120,6 @@ void Profiler::didExecute(ExecState* exec, const UString& sourceURL, int startin
 void getStackNames(Vector<UString>& names, ExecState* exec)
 {
     for (ExecState* currentState = exec; currentState; currentState = currentState->callingExecState()) {
-
         if (FunctionImp* functionImp = currentState->function())
             names.prepend(getFunctionName(functionImp));
         else if (ScopeNode* scopeNode = currentState->scopeNode())
@@ -153,16 +152,6 @@ UString getFunctionName(FunctionImp* functionImp)
     return (name.isEmpty() ? "[anonymous function]" : name) + " " + URL + ": " + UString::from(lineNumber);
 }
 
-void Profiler::printDataInspectorStyle(unsigned whichProfile) const
-{
-    m_allProfiles[whichProfile]->printDataInspectorStyle();
-}
-
-void Profiler::printDataSampleStyle(unsigned whichProfile) const
-{
-    m_allProfiles[whichProfile]->printDataSampleStyle();
-}
-
 void Profiler::debugLog(UString message)
 {
     printf("Profiler Log: %s\n", message.UTF8String().c_str());
index 270abab..fb5a2da 100644 (file)
@@ -56,9 +56,6 @@ namespace KJS {
 
         Profile* currentProfile() const { return m_currentProfile.get(); }
 
-        void printDataInspectorStyle(unsigned whichProfile) const;
-        void printDataSampleStyle(unsigned whichProfile) const;
-
     private:
         Profiler()
             : m_profiling(false)
index ade6435..9e3a8ae 100644 (file)
@@ -1,3 +1,15 @@
+2008-05-16  Kevin McCullough  <kmccullough@apple.com>
+
+        Reviewed by Tim.
+
+        <rdar://problem/5770054> JavaScript profiler (10928)
+        Use a Vector instead of a Deque since we don't use the extra capabilities
+        of the Deque.
+
+        * page/JavaScriptProfileNode.cpp:
+        (WebCore::getChildren):
+        (WebCore::toJS):
+
 2008-05-16  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Brady.
index 4dae4f5..0c3fc3e 100644 (file)
@@ -125,7 +125,7 @@ static JSValueRef getChildren(JSContextRef ctx, JSObjectRef thisObject, JSString
         return JSValueMakeUndefined(ctx);
 
     ProfileNode* profileNode = static_cast<ProfileNode*>(JSObjectGetPrivate(thisObject));
-    const Deque<RefPtr<ProfileNode> >& children = profileNode->children();
+    const Vector<RefPtr<ProfileNode> >& children = profileNode->children();
 
     JSObjectRef global = JSContextGetGlobalObject(ctx);
 
@@ -153,7 +153,7 @@ static JSValueRef getChildren(JSContextRef ctx, JSObjectRef thisObject, JSString
     if (exception && *exception)
         return JSValueMakeUndefined(ctx);
 
-    for (Deque<RefPtr<ProfileNode> >::const_iterator it = children.begin(); it != children.end(); ++it) {
+    for (Vector<RefPtr<ProfileNode> >::const_iterator it = children.begin(); it != children.end(); ++it) {
         JSValueRef arg0 = toRef(toJS(toJS(ctx), (*it).get() ));
         JSObjectCallAsFunction(ctx, pushFunction, result, 1, &arg0, exception);
         if (exception && *exception)
@@ -206,7 +206,6 @@ JSValue* toJS(ExecState* exec, ProfileNode* ProfileNode)
     ProfileNodeWrapper = toJS(JSObjectMake(toRef(exec), ProfileNodeClass(), static_cast<void*>(ProfileNode)));
     ProfileNodeCache().set(ProfileNode, ProfileNodeWrapper);
     return ProfileNodeWrapper;
-
 }