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):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.