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

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

Reviewed by Darin.

<rdar://problem/5969992> JSProfiler: Remove the recursion limit in the
profiler
Implement Next Sibling pointers as groundwork for removing the recursion
limit in the profiler.

  • profiler/ProfileNode.cpp: Also I renamed parentNode and headNode since 'node' is redundant. (KJS::ProfileNode::ProfileNode): Initialize the nextSibling. (KJS::ProfileNode::willExecute): If there are already children then the new child needs to be the nextSibling of the last child. (KJS::ProfileNode::didExecute): (KJS::ProfileNode::addChild): Ditto. (KJS::ProfileNode::stopProfiling): (KJS::ProfileNode::sortTotalTimeDescending): For all of the sorting algorithms once the children are sorted their nextSibling pointers need to be reset to reflect the new order. (KJS::ProfileNode::sortTotalTimeAscending): (KJS::ProfileNode::sortSelfTimeDescending): (KJS::ProfileNode::sortSelfTimeAscending): (KJS::ProfileNode::sortCallsDescending): (KJS::ProfileNode::sortCallsAscending): (KJS::ProfileNode::sortFunctionNameDescending): (KJS::ProfileNode::sortFunctionNameAscending): (KJS::ProfileNode::resetChildrensSiblings): This new function simply loops over all of the children and sets their nextSibling pointers to the next child in the Vector (KJS::ProfileNode::debugPrintData):
  • profiler/ProfileNode.h: (KJS::ProfileNode::parent): (KJS::ProfileNode::setParent): (KJS::ProfileNode::nextSibling): (KJS::ProfileNode::setNextSibling): (KJS::ProfileNode::totalPercent): (KJS::ProfileNode::selfPercent):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/profiler/ProfileNode.cpp

    r34060 r34310  
    5959ProfileNode::ProfileNode(const CallIdentifier& callIdentifier, ProfileNode* headNode, ProfileNode* parentNode)
    6060    : m_callIdentifier(callIdentifier)
    61     , m_headNode(headNode)
    62     , m_parentNode(parentNode)
     61    , m_head(headNode)
     62    , m_parent(parentNode)
     63    , m_nextSibling(0)
    6364    , m_startTime(0.0)
    64     , m_actualTotalTime (0.0)
    65     , m_visibleTotalTime (0.0)
    66     , m_actualSelfTime (0.0)
    67     , m_visibleSelfTime (0.0)
     65    , m_actualTotalTime(0.0)
     66    , m_visibleTotalTime(0.0)
     67    , m_actualSelfTime(0.0)
     68    , m_visibleSelfTime(0.0)
    6869    , m_numberOfCalls(0)
    6970    , m_visible(true)
    7071{
    71     if (!m_headNode)
    72         m_headNode = this;
     72    if (!m_head)
     73        m_head = this;
    7374
    7475    startTimer();
     
    8485    }
    8586
    86     m_children.append(ProfileNode::create(callIdentifier, m_headNode, this));
     87    RefPtr<ProfileNode> newChild = ProfileNode::create(callIdentifier, m_head, this);
     88    if (m_children.size())
     89        m_children.last()->setNextSibling(newChild.get());
     90    m_children.append(newChild.release());
    8791    return m_children.last().get();
    8892}
     
    9195{
    9296    endAndRecordCall();
    93     return m_parentNode;
     97    return m_parent;
    9498}
    9599
     
    98102    RefPtr<ProfileNode> child = prpChild;
    99103    child->setParent(this);
     104    if (m_children.size())
     105        m_children.last()->setNextSibling(child.get());
    100106    m_children.append(child.release());
    101107}
     
    131137    m_actualSelfTime = m_actualTotalTime - m_actualSelfTime;
    132138
    133     if (m_headNode == this && m_actualSelfTime) {
     139    if (m_head == this && m_actualSelfTime) {
    134140        ProfileNode* idleNode = willExecute(CallIdentifier(NonJSExecution, 0, 0));
    135141
     
    155161    std::sort(m_children.begin(), m_children.end(), totalTimeDescendingComparator);
    156162
    157     for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild)
    158         (*currentChild)->sortTotalTimeDescending();
     163    unsigned size = m_children.size();
     164    for (unsigned i = 0; i < size; ++i)
     165        m_children[i]->sortTotalTimeDescending();
     166   
     167    resetChildrensSiblings();
    159168}
    160169
     
    168177    std::sort(m_children.begin(), m_children.end(), totalTimeAscendingComparator);
    169178
    170     for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild)
    171         (*currentChild)->sortTotalTimeAscending();
     179    unsigned size = m_children.size();
     180    for (unsigned i = 0; i < size; ++i)
     181        m_children[i]->sortTotalTimeAscending();
     182
     183    resetChildrensSiblings();
    172184}
    173185
     
    181193    std::sort(m_children.begin(), m_children.end(), selfTimeDescendingComparator);
    182194
    183     for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild)
    184         (*currentChild)->sortSelfTimeDescending();
     195    unsigned size = m_children.size();
     196    for (unsigned i = 0; i < size; ++i)
     197        m_children[i]->sortSelfTimeDescending();
     198
     199    resetChildrensSiblings();
    185200}
    186201
     
    194209    std::sort(m_children.begin(), m_children.end(), selfTimeAscendingComparator);
    195210
    196     for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild)
    197         (*currentChild)->sortSelfTimeAscending();
     211    unsigned size = m_children.size();
     212    for (unsigned i = 0; i < size; ++i)
     213        m_children[i]->sortSelfTimeAscending();
     214
     215    resetChildrensSiblings();
    198216}
    199217
     
    207225    std::sort(m_children.begin(), m_children.end(), callsDescendingComparator);
    208226
    209     for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild)
    210         (*currentChild)->sortCallsDescending();
     227    unsigned size = m_children.size();
     228    for (unsigned i = 0; i < size; ++i)
     229        m_children[i]->sortCallsDescending();
     230
     231    resetChildrensSiblings();
    211232}
    212233
     
    220241    std::sort(m_children.begin(), m_children.end(), callsAscendingComparator);
    221242
    222     for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild)
    223         (*currentChild)->sortCallsAscending();
     243    unsigned size = m_children.size();
     244    for (unsigned i = 0; i < size; ++i)
     245        m_children[i]->sortCallsAscending();
     246
     247    resetChildrensSiblings();
    224248}
    225249
     
    233257    std::sort(m_children.begin(), m_children.end(), functionNameDescendingComparator);
    234258
    235     for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild)
    236         (*currentChild)->sortFunctionNameDescending();
     259    unsigned size = m_children.size();
     260    for (unsigned i = 0; i < size; ++i)
     261        m_children[i]->sortFunctionNameDescending();
     262
     263    resetChildrensSiblings();
    237264}
    238265
     
    246273    std::sort(m_children.begin(), m_children.end(), functionNameAscendingComparator);
    247274
    248     for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild)
    249         (*currentChild)->sortFunctionNameAscending();
     275    unsigned size = m_children.size();
     276    for (unsigned i = 0; i < size; ++i)
     277        m_children[i]->sortFunctionNameAscending();
     278
     279    resetChildrensSiblings();
    250280}
    251281
     
    321351}
    322352
     353void ProfileNode::resetChildrensSiblings()
     354{
     355    unsigned size = m_children.size();
     356    for (unsigned i = 0; i < size; ++i)
     357        m_children[i]->setNextSibling(i + 1 == size ? 0 : m_children[i + 1].get());
     358}
     359
    323360#ifndef NDEBUG
    324361void ProfileNode::debugPrintData(int indentLevel) const
     
    328365        printf("  ");
    329366
    330     printf("%d SelfTime %.3fms/%.3f%% TotalTime %.3fms/%.3f%% VSelf %.3fms VTotal %.3fms Function Name %s Visible %s\n",
     367    printf("%d SelfTime %.3fms/%.3f%% TotalTime %.3fms/%.3f%% VSelf %.3fms VTotal %.3fms Function Name %s Visible %s Next Sibling %s\n",
    331368        m_numberOfCalls, m_actualSelfTime, selfPercent(), m_actualTotalTime, totalPercent(),
    332369        m_visibleSelfTime, m_visibleTotalTime,
    333         functionName().UTF8String().c_str(), (m_visible ? "True" : "False"));
     370        functionName().UTF8String().c_str(), (m_visible ? "True" : "False"),
     371        m_nextSibling ? m_nextSibling->functionName().UTF8String().c_str() : "");
    334372
    335373    ++indentLevel;
Note: See TracChangeset for help on using the changeset viewer.