Ignore:
Timestamp:
Sep 4, 2014, 10:00:22 AM (11 years ago)
Author:
Brian Burg
Message:

LegacyProfiler: ProfileNodes should be used more like structs
https://bugs.webkit.org/show_bug.cgi?id=136381

Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

Previously, both the profile generator and individual profile nodes
were collectively responsible for creating new Call entries and
maintaining data structure invariants. This complexity is unnecessary.

This patch centralizes profile data creation inside the profile generator.
The profile nodes manage nextSibling and parent pointers, but do not
collect the current time or create new Call entries themselves.

Since ProfileNode::nextSibling and its callers are only used within
debug printing code, it should be compiled out for release builds.

  • profiler/ProfileGenerator.cpp:

(JSC::ProfileGenerator::ProfileGenerator):
(JSC::AddParentForConsoleStartFunctor::operator()):
(JSC::ProfileGenerator::beginCallEntry): create a new Call entry.
(JSC::ProfileGenerator::endCallEntry): finish the last Call entry.
(JSC::ProfileGenerator::willExecute): inline ProfileNode::willExecute()
(JSC::ProfileGenerator::didExecute): inline ProfileNode::didExecute()
(JSC::ProfileGenerator::stopProfiling): Only walk up the spine.
(JSC::ProfileGenerator::removeProfileStart):
(JSC::ProfileGenerator::removeProfileEnd):

  • profiler/ProfileGenerator.h:
  • profiler/ProfileNode.cpp:

(JSC::ProfileNode::ProfileNode):
(JSC::ProfileNode::addChild):
(JSC::ProfileNode::removeChild):
(JSC::ProfileNode::spliceNode): Renamed from insertNode.
(JSC::ProfileNode::debugPrintRecursively):
(JSC::ProfileNode::willExecute): Deleted.
(JSC::ProfileNode::insertNode): Deleted.
(JSC::ProfileNode::stopProfiling): Deleted.
(JSC::ProfileNode::traverseNextNodePostOrder):
(JSC::ProfileNode::endAndRecordCall): Deleted.
(JSC::ProfileNode::debugPrintDataSampleStyle):

  • profiler/ProfileNode.h:

(JSC::ProfileNode::Call::setStartTime):
(JSC::ProfileNode::Call::setTotalTime):
(JSC::ProfileNode::appendCall):
(JSC::ProfileNode::firstChild):
(JSC::ProfileNode::lastChild):
(JSC::ProfileNode::nextSibling):
(JSC::ProfileNode::setNextSibling):

Source/WebCore:

  • inspector/ScriptProfileNode.idl: Remove an unused property.
File:
1 edited

Legend:

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

    r173199 r173262  
    4343    , m_callIdentifier(callIdentifier)
    4444    , m_parent(parentNode)
     45#ifndef NDEBUG
    4546    , m_nextSibling(nullptr)
    46 {
    47     startTimer();
     47#endif
     48{
    4849}
    4950
     
    5253    , m_callIdentifier(nodeToCopy->callIdentifier())
    5354    , m_parent(nodeToCopy->parent())
     55    , m_calls(nodeToCopy->calls())
     56#ifndef NDEBUG
    5457    , m_nextSibling(nullptr)
    55     , m_calls(nodeToCopy->calls())
    56 {
    57 }
    58 
    59 ProfileNode* ProfileNode::willExecute(ExecState* callerCallFrame, const CallIdentifier& callIdentifier)
    60 {
    61     for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild) {
    62         if ((*currentChild)->callIdentifier() == callIdentifier) {
    63             (*currentChild)->startTimer();
    64             return (*currentChild).get();
    65         }
    66     }
    67 
    68     RefPtr<ProfileNode> newChild = ProfileNode::create(callerCallFrame, callIdentifier, this);
    69     if (m_children.size())
    70         m_children.last()->setNextSibling(newChild.get());
    71     m_children.append(newChild.release());
    72     return m_children.last().get();
    73 }
    74 
    75 ProfileNode* ProfileNode::didExecute()
    76 {
    77     endAndRecordCall();
    78     return m_parent;
     58#endif
     59{
    7960}
    8061
     
    8364    RefPtr<ProfileNode> child = prpChild;
    8465    child->setParent(this);
     66#ifndef NDEBUG
    8567    if (m_children.size())
    8668        m_children.last()->setNextSibling(child.get());
     69#endif
    8770    m_children.append(child.release());
    8871}
     
    10083    }
    10184
    102     resetChildrensSiblings();
    103 }
    104 
    105 void ProfileNode::insertNode(PassRefPtr<ProfileNode> prpNode)
     85#ifndef NDEBUG
     86    size_t size = m_children.size();
     87    for (size_t i = 0; i < size; ++i)
     88        m_children[i]->setNextSibling(i + 1 == size ? nullptr : m_children[i + 1].get());
     89#endif
     90}
     91
     92void ProfileNode::spliceNode(PassRefPtr<ProfileNode> prpNode)
    10693{
    10794    RefPtr<ProfileNode> node = prpNode;
     
    114101}
    115102
    116 void ProfileNode::stopProfiling()
    117 {
    118     ASSERT(!m_calls.isEmpty());
    119 
    120     if (isnan(m_calls.last().totalTime()))
    121         endAndRecordCall();
    122 }
    123 
     103#ifndef NDEBUG
    124104ProfileNode* ProfileNode::traverseNextNodePostOrder() const
    125105{
     
    132112}
    133113
    134 void ProfileNode::endAndRecordCall()
    135 {
    136     Call& last = lastCall();
    137     ASSERT(isnan(last.totalTime()));
    138 
    139     last.setTotalTime(currentTime() - last.startTime());
    140 }
    141 
    142 void ProfileNode::startTimer()
    143 {
    144     m_calls.append(Call(currentTime()));
    145 }
    146 
    147 void ProfileNode::resetChildrensSiblings()
    148 {
    149     unsigned size = m_children.size();
    150     for (unsigned i = 0; i < size; ++i)
    151         m_children[i]->setNextSibling(i + 1 == size ? 0 : m_children[i + 1].get());
    152 }
    153 
    154 #ifndef NDEBUG
    155114void ProfileNode::debugPrint()
    156115{
     
    188147    dataLogF("Function Name %s %zu SelfTime %.3fms/%.3f%% TotalTime %.3fms/%.3f%% Next Sibling %s\n",
    189148        functionName().utf8().data(),
    190         numberOfCalls(), nodeSelfTime, nodeSelfTime / rootTotalTime * 100.0, nodeTotalTime, nodeTotalTime / rootTotalTime * 100.0,
     149        m_calls.size(), nodeSelfTime, nodeSelfTime / rootTotalTime * 100.0, nodeTotalTime, nodeTotalTime / rootTotalTime * 100.0,
    191150        m_nextSibling ? m_nextSibling->functionName().utf8().data() : "");
    192151
Note: See TracChangeset for help on using the changeset viewer.