Ignore:
Timestamp:
Sep 2, 2014, 9:58:55 PM (11 years ago)
Author:
Brian Burg
Message:

LegacyProfiler: remove redundant ProfileNode members and other cleanup
https://bugs.webkit.org/show_bug.cgi?id=136380

Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

ProfileNode's selfTime and totalTime members are redundant and only used
for dumping profile data from debug-only code. Remove the members and compute
the same data on-demand when necessary using a postorder traversal functor.

Remove ProfileNode.head since it is only used to calculate percentages for
dumped profile data. This can be explicitly passed around when needed.

Rename Profile.head to Profile.rootNode, and other various renamings.

Rearrange some header includes so that touching LegacyProfiler-related headers
will no longer cause a full rebuild.

  • inspector/JSConsoleClient.cpp: Add header include.
  • inspector/agents/InspectorProfilerAgent.cpp:

(Inspector::InspectorProfilerAgent::buildProfileInspectorObject):

  • inspector/protocol/Profiler.json: Remove unused Profile.idleTime member.
  • jit/JIT.h: Remove header include.
  • jit/JITCode.h: Remove header include.
  • jit/JITOperations.cpp: Sort and add header include.
  • llint/LLIntSlowPaths.cpp: Sort and add header include.
  • profiler/Profile.cpp: Rename the debug dumping functions. Move the node

postorder traversal code to ProfileNode so we can traverse any subtree.
(JSC::Profile::Profile):
(JSC::Profile::debugPrint):
(JSC::Profile::debugPrintSampleStyle):
(JSC::Profile::forEach): Deleted.
(JSC::Profile::debugPrintData): Deleted.
(JSC::Profile::debugPrintDataSampleStyle): Deleted.

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

(JSC::ProfileGenerator::ProfileGenerator):
(JSC::AddParentForConsoleStartFunctor::AddParentForConsoleStartFunctor):
(JSC::AddParentForConsoleStartFunctor::operator()):
(JSC::ProfileGenerator::addParentForConsoleStart):
(JSC::ProfileGenerator::didExecute):
(JSC::StopProfilingFunctor::operator()):
(JSC::ProfileGenerator::stopProfiling):
(JSC::ProfileGenerator::removeProfileStart):
(JSC::ProfileGenerator::removeProfileEnd):

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

(JSC::ProfileNode::ProfileNode):
(JSC::ProfileNode::willExecute):
(JSC::ProfileNode::removeChild):
(JSC::ProfileNode::stopProfiling):
(JSC::ProfileNode::endAndRecordCall):
(JSC::ProfileNode::debugPrint):
(JSC::ProfileNode::debugPrintSampleStyle):
(JSC::ProfileNode::debugPrintRecursively):
(JSC::ProfileNode::debugPrintSampleStyleRecursively):
(JSC::ProfileNode::debugPrintData): Deleted.
(JSC::ProfileNode::debugPrintDataSampleStyle): Deleted.

  • profiler/ProfileNode.h: Calculate per-node self and total times using a postorder traversal.

The forEachNodePostorder functor traverses the subtree rooted at |this|.
(JSC::ProfileNode::create):
(JSC::ProfileNode::calls):
(JSC::ProfileNode::forEachNodePostorder):
(JSC::CalculateProfileSubtreeDataFunctor::returnValue):
(JSC::CalculateProfileSubtreeDataFunctor::operator()):
(JSC::ProfileNode::head): Deleted.
(JSC::ProfileNode::setHead): Deleted.
(JSC::ProfileNode::totalTime): Deleted.
(JSC::ProfileNode::setTotalTime): Deleted.
(JSC::ProfileNode::selfTime): Deleted.
(JSC::ProfileNode::setSelfTime): Deleted.
(JSC::ProfileNode::totalPercent): Deleted.
(JSC::ProfileNode::selfPercent): Deleted.

  • runtime/ConsoleClient.h: Remove header include.

Source/WebCore:

Remove Profile.idleTime, rename head to rootNode, and remove ProfileNode members.

Covered by existing tests.

  • inspector/ScriptProfile.idl:
  • inspector/ScriptProfileNode.idl:
  • inspector/TimelineRecordFactory.cpp:

Source/WebInspectorUI:

Remove unused Profile.idleTime member.

  • UserInterface/Models/Profile.js:

(WebInspector.Profile.prototype.get idleTime): Deleted.

  • UserInterface/Models/ScriptTimelineRecord.js:

(WebInspector.ScriptTimelineRecord.prototype._initializeProfileFromPayload):

LayoutTests:

Renamed Profile.head to Profile.rootNode.

  • fast/profiler/resources/profiler-test-JS-resources.js:

(printHeavyProfilesDataWithoutTime):
(printProfilesDataWithoutTime):

File:
1 edited

