Changeset 36058 in webkit for trunk/JavaScriptCore/profiler/ProfileGenerator.cpp
- Timestamp:
- Sep 3, 2008, 10:35:42 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/profiler/ProfileGenerator.cpp
r35847 r36058 27 27 #include "ProfileGenerator.h" 28 28 29 #include "ExecState.h" 30 #include "JSGlobalObject.h" 31 #include "JSStringRef.h" 32 #include "JSFunction.h" 33 #include "Machine.h" 29 34 #include "Profile.h" 30 35 #include "Profiler.h" … … 35 40 static const char* NonJSExecution = "(idle)"; 36 41 37 PassRefPtr<ProfileGenerator> ProfileGenerator::create(const UString& title, ExecState* originating GlobalExec, unsigned profileGroup, ProfilerClient* client, unsigned uid)42 PassRefPtr<ProfileGenerator> ProfileGenerator::create(const UString& title, ExecState* originatingExec, ProfilerClient* client, unsigned uid) 38 43 { 39 return adoptRef(new ProfileGenerator(title, originating GlobalExec, profileGroup, client, uid));44 return adoptRef(new ProfileGenerator(title, originatingExec, client, uid)); 40 45 } 41 46 42 ProfileGenerator::ProfileGenerator(const UString& title, ExecState* originating GlobalExec, unsigned profileGroup, ProfilerClient* client, unsigned uid)43 : m_originatingGlobalExec(originating GlobalExec)44 , m_profileGroup( profileGroup)47 ProfileGenerator::ProfileGenerator(const UString& title, ExecState* originatingExec, ProfilerClient* client, unsigned uid) 48 : m_originatingGlobalExec(originatingExec->lexicalGlobalObject()->globalExec()) 49 , m_profileGroup(originatingExec->lexicalGlobalObject()->profileGroup()) 45 50 , m_client(client) 46 , m_stoppedProfiling(false)47 , m_stoppedCallDepth(0)48 51 { 49 52 m_profile = Profile::create(title, uid); 50 53 m_currentNode = m_head = m_profile->head(); 54 55 addParentForConsoleStart(originatingExec); 56 } 57 58 void ProfileGenerator::addParentForConsoleStart(ExecState* exec) 59 { 60 int lineNumber; 61 int sourceID; 62 UString sourceURL; 63 JSValue* function; 64 65 exec->machine()->retrieveLastCaller(exec, lineNumber, sourceID, sourceURL, function); 66 m_currentNode = ProfileNode::create(Profiler::createCallIdentifier(exec, function ? function->toThisObject(exec) : 0, sourceURL, lineNumber), m_head.get(), m_head.get()); 67 m_head->insertNode(m_currentNode.get()); 51 68 } 52 69 … … 64 81 } 65 82 66 if (m_stoppedProfiling) { 67 ++m_stoppedCallDepth; 68 return; 69 } 70 71 ASSERT(m_currentNode); 83 ASSERT_ARG(m_currentNode, m_currentNode); 72 84 m_currentNode = m_currentNode->willExecute(callIdentifier); 73 85 } … … 81 93 } 82 94 83 if (!m_currentNode) 84 return; 85 86 if (m_stoppedProfiling && m_stoppedCallDepth > 0) { 87 --m_stoppedCallDepth; 95 ASSERT_ARG(m_currentNode, m_currentNode); 96 if (m_currentNode->callIdentifier() != callIdentifier) { 97 RefPtr<ProfileNode> returningNode = ProfileNode::create(callIdentifier, m_head.get(), m_currentNode.get()); 98 returningNode->setStartTime(m_currentNode->startTime()); 99 returningNode->didExecute(); 100 m_currentNode->insertNode(returningNode.release()); 88 101 return; 89 102 } 90 103 91 if (m_currentNode == m_head) { 92 m_currentNode = ProfileNode::create(callIdentifier, m_head.get(), m_head.get()); 93 m_currentNode->setStartTime(m_head->startTime()); 94 m_currentNode->didExecute(); 95 96 if (m_stoppedProfiling) { 97 m_currentNode->setTotalTime(m_head->totalTime()); 98 m_currentNode->setSelfTime(m_head->selfTime()); 99 m_head->setSelfTime(0.0); 100 } 101 102 m_head->insertNode(m_currentNode.release()); 103 m_currentNode = m_stoppedProfiling ? 0 : m_head; 104 105 return; 106 } 107 108 // Set m_currentNode to the parent (which didExecute returns). If stopped, just set the 109 // m_currentNode to the parent and don't call didExecute. 110 m_currentNode = m_stoppedProfiling ? m_currentNode->parent() : m_currentNode->didExecute(); 104 m_currentNode = m_currentNode->didExecute(); 111 105 } 112 106 … … 118 112 removeProfileEnd(); 119 113 120 ASSERT (m_currentNode);114 ASSERT_ARG(m_currentNode, m_currentNode); 121 115 122 116 // Set the current node to the parent, because we are in a call that … … 124 118 m_currentNode = m_currentNode->parent(); 125 119 126 m_stoppedProfiling = true; 127 } 128 129 bool ProfileGenerator::didFinishAllExecution() 130 { 131 if (!m_stoppedProfiling) 132 return false; 133 134 if (double headSelfTime = m_head->selfTime()) { 120 if (double headSelfTime = m_head->selfTime()) { 135 121 RefPtr<ProfileNode> idleNode = ProfileNode::create(CallIdentifier(NonJSExecution, 0, 0), m_head.get(), m_head.get()); 136 122 … … 142 128 m_head->addChild(idleNode.release()); 143 129 } 144 145 m_currentNode = 0;146 m_originatingGlobalExec = 0;147 148 m_profile->setHead(m_head.release());149 return true;150 130 } 151 131 … … 160 140 return; 161 141 162 // Increment m_stoppedCallDepth to account for didExecute not being called for console.ProfileGenerator.163 ++m_stoppedCallDepth;164 165 142 // Attribute the time of the node aobut to be removed to the self time of its parent 166 143 currentNode->parent()->setSelfTime(currentNode->parent()->selfTime() + currentNode->totalTime()); 167 168 ASSERT(currentNode->callIdentifier() == (currentNode->parent()->children()[0])->callIdentifier()); 169 currentNode->parent()->removeChild(0); 144 currentNode->parent()->removeChild(currentNode); 170 145 } 171 146 … … 184 159 185 160 ASSERT(currentNode->callIdentifier() == (currentNode->parent()->children()[currentNode->parent()->children().size() - 1])->callIdentifier()); 186 currentNode->parent()->removeChild(currentNode ->parent()->children().size() - 1);161 currentNode->parent()->removeChild(currentNode); 187 162 } 188 163
Note:
See TracChangeset
for help on using the changeset viewer.