Changeset 34362 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Jun 4, 2008, 11:53:10 AM (17 years ago)
Author:
[email protected]
Message:

2008-06-04 Kevin McCullough <[email protected]>

Reviewed by Geoff.

<rdar://problem/5969992> JSProfiler: Remove the recursion limit in the
profiler.

  • This patch removes the use of recursion for the sort functions.
  • JavaScriptCore.exp: Change the signatures of the functions being exported.
  • profiler/Profile.cpp: (KJS::Profile::sort): This generic function will accept any of the static sort functions and apply them to the whole tree.
  • profiler/Profile.h: All of the sorting functions now call the new sort() function. (KJS::Profile::sortTotalTimeDescending): (KJS::Profile::sortTotalTimeAscending): (KJS::Profile::sortSelfTimeDescending): (KJS::Profile::sortSelfTimeAscending): (KJS::Profile::sortCallsDescending): (KJS::Profile::sortCallsAscending): (KJS::Profile::sortFunctionNameDescending): (KJS::Profile::sortFunctionNameAscending):
  • profiler/ProfileNode.cpp: (KJS::ProfileNode::ProfileNode): m_head used to point to the head node if this was the head node. It now points to null to make iteration easy (KJS::ProfileNode::willExecute): Now must check if m_head is null, this check used to happend in the constructor. (KJS::ProfileNode::stopProfiling): Again the check is slightly different to determine if this is the head. (KJS::ProfileNode::traverseNextNode): This function returns the next node in post order. (KJS::ProfileNode::sort): This generic function will sort according to the comparator passed in, then reset the children pointers to macth the new order.
  • profiler/ProfileNode.h: The sorting function were removed from the definition file and instead use the new generic sort() function (KJS::ProfileNode::totalPercent): because the head can now be empty we need to check here too for the head node. (KJS::ProfileNode::selfPercent): Ditto (KJS::ProfileNode::firstChild): This function is necessary for the iterative algorithm in Profile.cpp. (KJS::ProfileNode::sortTotalTimeDescending): (KJS::ProfileNode::sortTotalTimeAscending): (KJS::ProfileNode::sortSelfTimeDescending): (KJS::ProfileNode::sortSelfTimeAscending): (KJS::ProfileNode::sortCallsDescending): (KJS::ProfileNode::sortCallsAscending): (KJS::ProfileNode::sortFunctionNameDescending): (KJS::ProfileNode::sortFunctionNameAscending): (KJS::ProfileNode::childrenBegin): (KJS::ProfileNode::childrenEnd): (KJS::ProfileNode::totalTimeDescendingComparator): (KJS::ProfileNode::totalTimeAscendingComparator): (KJS::ProfileNode::selfTimeDescendingComparator): (KJS::ProfileNode::selfTimeAscendingComparator): (KJS::ProfileNode::callsDescendingComparator): (KJS::ProfileNode::callsAscendingComparator): (KJS::ProfileNode::functionNameDescendingComparator): (KJS::ProfileNode::functionNameAscendingComparator):
