Changeset 173199 in webkit for trunk/Source/JavaScriptCore/profiler/ProfileNode.h
- Timestamp:
- Sep 2, 2014, 9:58:55 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/profiler/ProfileNode.h
r165676 r173199 45 45 class ProfileNode : public RefCounted<ProfileNode> { 46 46 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) 48 48 { 49 return adoptRef(new ProfileNode(callerCallFrame, callIdentifier, headNode,parentNode));49 return adoptRef(new ProfileNode(callerCallFrame, callIdentifier, parentNode)); 50 50 } 51 51 52 static PassRefPtr<ProfileNode> create(ExecState* callerCallFrame, ProfileNode* headNode, ProfileNode*node)52 static PassRefPtr<ProfileNode> create(ExecState* callerCallFrame, ProfileNode* node) 53 53 { 54 return adoptRef(new ProfileNode(callerCallFrame, headNode,node));54 return adoptRef(new ProfileNode(callerCallFrame, node)); 55 55 } 56 56 … … 91 91 92 92 // Relationships 93 ProfileNode* head() const { return m_head; }94 void setHead(ProfileNode* head) { m_head = head; }95 96 93 ProfileNode* parent() const { return m_parent; } 97 94 void setParent(ProfileNode* parent) { m_parent = parent; } … … 100 97 void setNextSibling(ProfileNode* nextSibling) { m_nextSibling = nextSibling; } 101 98 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; } 113 100 Call& lastCall() { ASSERT(!m_calls.isEmpty()); return m_calls.last(); } 114 101 size_t numberOfCalls() const { return m_calls.size(); } … … 122 109 void insertNode(PassRefPtr<ProfileNode> prpNode); 123 110 124 ProfileNode* traverseNextNodePostOrder() const;111 template <typename Functor> void forEachNodePostorder(Functor&); 125 112 126 113 #ifndef NDEBUG 114 struct ProfileSubtreeData { 115 HashMap<ProfileNode*, std::pair<double, double>> selfAndTotalTimes; 116 double rootTotalTime; 117 }; 118 127 119 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&); 130 127 #endif 131 128 … … 133 130 typedef Vector<RefPtr<ProfileNode>>::const_iterator StackIterator; 134 131 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); 137 134 138 135 void startTimer(); 139 136 void resetChildrensSiblings(); 140 137 void endAndRecordCall(); 138 ProfileNode* traverseNextNodePostOrder() const; 141 139 142 140 ExecState* m_callerCallFrame; 143 141 CallIdentifier m_callIdentifier; 144 ProfileNode* m_head;145 142 ProfileNode* m_parent; 146 143 ProfileNode* m_nextSibling; 147 144 148 double m_totalTime; 149 double m_selfTime; 150 151 Vector<Call, 1> m_calls; 145 Vector<Call> m_calls; 152 146 Vector<RefPtr<ProfileNode>> m_children; 153 147 }; 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 154 189 155 190 } // namespace JSC
Note:
See TracChangeset
for help on using the changeset viewer.