Changeset 33007 in webkit for trunk/JavaScriptCore/profiler/Profiler.cpp
- Timestamp:
- May 9, 2008, 1:18:08 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/profiler/Profiler.cpp
r32760 r33007 30 30 #include "Profiler.h" 31 31 32 #include "ExecState.h" 33 #include "function.h" 32 34 #include "FunctionCallProfile.h" 33 35 #include "JSGlobalObject.h" 34 #include "ExecState.h" 35 #include "function.h" 36 #include "Profile.h" 36 37 37 38 #include <stdio.h> … … 54 55 } 55 56 56 void Profiler::startProfiling(unsigned pageGroupIdentifier )57 void Profiler::startProfiling(unsigned pageGroupIdentifier, const UString& title) 57 58 { 58 59 if (m_profiling) … … 61 62 m_pageGroupIdentifier = pageGroupIdentifier; 62 63 63 // FIXME: When multi-threading is supported this will be a vector and calls 64 // into the profiler will need to know which thread it is executing on. 65 m_callTree.set(new FunctionCallProfile("Thread_1")); 64 m_currentProfile.set(new Profile(title)); 66 65 m_profiling = true; 67 66 } … … 70 69 { 71 70 m_profiling = false; 72 m_callTree->stopProfiling(); 71 72 if (!m_currentProfile) 73 return; 74 75 m_currentProfile->stopProfiling(); 76 m_allProfiles.append(m_currentProfile.release()); 73 77 } 74 78 … … 80 84 Vector<UString> callStackNames; 81 85 getStackNames(callStackNames, exec, calledFunction); 82 insertStackNamesInTree(callStackNames);86 m_currentProfile->willExecute(callStackNames); 83 87 } 84 88 … … 90 94 Vector<UString> callStackNames; 91 95 getStackNames(callStackNames, exec, sourceURL, startingLineNumber); 92 insertStackNamesInTree(callStackNames);96 m_currentProfile->willExecute(callStackNames); 93 97 } 94 98 … … 100 104 Vector<UString> callStackNames; 101 105 getStackNames(callStackNames, exec, calledFunction); 102 m_c allTree->didExecute(callStackNames, 0);106 m_currentProfile->didExecute(callStackNames); 103 107 } 104 108 … … 110 114 Vector<UString> callStackNames; 111 115 getStackNames(callStackNames, exec, sourceURL, startingLineNumber); 112 m_callTree->didExecute(callStackNames, 0); 113 } 114 115 void Profiler::insertStackNamesInTree(const Vector<UString>& callStackNames) 116 { 117 FunctionCallProfile* callTreeInsertionPoint = 0; 118 FunctionCallProfile* foundNameInTree = m_callTree.get(); 119 NameIterator callStackLocation = callStackNames.begin(); 120 121 while (callStackLocation != callStackNames.end() && foundNameInTree) { 122 callTreeInsertionPoint = foundNameInTree; 123 foundNameInTree = callTreeInsertionPoint->findChild(*callStackLocation); 124 ++callStackLocation; 125 } 126 127 if (!foundNameInTree) { // Insert remains of the stack into the call tree. 128 --callStackLocation; 129 for (FunctionCallProfile* next; callStackLocation != callStackNames.end(); ++callStackLocation) { 130 next = new FunctionCallProfile(*callStackLocation); 131 callTreeInsertionPoint->addChild(next); 132 callTreeInsertionPoint = next; 133 } 134 } else // We are calling a function that is already in the call tree. 135 foundNameInTree->willExecute(); 116 m_currentProfile->didExecute(callStackNames); 136 117 } 137 118 … … 172 153 } 173 154 174 void Profiler::printDataInspectorStyle( ) const155 void Profiler::printDataInspectorStyle(unsigned whichProfile) const 175 156 { 176 printf("Profiler Call graph:\n"); 177 m_callTree->printDataInspectorStyle(0); 157 m_allProfiles[whichProfile]->printDataInspectorStyle(); 178 158 } 179 159 180 typedef pair<UString::Rep*, unsigned> NameCountPair; 181 182 static inline bool functionNameCountPairComparator(const NameCountPair a, const NameCountPair b) 160 void Profiler::printDataSampleStyle(unsigned whichProfile) const 183 161 { 184 return a.second > b.second; 185 } 186 187 void Profiler::printDataSampleStyle() const 188 { 189 typedef Vector<NameCountPair> NameCountPairVector; 190 191 FunctionCallHashCount countedFunctions; 192 printf("Call graph:\n"); 193 m_callTree->printDataSampleStyle(0, countedFunctions); 194 195 printf("\nTotal number in stack:\n"); 196 NameCountPairVector sortedFunctions(countedFunctions.size()); 197 copyToVector(countedFunctions, sortedFunctions); 198 199 std::sort(sortedFunctions.begin(), sortedFunctions.end(), functionNameCountPairComparator); 200 for (NameCountPairVector::iterator it = sortedFunctions.begin(); it != sortedFunctions.end(); ++it) 201 printf(" %-12d%s\n", (*it).second, UString((*it).first).UTF8String().c_str()); 202 203 printf("\nSort by top of stack, same collapsed (when >= 5):\n"); 162 m_allProfiles[whichProfile]->printDataSampleStyle(); 204 163 } 205 164
Note:
See TracChangeset
for help on using the changeset viewer.