Location:
trunk/JavaScriptCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r34361 r34362  
     12008-06-04  Kevin McCullough  <[email protected]>
     2
     3        Reviewed by Geoff.
     4
     5        <rdar://problem/5969992> JSProfiler: Remove the recursion limit in the
     6        profiler.
     7        - This patch removes the use of recursion for the sort functions.
     8
     9        * JavaScriptCore.exp: Change the signatures of the functions being
     10        exported.
     11        * profiler/Profile.cpp:
     12        (KJS::Profile::sort): This generic function will accept any of the
     13        static sort functions and apply them to the whole tree.
     14        * profiler/Profile.h: All of the sorting functions now call the new
     15        sort() function.
     16        (KJS::Profile::sortTotalTimeDescending):
     17        (KJS::Profile::sortTotalTimeAscending):
     18        (KJS::Profile::sortSelfTimeDescending):
     19        (KJS::Profile::sortSelfTimeAscending):
     20        (KJS::Profile::sortCallsDescending):
     21        (KJS::Profile::sortCallsAscending):
     22        (KJS::Profile::sortFunctionNameDescending):
     23        (KJS::Profile::sortFunctionNameAscending):
     24        * profiler/ProfileNode.cpp:
     25        (KJS::ProfileNode::ProfileNode): m_head used to point to the head node
     26        if this was the head node.  It now points to null to make iteration easy
     27        (KJS::ProfileNode::willExecute): Now must check if m_head is null, this
     28        check used to happend in the constructor.
     29        (KJS::ProfileNode::stopProfiling): Again the check is slightly different
     30        to determine if this is the head.
     31        (KJS::ProfileNode::traverseNextNode): This function returns the next
     32        node in post order.
     33        (KJS::ProfileNode::sort): This generic function will sort according to
     34        the comparator passed in, then reset the children pointers to macth the
     35        new order.
     36        * profiler/ProfileNode.h: The sorting function were removed from the
     37        definition file and instead use the new generic sort() function
     38        (KJS::ProfileNode::totalPercent): because the head can now be empty we
     39        need to check here too for the head node.
     40        (KJS::ProfileNode::selfPercent): Ditto
     41        (KJS::ProfileNode::firstChild): This function is necessary for the
     42        iterative algorithm in Profile.cpp.
     43        (KJS::ProfileNode::sortTotalTimeDescending):
     44        (KJS::ProfileNode::sortTotalTimeAscending):
     45        (KJS::ProfileNode::sortSelfTimeDescending):
     46        (KJS::ProfileNode::sortSelfTimeAscending):
     47        (KJS::ProfileNode::sortCallsDescending):
     48        (KJS::ProfileNode::sortCallsAscending):
     49        (KJS::ProfileNode::sortFunctionNameDescending):
     50        (KJS::ProfileNode::sortFunctionNameAscending):
     51        (KJS::ProfileNode::childrenBegin):
     52        (KJS::ProfileNode::childrenEnd):
     53        (KJS::ProfileNode::totalTimeDescendingComparator):
     54        (KJS::ProfileNode::totalTimeAscendingComparator):
     55        (KJS::ProfileNode::selfTimeDescendingComparator):
     56        (KJS::ProfileNode::selfTimeAscendingComparator):
     57        (KJS::ProfileNode::callsDescendingComparator):
     58        (KJS::ProfileNode::callsAscendingComparator):
     59        (KJS::ProfileNode::functionNameDescendingComparator):
     60        (KJS::ProfileNode::functionNameAscendingComparator):
     61
    1622008-06-04  Alexey Proskuryakov  <[email protected]>
    263
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r34361 r34362  
    1616__ZN3KJS11JSImmediate8toObjectEPKNS_7JSValueEPNS_9ExecStateE
    1717__ZN3KJS11JSImmediate8toStringEPKNS_7JSValueE
    18 __ZN3KJS11ProfileNode10restoreAllEv
    19 __ZN3KJS11ProfileNode18sortCallsAscendingEv
    20 __ZN3KJS11ProfileNode19sortCallsDescendingEv
    21 __ZN3KJS11ProfileNode21sortSelfTimeAscendingEv
    22 __ZN3KJS11ProfileNode22sortSelfTimeDescendingEv
    23 __ZN3KJS11ProfileNode22sortTotalTimeAscendingEv
    24 __ZN3KJS11ProfileNode23sortTotalTimeDescendingEv
    25 __ZN3KJS11ProfileNode25sortFunctionNameAscendingEv
    26 __ZN3KJS11ProfileNode26sortFunctionNameDescendingEv
     18__ZN3KJS11ProfileNode4sortEPFbRKN3WTF6RefPtrIS0_EES5_E
    2719__ZN3KJS11ProfileNode5focusERKNS_14CallIdentifierEb
    2820__ZN3KJS11ProfileNode7excludeERKNS_14CallIdentifierE
     21__ZN3KJS11ProfileNode10restoreAllEv
    2922__ZN3KJS11ProgramNode6createEPNS_14SourceElementsEPN3WTF6VectorISt4pairINS_10IdentifierEjELm16EEEPNS4_INS3_6RefPtrINS_12FuncDeclNodeEEELm16EEEbb
    3023__ZN3KJS11PropertyMap11getLocationERKNS_10IdentifierE
     
    9689__ZN3KJS7CStringD1Ev
    9790__ZN3KJS7Machine13dumpCallFrameEPKNS_9CodeBlockEPNS_14ScopeChainNodeEPNS_12RegisterFileEPKNS_8RegisterE
     91__ZN3KJS7Profile4sortEPFvPNS_11ProfileNodeEE
    9892__ZN3KJS7UString3Rep11computeHashEPKti
    9993__ZN3KJS7UString3Rep4nullE
     
    150144__ZN3KJS9ExecStateC1EPNS_14JSGlobalObjectEPNS_8JSObjectEPNS_14ScopeChainNodeE
    151145__ZN3KJSeqERKNS_7UStringEPKc
     146__ZN3KJSgtERKNS_7UStringES2_
     147__ZN3KJSltERKNS_7UStringES2_
    152148__ZN3WTF10fastCallocEmm
    153149__ZN3WTF10fastMallocEm
  • trunk/JavaScriptCore/profiler/Profile.cpp

    r34092 r34362  
    8787}
    8888
     89void Profile::sort(SortFunction function) {
     90
     91    ProfileNode* currentNode = m_headNode->firstChild();
     92    for (ProfileNode* nextNode = currentNode; nextNode; nextNode = nextNode->firstChild())
     93        currentNode = nextNode;
     94
     95    ProfileNode* endNode = m_headNode->traverseNextNode();
     96    while (currentNode && currentNode != endNode) {
     97    function(currentNode);
     98    currentNode = currentNode->traverseNextNode();
     99    }
     100}
     101
    89102#ifndef NDEBUG
    90103void Profile::debugPrintData() const
  • trunk/JavaScriptCore/profiler/Profile.h

    r34092 r34362  
    3434
    3535    class ExecState;
     36    typedef void (*SortFunction)(ProfileNode*);
    3637
    3738    class Profile : public RefCounted<Profile> {
     
    5152        unsigned pageGroupIdentifier() const { return m_pageGroupIdentifier; }
    5253
    53         void sortTotalTimeDescending() { m_headNode->sortTotalTimeDescending(); }
    54         void sortTotalTimeAscending() { m_headNode->sortTotalTimeAscending(); }
    55         void sortSelfTimeDescending() { m_headNode->sortSelfTimeDescending(); }
    56         void sortSelfTimeAscending() { m_headNode->sortSelfTimeAscending(); }
    57         void sortCallsDescending() { m_headNode->sortCallsDescending(); }
    58         void sortCallsAscending() { m_headNode->sortCallsAscending(); }
    59         void sortFunctionNameDescending() { m_headNode->sortFunctionNameDescending(); }
    60         void sortFunctionNameAscending() { m_headNode->sortFunctionNameAscending(); }
     54        void sort(SortFunction);
     55        void sortTotalTimeDescending() { sort(ProfileNode::sortTotalTimeDescending); }
     56        void sortTotalTimeAscending() { sort(ProfileNode::sortTotalTimeAscending); }
     57        void sortSelfTimeDescending() { sort(ProfileNode::sortSelfTimeDescending); }
     58        void sortSelfTimeAscending() { sort(ProfileNode::sortSelfTimeAscending); }
     59        void sortCallsDescending() { sort(ProfileNode::sortCallsDescending); }
     60        void sortCallsAscending() { sort(ProfileNode::sortCallsAscending); }
     61        void sortFunctionNameDescending() { sort(ProfileNode::sortFunctionNameDescending); }
     62        void sortFunctionNameAscending() { sort(ProfileNode::sortFunctionNameAscending); }
    6163
    6264        void focus(const ProfileNode* profileNode) { if (!profileNode) return; m_headNode->focus(profileNode->callIdentifier()); }
  • trunk/JavaScriptCore/profiler/ProfileNode.cpp

    r34310 r34362  
    7070    , m_visible(true)
    7171{
    72     if (!m_head)
    73         m_head = this;
    74 
    7572    startTimer();
    7673}
     
    8582    }
    8683
    87     RefPtr<ProfileNode> newChild = ProfileNode::create(callIdentifier, m_head, this);
     84    RefPtr<ProfileNode> newChild = ProfileNode::create(callIdentifier, m_head ? m_head : this, this);   // If this ProfileNode has no head it is the head.
    8885    if (m_children.size())
    8986        m_children.last()->setNextSibling(newChild.get());
     
    137134    m_actualSelfTime = m_actualTotalTime - m_actualSelfTime;
    138135
    139     if (m_head == this && m_actualSelfTime) {
     136    if (!m_head && m_actualSelfTime) {
    140137        ProfileNode* idleNode = willExecute(CallIdentifier(NonJSExecution, 0, 0));
    141138
     
    150147}
    151148
    152 // Sorting methods
    153 
    154 static inline bool totalTimeDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b)
    155 {
    156     return a->totalTime() > b->totalTime();
    157 }
    158 
    159 void ProfileNode::sortTotalTimeDescending()
    160 {
    161     std::sort(m_children.begin(), m_children.end(), totalTimeDescendingComparator);
    162 
    163     unsigned size = m_children.size();
    164     for (unsigned i = 0; i < size; ++i)
    165         m_children[i]->sortTotalTimeDescending();
    166    
    167     resetChildrensSiblings();
    168 }
    169 
    170 static inline bool totalTimeAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b)
    171 {
    172     return a->totalTime() < b->totalTime();
    173 }
    174 
    175 void ProfileNode::sortTotalTimeAscending()
    176 {
    177     std::sort(m_children.begin(), m_children.end(), totalTimeAscendingComparator);
    178 
    179     unsigned size = m_children.size();
    180     for (unsigned i = 0; i < size; ++i)
    181         m_children[i]->sortTotalTimeAscending();
    182 
    183     resetChildrensSiblings();
    184 }
    185 
    186 static inline bool selfTimeDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b)
    187 {
    188     return a->selfTime() > b->selfTime();
    189 }
    190 
    191 void ProfileNode::sortSelfTimeDescending()
    192 {
    193     std::sort(m_children.begin(), m_children.end(), selfTimeDescendingComparator);
    194 
    195     unsigned size = m_children.size();
    196     for (unsigned i = 0; i < size; ++i)
    197         m_children[i]->sortSelfTimeDescending();
    198 
    199     resetChildrensSiblings();
    200 }
    201 
    202 static inline bool selfTimeAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b)
    203 {
    204     return a->selfTime() < b->selfTime();
    205 }
    206 
    207 void ProfileNode::sortSelfTimeAscending()
    208 {
    209     std::sort(m_children.begin(), m_children.end(), selfTimeAscendingComparator);
    210 
    211     unsigned size = m_children.size();
    212     for (unsigned i = 0; i < size; ++i)
    213         m_children[i]->sortSelfTimeAscending();
    214 
    215     resetChildrensSiblings();
    216 }
    217 
    218 static inline bool callsDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b)
    219 {
    220     return a->numberOfCalls() > b->numberOfCalls();
    221 }
    222 
    223 void ProfileNode::sortCallsDescending()
    224 {
    225     std::sort(m_children.begin(), m_children.end(), callsDescendingComparator);
    226 
    227     unsigned size = m_children.size();
    228     for (unsigned i = 0; i < size; ++i)
    229         m_children[i]->sortCallsDescending();
    230 
    231     resetChildrensSiblings();
    232 }
    233 
    234 static inline bool callsAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b)
    235 {
    236     return a->numberOfCalls() < b->numberOfCalls();
    237 }
    238 
    239 void ProfileNode::sortCallsAscending()
    240 {
    241     std::sort(m_children.begin(), m_children.end(), callsAscendingComparator);
    242 
    243     unsigned size = m_children.size();
    244     for (unsigned i = 0; i < size; ++i)
    245         m_children[i]->sortCallsAscending();
    246 
    247     resetChildrensSiblings();
    248 }
    249 
    250 static inline bool functionNameDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b)
    251 {
    252     return a->functionName() > b->functionName();
    253 }
    254 
    255 void ProfileNode::sortFunctionNameDescending()
    256 {
    257     std::sort(m_children.begin(), m_children.end(), functionNameDescendingComparator);
    258 
    259     unsigned size = m_children.size();
    260     for (unsigned i = 0; i < size; ++i)
    261         m_children[i]->sortFunctionNameDescending();
    262 
    263     resetChildrensSiblings();
    264 }
    265 
    266 static inline bool functionNameAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b)
    267 {
    268     return a->functionName() < b->functionName();
    269 }
    270 
    271 void ProfileNode::sortFunctionNameAscending()
    272 {
    273     std::sort(m_children.begin(), m_children.end(), functionNameAscendingComparator);
    274 
    275     unsigned size = m_children.size();
    276     for (unsigned i = 0; i < size; ++i)
    277         m_children[i]->sortFunctionNameAscending();
    278 
     149ProfileNode* ProfileNode::traverseNextNode() const
     150{
     151    ProfileNode* next = m_nextSibling;
     152    if (!next)
     153        return m_parent;
     154    while (ProfileNode* firstChild = next->firstChild())
     155        next = firstChild;
     156    return next;
     157}
     158
     159void ProfileNode::sort(bool comparator(const RefPtr<ProfileNode>& , const RefPtr<ProfileNode>& ))
     160{
     161    std::sort(childrenBegin(), childrenEnd(), comparator);   
    279162    resetChildrensSiblings();
    280163}
  • trunk/JavaScriptCore/profiler/ProfileNode.h

    r34361 r34362  
    8181        double selfTime() const { return m_visibleSelfTime; }
    8282        void setSelfTime(double time) { m_actualSelfTime = time; m_visibleSelfTime = time; }
    83         double totalPercent() const { return (m_visibleTotalTime / m_head->totalTime()) * 100.0; }
    84         double selfPercent() const { return (m_visibleSelfTime / m_head->totalTime()) * 100.0; }
     83        double totalPercent() const { return (m_visibleTotalTime / (m_head ? m_head->totalTime() : totalTime())) * 100.0; }
     84        double selfPercent() const { return (m_visibleSelfTime / (m_head ? m_head->totalTime() : totalTime())) * 100.0; }
    8585        unsigned numberOfCalls() const { return m_numberOfCalls; }
    8686        void setNumberOfCalls(unsigned number) { m_numberOfCalls = number; }
    8787        const Vector<RefPtr<ProfileNode> >& children() const { return m_children; }
     88        ProfileNode* firstChild() const { return m_children.size() ? m_children[0].get() : 0; }
    8889        void addChild(PassRefPtr<ProfileNode> prpChild);
    8990        void insertNode(PassRefPtr<ProfileNode> prpNode);
     
    9394        void setTreeVisible(bool visible);
    9495
    95         // Sorting functions
    96         void sortTotalTimeDescending();
    97         void sortTotalTimeAscending();
    98         void sortSelfTimeDescending();
    99         void sortSelfTimeAscending();
    100         void sortCallsDescending();
    101         void sortCallsAscending();
    102         void sortFunctionNameDescending();
    103         void sortFunctionNameAscending();
     96        ProfileNode* traverseNextNode() const;
     97        void sort(bool (*)(const RefPtr<ProfileNode>&, const RefPtr<ProfileNode>&));
     98        static void sortTotalTimeDescending(ProfileNode* n) { n->sort(totalTimeDescendingComparator); }
     99        static void sortTotalTimeAscending(ProfileNode* n) { n->sort(totalTimeAscendingComparator); }
     100        static void sortSelfTimeDescending(ProfileNode* n) { n->sort(selfTimeDescendingComparator); }
     101        static void sortSelfTimeAscending(ProfileNode* n) { n->sort(selfTimeAscendingComparator); }
     102        static void sortCallsDescending(ProfileNode* n) { n->sort(callsDescendingComparator); }
     103        static void sortCallsAscending(ProfileNode* n) { n->sort(callsAscendingComparator); }
     104        static void sortFunctionNameDescending(ProfileNode* n) { n->sort(functionNameDescendingComparator); }
     105        static void sortFunctionNameAscending(ProfileNode* n) { n->sort(functionNameAscendingComparator); }
    104106
    105107        void focus(const CallIdentifier&, bool forceVisible = false);
     
    118120        void startTimer();
    119121        void resetChildrensSiblings();
     122        RefPtr<ProfileNode>* childrenBegin() { return m_children.begin(); }
     123        RefPtr<ProfileNode>* childrenEnd() { return m_children.end(); }
     124
     125        // Sorting comparators
     126        static inline bool totalTimeDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) { return a->totalTime() > b->totalTime(); }
     127        static inline bool totalTimeAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) { return a->totalTime() < b->totalTime(); }
     128        static inline bool selfTimeDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) { return a->selfTime() > b->selfTime(); }
     129        static inline bool selfTimeAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) { return a->selfTime() < b->selfTime(); }
     130        static inline bool callsDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) { return a->numberOfCalls() > b->numberOfCalls(); }
     131        static inline bool callsAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) { return a->numberOfCalls() < b->numberOfCalls(); }
     132        static inline bool functionNameDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) { return a->functionName() > b->functionName(); }
     133        static inline bool functionNameAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) { return a->functionName() < b->functionName(); }
    120134
    121135        CallIdentifier m_callIdentifier;
Note: See TracChangeset for help on using the changeset viewer.