Legend:

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

    r165676 r173199  
    4545    class ProfileNode : public RefCounted<ProfileNode> {
    4646    public:
    47         static PassRefPtr<ProfileNode> create(ExecState* callerCallFrame, const CallIdentifier& callIdentifier, ProfileNode* headNode, ProfileNode* parentNode)
     47        static PassRefPtr<ProfileNode> create(ExecState* callerCallFrame, const CallIdentifier& callIdentifier, ProfileNode* parentNode)
    4848        {
    49             return adoptRef(new ProfileNode(callerCallFrame, callIdentifier, headNode, parentNode));
     49            return adoptRef(new ProfileNode(callerCallFrame, callIdentifier, parentNode));
    5050        }
    5151
    52         static PassRefPtr<ProfileNode> create(ExecState* callerCallFrame, ProfileNode* headNode, ProfileNode* node)
     52        static PassRefPtr<ProfileNode> create(ExecState* callerCallFrame, ProfileNode* node)
    5353        {
    54             return adoptRef(new ProfileNode(callerCallFrame, headNode, node));
     54            return adoptRef(new ProfileNode(callerCallFrame, node));
    5555        }
    5656
     
    9191
    9292        // Relationships
    93         ProfileNode* head() const { return m_head; }
    94         void setHead(ProfileNode* head) { m_head = head; }
    95 
    9693        ProfileNode* parent() const { return m_parent; }
    9794        void setParent(ProfileNode* parent) { m_parent = parent; }
     
    10097        void setNextSibling(ProfileNode* nextSibling) { m_nextSibling = nextSibling; }
    10198
    102         // Time members
    103         double totalTime() const { return m_totalTime; }
    104         void setTotalTime(double time) { m_totalTime = time; }
    105 
    106         double selfTime() const { return m_selfTime; }
    107         void setSelfTime(double time) { m_selfTime = time; }
    108 
    109         double totalPercent() const { return (m_totalTime / (m_head ? m_head->totalTime() : totalTime())) * 100.0; }
    110         double selfPercent() const { return (m_selfTime / (m_head ? m_head->totalTime() : totalTime())) * 100.0; }
    111 
    112         Vector<Call> calls() const { return m_calls; }
     99        const Vector<Call>& calls() const { return m_calls; }
    113100        Call& lastCall() { ASSERT(!m_calls.isEmpty()); return m_calls.last(); }
    114101        size_t numberOfCalls() const { return m_calls.size(); }
     
    122109        void insertNode(PassRefPtr<ProfileNode> prpNode);
    123110
    124         ProfileNode* traverseNextNodePostOrder() const;
     111        template <typename Functor> void forEachNodePostorder(Functor&);
    125112
    126113#ifndef NDEBUG
     114        struct ProfileSubtreeData {
     115            HashMap<ProfileNode*, std::pair<double, double>> selfAndTotalTimes;
     116            double rootTotalTime;
     117        };
     118
    127119        const char* c_str() const { return m_callIdentifier; }
    128         void debugPrintData(int indentLevel) const;
    129         double debugPrintDataSampleStyle(int indentLevel, FunctionCallHashCount&) const;
     120        // Use these functions to dump the subtree rooted at this node.
     121        void debugPrint();
     122        void debugPrintSampleStyle();
     123
     124        // These are used to recursively print entire subtrees using precomputed self and total times.
     125        void debugPrintRecursively(int indentLevel, const ProfileSubtreeData&);
     126        double debugPrintSampleStyleRecursively(int indentLevel, FunctionCallHashCount&, const ProfileSubtreeData&);
    130127#endif
    131128
     
    133130        typedef Vector<RefPtr<ProfileNode>>::const_iterator StackIterator;
    134131
    135         ProfileNode(ExecState* callerCallFrame, const CallIdentifier&, ProfileNode* headNode, ProfileNode* parentNode);
    136         ProfileNode(ExecState* callerCallFrame, ProfileNode* headNode, ProfileNode* nodeToCopy);
     132        ProfileNode(ExecState* callerCallFrame, const CallIdentifier&, ProfileNode* parentNode);
     133        ProfileNode(ExecState* callerCallFrame, ProfileNode* nodeToCopy);
    137134
    138135        void startTimer();
    139136        void resetChildrensSiblings();
    140137        void endAndRecordCall();
     138        ProfileNode* traverseNextNodePostOrder() const;
    141139
    142140        ExecState* m_callerCallFrame;
    143141        CallIdentifier m_callIdentifier;
    144         ProfileNode* m_head;
    145142        ProfileNode* m_parent;
    146143        ProfileNode* m_nextSibling;
    147144
    148         double m_totalTime;
    149         double m_selfTime;
    150 
    151         Vector<Call, 1> m_calls;
     145        Vector<Call> m_calls;
    152146        Vector<RefPtr<ProfileNode>> m_children;
    153147    };
     148
     149    template <typename Functor> inline void ProfileNode::forEachNodePostorder(Functor& functor)
     150    {
     151        ProfileNode* currentNode = this;
     152        // Go down to the first node of the traversal, and slowly walk back up.
     153        for (ProfileNode* nextNode = currentNode; nextNode; nextNode = nextNode->firstChild())
     154            currentNode = nextNode;
     155
     156        ProfileNode* endNode = this;
     157        while (currentNode && currentNode != endNode) {
     158            functor(currentNode);
     159            currentNode = currentNode->traverseNextNodePostOrder();
     160        }
     161
     162        functor(endNode);
     163    }
     164
     165#ifndef NDEBUG
     166    struct CalculateProfileSubtreeDataFunctor {
     167        void operator()(ProfileNode* node)
     168        {
     169            double selfTime = 0.0;
     170            for (const ProfileNode::Call& call : node->calls())
     171                selfTime += call.totalTime();
     172
     173            double totalTime = selfTime;
     174            for (RefPtr<ProfileNode> child : node->children()) {
     175                auto it = m_data.selfAndTotalTimes.find(child.get());
     176                if (it != m_data.selfAndTotalTimes.end())
     177                    totalTime += it->value.second;
     178            }
     179
     180            ASSERT(node);
     181            m_data.selfAndTotalTimes.set(node, std::make_pair(selfTime, totalTime));
     182        }
     183
     184        ProfileNode::ProfileSubtreeData returnValue() { return WTF::move(m_data); }
     185
     186        ProfileNode::ProfileSubtreeData m_data;
     187    };
     188#endif
    154189
    155190} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.