Changeset 34362 in webkit for trunk/JavaScriptCore
- Timestamp:
- Jun 4, 2008, 11:53:10 AM (17 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r34361 r34362 1 2008-06-04 Kevin McCullough <[email protected]> 2 3 Reviewed by Geoff. 4 5 <rdar://problem/5969992> JSProfiler: Remove the recursion limit in the 6 profiler. 7 - This patch removes the use of recursion for the sort functions. 8 9 * JavaScriptCore.exp: Change the signatures of the functions being 10 exported. 11 * profiler/Profile.cpp: 12 (KJS::Profile::sort): This generic function will accept any of the 13 static sort functions and apply them to the whole tree. 14 * profiler/Profile.h: All of the sorting functions now call the new 15 sort() function. 16 (KJS::Profile::sortTotalTimeDescending): 17 (KJS::Profile::sortTotalTimeAscending): 18 (KJS::Profile::sortSelfTimeDescending): 19 (KJS::Profile::sortSelfTimeAscending): 20 (KJS::Profile::sortCallsDescending): 21 (KJS::Profile::sortCallsAscending): 22 (KJS::Profile::sortFunctionNameDescending): 23 (KJS::Profile::sortFunctionNameAscending): 24 * profiler/ProfileNode.cpp: 25 (KJS::ProfileNode::ProfileNode): m_head used to point to the head node 26 if this was the head node. It now points to null to make iteration easy 27 (KJS::ProfileNode::willExecute): Now must check if m_head is null, this 28 check used to happend in the constructor. 29 (KJS::ProfileNode::stopProfiling): Again the check is slightly different 30 to determine if this is the head. 31 (KJS::ProfileNode::traverseNextNode): This function returns the next 32 node in post order. 33 (KJS::ProfileNode::sort): This generic function will sort according to 34 the comparator passed in, then reset the children pointers to macth the 35 new order. 36 * profiler/ProfileNode.h: The sorting function were removed from the 37 definition file and instead use the new generic sort() function 38 (KJS::ProfileNode::totalPercent): because the head can now be empty we 39 need to check here too for the head node. 40 (KJS::ProfileNode::selfPercent): Ditto 41 (KJS::ProfileNode::firstChild): This function is necessary for the 42 iterative algorithm in Profile.cpp. 43 (KJS::ProfileNode::sortTotalTimeDescending): 44 (KJS::ProfileNode::sortTotalTimeAscending): 45 (KJS::ProfileNode::sortSelfTimeDescending): 46 (KJS::ProfileNode::sortSelfTimeAscending): 47 (KJS::ProfileNode::sortCallsDescending): 48 (KJS::ProfileNode::sortCallsAscending): 49 (KJS::ProfileNode::sortFunctionNameDescending): 50 (KJS::ProfileNode::sortFunctionNameAscending): 51 (KJS::ProfileNode::childrenBegin): 52 (KJS::ProfileNode::childrenEnd): 53 (KJS::ProfileNode::totalTimeDescendingComparator): 54 (KJS::ProfileNode::totalTimeAscendingComparator): 55 (KJS::ProfileNode::selfTimeDescendingComparator): 56 (KJS::ProfileNode::selfTimeAscendingComparator): 57 (KJS::ProfileNode::callsDescendingComparator): 58 (KJS::ProfileNode::callsAscendingComparator): 59 (KJS::ProfileNode::functionNameDescendingComparator): 60 (KJS::ProfileNode::functionNameAscendingComparator): 61 1 62 2008-06-04 Alexey Proskuryakov <[email protected]> 2 63 -
trunk/JavaScriptCore/JavaScriptCore.exp
r34361 r34362 16 16 __ZN3KJS11JSImmediate8toObjectEPKNS_7JSValueEPNS_9ExecStateE 17 17 __ZN3KJS11JSImmediate8toStringEPKNS_7JSValueE 18 __ZN3KJS11ProfileNode10restoreAllEv 19 __ZN3KJS11ProfileNode18sortCallsAscendingEv 20 __ZN3KJS11ProfileNode19sortCallsDescendingEv 21 __ZN3KJS11ProfileNode21sortSelfTimeAscendingEv 22 __ZN3KJS11ProfileNode22sortSelfTimeDescendingEv 23 __ZN3KJS11ProfileNode22sortTotalTimeAscendingEv 24 __ZN3KJS11ProfileNode23sortTotalTimeDescendingEv 25 __ZN3KJS11ProfileNode25sortFunctionNameAscendingEv 26 __ZN3KJS11ProfileNode26sortFunctionNameDescendingEv 18 __ZN3KJS11ProfileNode4sortEPFbRKN3WTF6RefPtrIS0_EES5_E 27 19 __ZN3KJS11ProfileNode5focusERKNS_14CallIdentifierEb 28 20 __ZN3KJS11ProfileNode7excludeERKNS_14CallIdentifierE 21 __ZN3KJS11ProfileNode10restoreAllEv 29 22 __ZN3KJS11ProgramNode6createEPNS_14SourceElementsEPN3WTF6VectorISt4pairINS_10IdentifierEjELm16EEEPNS4_INS3_6RefPtrINS_12FuncDeclNodeEEELm16EEEbb 30 23 __ZN3KJS11PropertyMap11getLocationERKNS_10IdentifierE … … 96 89 __ZN3KJS7CStringD1Ev 97 90 __ZN3KJS7Machine13dumpCallFrameEPKNS_9CodeBlockEPNS_14ScopeChainNodeEPNS_12RegisterFileEPKNS_8RegisterE 91 __ZN3KJS7Profile4sortEPFvPNS_11ProfileNodeEE 98 92 __ZN3KJS7UString3Rep11computeHashEPKti 99 93 __ZN3KJS7UString3Rep4nullE … … 150 144 __ZN3KJS9ExecStateC1EPNS_14JSGlobalObjectEPNS_8JSObjectEPNS_14ScopeChainNodeE 151 145 __ZN3KJSeqERKNS_7UStringEPKc 146 __ZN3KJSgtERKNS_7UStringES2_ 147 __ZN3KJSltERKNS_7UStringES2_ 152 148 __ZN3WTF10fastCallocEmm 153 149 __ZN3WTF10fastMallocEm -
trunk/JavaScriptCore/profiler/Profile.cpp
r34092 r34362 87 87 } 88 88 89 void Profile::sort(SortFunction function) { 90 91 ProfileNode* currentNode = m_headNode->firstChild(); 92 for (ProfileNode* nextNode = currentNode; nextNode; nextNode = nextNode->firstChild()) 93 currentNode = nextNode; 94 95 ProfileNode* endNode = m_headNode->traverseNextNode(); 96 while (currentNode && currentNode != endNode) { 97 function(currentNode); 98 currentNode = currentNode->traverseNextNode(); 99 } 100 } 101 89 102 #ifndef NDEBUG 90 103 void Profile::debugPrintData() const -
trunk/JavaScriptCore/profiler/Profile.h
r34092 r34362 34 34 35 35 class ExecState; 36 typedef void (*SortFunction)(ProfileNode*); 36 37 37 38 class Profile : public RefCounted<Profile> { … … 51 52 unsigned pageGroupIdentifier() const { return m_pageGroupIdentifier; } 52 53 53 void sortTotalTimeDescending() { m_headNode->sortTotalTimeDescending(); } 54 void sortTotalTimeAscending() { m_headNode->sortTotalTimeAscending(); } 55 void sortSelfTimeDescending() { m_headNode->sortSelfTimeDescending(); } 56 void sortSelfTimeAscending() { m_headNode->sortSelfTimeAscending(); } 57 void sortCallsDescending() { m_headNode->sortCallsDescending(); } 58 void sortCallsAscending() { m_headNode->sortCallsAscending(); } 59 void sortFunctionNameDescending() { m_headNode->sortFunctionNameDescending(); } 60 void sortFunctionNameAscending() { m_headNode->sortFunctionNameAscending(); } 54 void sort(SortFunction); 55 void sortTotalTimeDescending() { sort(ProfileNode::sortTotalTimeDescending); } 56 void sortTotalTimeAscending() { sort(ProfileNode::sortTotalTimeAscending); } 57 void sortSelfTimeDescending() { sort(ProfileNode::sortSelfTimeDescending); } 58 void sortSelfTimeAscending() { sort(ProfileNode::sortSelfTimeAscending); } 59 void sortCallsDescending() { sort(ProfileNode::sortCallsDescending); } 60 void sortCallsAscending() { sort(ProfileNode::sortCallsAscending); } 61 void sortFunctionNameDescending() { sort(ProfileNode::sortFunctionNameDescending); } 62 void sortFunctionNameAscending() { sort(ProfileNode::sortFunctionNameAscending); } 61 63 62 64 void focus(const ProfileNode* profileNode) { if (!profileNode) return; m_headNode->focus(profileNode->callIdentifier()); } -
trunk/JavaScriptCore/profiler/ProfileNode.cpp
r34310 r34362 70 70 , m_visible(true) 71 71 { 72 if (!m_head)73 m_head = this;74 75 72 startTimer(); 76 73 } … … 85 82 } 86 83 87 RefPtr<ProfileNode> newChild = ProfileNode::create(callIdentifier, m_head , this);84 RefPtr<ProfileNode> newChild = ProfileNode::create(callIdentifier, m_head ? m_head : this, this); // If this ProfileNode has no head it is the head. 88 85 if (m_children.size()) 89 86 m_children.last()->setNextSibling(newChild.get()); … … 137 134 m_actualSelfTime = m_actualTotalTime - m_actualSelfTime; 138 135 139 if ( m_head == this&& m_actualSelfTime) {136 if (!m_head && m_actualSelfTime) { 140 137 ProfileNode* idleNode = willExecute(CallIdentifier(NonJSExecution, 0, 0)); 141 138 … … 150 147 } 151 148 152 // Sorting methods 153 154 static inline bool totalTimeDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) 155 { 156 return a->totalTime() > b->totalTime(); 157 } 158 159 void ProfileNode::sortTotalTimeDescending() 160 { 161 std::sort(m_children.begin(), m_children.end(), totalTimeDescendingComparator); 162 163 unsigned size = m_children.size(); 164 for (unsigned i = 0; i < size; ++i) 165 m_children[i]->sortTotalTimeDescending(); 166 167 resetChildrensSiblings(); 168 } 169 170 static inline bool totalTimeAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) 171 { 172 return a->totalTime() < b->totalTime(); 173 } 174 175 void ProfileNode::sortTotalTimeAscending() 176 { 177 std::sort(m_children.begin(), m_children.end(), totalTimeAscendingComparator); 178 179 unsigned size = m_children.size(); 180 for (unsigned i = 0; i < size; ++i) 181 m_children[i]->sortTotalTimeAscending(); 182 183 resetChildrensSiblings(); 184 } 185 186 static inline bool selfTimeDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) 187 { 188 return a->selfTime() > b->selfTime(); 189 } 190 191 void ProfileNode::sortSelfTimeDescending() 192 { 193 std::sort(m_children.begin(), m_children.end(), selfTimeDescendingComparator); 194 195 unsigned size = m_children.size(); 196 for (unsigned i = 0; i < size; ++i) 197 m_children[i]->sortSelfTimeDescending(); 198 199 resetChildrensSiblings(); 200 } 201 202 static inline bool selfTimeAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) 203 { 204 return a->selfTime() < b->selfTime(); 205 } 206 207 void ProfileNode::sortSelfTimeAscending() 208 { 209 std::sort(m_children.begin(), m_children.end(), selfTimeAscendingComparator); 210 211 unsigned size = m_children.size(); 212 for (unsigned i = 0; i < size; ++i) 213 m_children[i]->sortSelfTimeAscending(); 214 215 resetChildrensSiblings(); 216 } 217 218 static inline bool callsDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) 219 { 220 return a->numberOfCalls() > b->numberOfCalls(); 221 } 222 223 void ProfileNode::sortCallsDescending() 224 { 225 std::sort(m_children.begin(), m_children.end(), callsDescendingComparator); 226 227 unsigned size = m_children.size(); 228 for (unsigned i = 0; i < size; ++i) 229 m_children[i]->sortCallsDescending(); 230 231 resetChildrensSiblings(); 232 } 233 234 static inline bool callsAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) 235 { 236 return a->numberOfCalls() < b->numberOfCalls(); 237 } 238 239 void ProfileNode::sortCallsAscending() 240 { 241 std::sort(m_children.begin(), m_children.end(), callsAscendingComparator); 242 243 unsigned size = m_children.size(); 244 for (unsigned i = 0; i < size; ++i) 245 m_children[i]->sortCallsAscending(); 246 247 resetChildrensSiblings(); 248 } 249 250 static inline bool functionNameDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) 251 { 252 return a->functionName() > b->functionName(); 253 } 254 255 void ProfileNode::sortFunctionNameDescending() 256 { 257 std::sort(m_children.begin(), m_children.end(), functionNameDescendingComparator); 258 259 unsigned size = m_children.size(); 260 for (unsigned i = 0; i < size; ++i) 261 m_children[i]->sortFunctionNameDescending(); 262 263 resetChildrensSiblings(); 264 } 265 266 static inline bool functionNameAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) 267 { 268 return a->functionName() < b->functionName(); 269 } 270 271 void ProfileNode::sortFunctionNameAscending() 272 { 273 std::sort(m_children.begin(), m_children.end(), functionNameAscendingComparator); 274 275 unsigned size = m_children.size(); 276 for (unsigned i = 0; i < size; ++i) 277 m_children[i]->sortFunctionNameAscending(); 278 149 ProfileNode* ProfileNode::traverseNextNode() const 150 { 151 ProfileNode* next = m_nextSibling; 152 if (!next) 153 return m_parent; 154 while (ProfileNode* firstChild = next->firstChild()) 155 next = firstChild; 156 return next; 157 } 158 159 void ProfileNode::sort(bool comparator(const RefPtr<ProfileNode>& , const RefPtr<ProfileNode>& )) 160 { 161 std::sort(childrenBegin(), childrenEnd(), comparator); 279 162 resetChildrensSiblings(); 280 163 } -
trunk/JavaScriptCore/profiler/ProfileNode.h
r34361 r34362 81 81 double selfTime() const { return m_visibleSelfTime; } 82 82 void setSelfTime(double time) { m_actualSelfTime = time; m_visibleSelfTime = time; } 83 double totalPercent() const { return (m_visibleTotalTime / m_head->totalTime()) * 100.0; }84 double selfPercent() const { return (m_visibleSelfTime / m_head->totalTime()) * 100.0; }83 double totalPercent() const { return (m_visibleTotalTime / (m_head ? m_head->totalTime() : totalTime())) * 100.0; } 84 double selfPercent() const { return (m_visibleSelfTime / (m_head ? m_head->totalTime() : totalTime())) * 100.0; } 85 85 unsigned numberOfCalls() const { return m_numberOfCalls; } 86 86 void setNumberOfCalls(unsigned number) { m_numberOfCalls = number; } 87 87 const Vector<RefPtr<ProfileNode> >& children() const { return m_children; } 88 ProfileNode* firstChild() const { return m_children.size() ? m_children[0].get() : 0; } 88 89 void addChild(PassRefPtr<ProfileNode> prpChild); 89 90 void insertNode(PassRefPtr<ProfileNode> prpNode); … … 93 94 void setTreeVisible(bool visible); 94 95 95 // Sorting functions 96 void sortTotalTimeDescending(); 97 void sortTotalTimeAscending(); 98 void sortSelfTimeDescending(); 99 void sortSelfTimeAscending(); 100 void sortCallsDescending(); 101 void sortCallsAscending(); 102 void sortFunctionNameDescending(); 103 void sortFunctionNameAscending(); 96 ProfileNode* traverseNextNode() const; 97 void sort(bool (*)(const RefPtr<ProfileNode>&, const RefPtr<ProfileNode>&)); 98 static void sortTotalTimeDescending(ProfileNode* n) { n->sort(totalTimeDescendingComparator); } 99 static void sortTotalTimeAscending(ProfileNode* n) { n->sort(totalTimeAscendingComparator); } 100 static void sortSelfTimeDescending(ProfileNode* n) { n->sort(selfTimeDescendingComparator); } 101 static void sortSelfTimeAscending(ProfileNode* n) { n->sort(selfTimeAscendingComparator); } 102 static void sortCallsDescending(ProfileNode* n) { n->sort(callsDescendingComparator); } 103 static void sortCallsAscending(ProfileNode* n) { n->sort(callsAscendingComparator); } 104 static void sortFunctionNameDescending(ProfileNode* n) { n->sort(functionNameDescendingComparator); } 105 static void sortFunctionNameAscending(ProfileNode* n) { n->sort(functionNameAscendingComparator); } 104 106 105 107 void focus(const CallIdentifier&, bool forceVisible = false); … … 118 120 void startTimer(); 119 121 void resetChildrensSiblings(); 122 RefPtr<ProfileNode>* childrenBegin() { return m_children.begin(); } 123 RefPtr<ProfileNode>* childrenEnd() { return m_children.end(); } 124 125 // Sorting comparators 126 static inline bool totalTimeDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) { return a->totalTime() > b->totalTime(); } 127 static inline bool totalTimeAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) { return a->totalTime() < b->totalTime(); } 128 static inline bool selfTimeDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) { return a->selfTime() > b->selfTime(); } 129 static inline bool selfTimeAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) { return a->selfTime() < b->selfTime(); } 130 static inline bool callsDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) { return a->numberOfCalls() > b->numberOfCalls(); } 131 static inline bool callsAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) { return a->numberOfCalls() < b->numberOfCalls(); } 132 static inline bool functionNameDescendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) { return a->functionName() > b->functionName(); } 133 static inline bool functionNameAscendingComparator(const RefPtr<ProfileNode>& a, const RefPtr<ProfileNode>& b) { return a->functionName() < b->functionName(); } 120 134 121 135 CallIdentifier m_callIdentifier;
Note:
See TracChangeset
for help on using the changeset viewer.