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.h

    r173199 r173262  
    6464
    6565            double startTime() const { return m_startTime; }
    66             void setStartTime(double time) { m_startTime = time; }
     66            void setStartTime(double time)
     67            {
     68                ASSERT_ARG(time, time >= 0.0);
     69                m_startTime = time;
     70            }
    6771
    6872            double totalTime() const { return m_totalTime; }
    69             void setTotalTime(double time) { m_totalTime = time; }
     73            void setTotalTime(double time)
     74            {
     75                ASSERT_ARG(time, time >= 0.0);
     76                m_totalTime = time;
     77            }
    7078
    7179        private:
     
    7684        bool operator==(ProfileNode* node) { return m_callIdentifier == node->callIdentifier(); }
    7785
    78         ProfileNode* willExecute(ExecState* callerCallFrame, const CallIdentifier&);
    79         ProfileNode* didExecute();
    80 
    81         void stopProfiling();
    82 
    83         // CallIdentifier members
    8486        ExecState* callerCallFrame() const { return m_callerCallFrame; }
    8587        const CallIdentifier& callIdentifier() const { return m_callIdentifier; }
     
    9092        unsigned columnNumber() const { return m_callIdentifier.columnNumber(); }
    9193
    92         // Relationships
    9394        ProfileNode* parent() const { return m_parent; }
    9495        void setParent(ProfileNode* parent) { m_parent = parent; }
    9596
    96         ProfileNode* nextSibling() const { return m_nextSibling; }
    97         void setNextSibling(ProfileNode* nextSibling) { m_nextSibling = nextSibling; }
    98 
    9997        const Vector<Call>& calls() const { return m_calls; }
    10098        Call& lastCall() { ASSERT(!m_calls.isEmpty()); return m_calls.last(); }
    101         size_t numberOfCalls() const { return m_calls.size(); }
     99        void appendCall(Call call) { m_calls.append(call); }
    102100
    103         // Children members
    104101        const Vector<RefPtr<ProfileNode>>& children() const { return m_children; }
    105         ProfileNode* firstChild() const { return m_children.size() ? m_children.first().get() : 0; }
    106         ProfileNode* lastChild() const { return m_children.size() ? m_children.last().get() : 0; }
     102        ProfileNode* firstChild() const { return m_children.size() ? m_children.first().get() : nullptr; }
     103        ProfileNode* lastChild() const { return m_children.size() ? m_children.last().get() : nullptr; }
     104
    107105        void removeChild(ProfileNode*);
    108         void addChild(PassRefPtr<ProfileNode> prpChild);
    109         void insertNode(PassRefPtr<ProfileNode> prpNode);
    110 
    111         template <typename Functor> void forEachNodePostorder(Functor&);
     106        void addChild(PassRefPtr<ProfileNode>);
     107        // Reparent our child nodes to the passed node, and make it a child node of |this|.
     108        void spliceNode(PassRefPtr<ProfileNode>);
    112109
    113110#ifndef NDEBUG
     
    117114        };
    118115
    119         const char* c_str() const { return m_callIdentifier; }
    120116        // Use these functions to dump the subtree rooted at this node.
    121117        void debugPrint();
     
    123119
    124120        // These are used to recursively print entire subtrees using precomputed self and total times.
     121        template <typename Functor> void forEachNodePostorder(Functor&);
     122
    125123        void debugPrintRecursively(int indentLevel, const ProfileSubtreeData&);
    126124        double debugPrintSampleStyleRecursively(int indentLevel, FunctionCallHashCount&, const ProfileSubtreeData&);
     
    133131        ProfileNode(ExecState* callerCallFrame, ProfileNode* nodeToCopy);
    134132
    135         void startTimer();
    136         void resetChildrensSiblings();
    137         void endAndRecordCall();
     133#ifndef NDEBUG
     134        ProfileNode* nextSibling() const { return m_nextSibling; }
     135        void setNextSibling(ProfileNode* nextSibling) { m_nextSibling = nextSibling; }
     136
    138137        ProfileNode* traverseNextNodePostOrder() const;
     138#endif
    139139
    140140        ExecState* m_callerCallFrame;
    141141        CallIdentifier m_callIdentifier;
    142142        ProfileNode* m_parent;
    143         ProfileNode* m_nextSibling;
    144 
    145143        Vector<Call> m_calls;
    146144        Vector<RefPtr<ProfileNode>> m_children;
     145
     146#ifndef NDEBUG
     147        ProfileNode* m_nextSibling;
     148#endif
    147149    };
    148150
     151#ifndef NDEBUG
    149152    template <typename Functor> inline void ProfileNode::forEachNodePostorder(Functor& functor)
    150153    {
     
    163166    }
    164167
    165 #ifndef NDEBUG
    166168    struct CalculateProfileSubtreeDataFunctor {
    167169        void operator()(ProfileNode* node)
Note: See TracChangeset for help on using the changeset viewer.