Changeset 35039 in webkit for trunk/JavaScriptCore/profiler/Profile.cpp
- Timestamp:
- Jul 7, 2008, 11:12:09 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/profiler/Profile.cpp
r35037 r35039 27 27 #include "Profile.h" 28 28 29 #include "ExecState.h"30 #include "JSFunction.h"31 #include "JSGlobalObject.h"29 //#include "ExecState.h" 30 //#include "JSFunction.h" 31 //#include "JSGlobalObject.h" 32 32 #include "ProfileNode.h" 33 33 #include "TreeProfile.h" … … 36 36 namespace KJS { 37 37 38 static const char* NonJSExecution = "(idle)"; 39 40 PassRefPtr<Profile> Profile::create(const UString& title, ExecState* originatingGlobalExec, unsigned pageGroupIdentifier, ProfilerClient* client) 38 PassRefPtr<Profile> Profile::create(const UString& title) 41 39 { 42 return TreeProfile::create(title , originatingGlobalExec, pageGroupIdentifier, client);40 return TreeProfile::create(title); 43 41 } 44 42 45 Profile::Profile(const UString& title , ExecState* originatingGlobalExec, unsigned pageGroupIdentifier, ProfilerClient* client)43 Profile::Profile(const UString& title) 46 44 : m_title(title) 47 , m_originatingGlobalExec(originatingGlobalExec)48 , m_pageGroupIdentifier(pageGroupIdentifier)49 , m_stoppedCallDepth(0)50 , m_client(client)51 , m_stoppedProfiling(false)52 45 { 53 46 // FIXME: When multi-threading is supported this will be a vector and calls 54 47 // into the profiler will need to know which thread it is executing on. 55 48 m_head = ProfileNode::create(CallIdentifier("Thread_1", 0, 0), 0, 0); 56 m_currentNode = m_head;57 49 } 58 50 59 51 Profile::~Profile() 60 52 { 61 }62 63 void Profile::stopProfiling()64 {65 forEach(&ProfileNode::stopProfiling);66 removeProfileStart();67 removeProfileEnd();68 69 ASSERT(m_currentNode);70 71 // Set the current node to the parent, because we are in a call that72 // will not get didExecute call.73 m_currentNode = m_currentNode->parent();74 75 m_stoppedProfiling = true;76 }77 78 bool Profile::didFinishAllExecution()79 {80 if (!m_stoppedProfiling)81 return false;82 83 if (double headSelfTime = m_head->selfTime()) {84 RefPtr<ProfileNode> idleNode = ProfileNode::create(CallIdentifier(NonJSExecution, 0, 0), m_head.get(), m_head.get());85 86 idleNode->setTotalTime(headSelfTime);87 idleNode->setSelfTime(headSelfTime);88 idleNode->setVisible(true);89 90 m_head->setSelfTime(0.0);91 m_head->addChild(idleNode.release());92 }93 94 m_currentNode = 0;95 m_originatingGlobalExec = 0;96 return true;97 }98 99 // The console.profile that started this profile will be the first child.100 void Profile::removeProfileStart()101 {102 ProfileNode* currentNode = 0;103 for (ProfileNode* next = m_head.get(); next; next = next->firstChild())104 currentNode = next;105 106 if (currentNode->callIdentifier().m_name != "profile")107 return;108 109 // Increment m_stoppedCallDepth to account for didExecute not being called for console.profile.110 ++m_stoppedCallDepth;111 112 // Attribute the time of the node aobut to be removed to the self time of its parent113 currentNode->parent()->setSelfTime(currentNode->parent()->selfTime() + currentNode->totalTime());114 115 ASSERT(currentNode->callIdentifier() == (currentNode->parent()->children()[0])->callIdentifier());116 currentNode->parent()->removeChild(0);117 }118 119 // The console.profileEnd that stopped this profile will be the last child.120 void Profile::removeProfileEnd()121 {122 ProfileNode* currentNode = 0;123 for (ProfileNode* next = m_head.get(); next; next = next->lastChild())124 currentNode = next;125 126 if (currentNode->callIdentifier().m_name != "profileEnd")127 return;128 129 // Attribute the time of the node aobut to be removed to the self time of its parent130 currentNode->parent()->setSelfTime(currentNode->parent()->selfTime() + currentNode->totalTime());131 132 ASSERT(currentNode->callIdentifier() == (currentNode->parent()->children()[currentNode->parent()->children().size() - 1])->callIdentifier());133 currentNode->parent()->removeChild(currentNode->parent()->children().size() - 1);134 }135 136 void Profile::willExecute(const CallIdentifier& callIdentifier)137 {138 if (m_stoppedProfiling) {139 ++m_stoppedCallDepth;140 return;141 }142 143 ASSERT(m_currentNode);144 m_currentNode = m_currentNode->willExecute(callIdentifier);145 }146 147 void Profile::didExecute(const CallIdentifier& callIdentifier)148 {149 if (!m_currentNode)150 return;151 152 if (m_stoppedProfiling && m_stoppedCallDepth > 0) {153 --m_stoppedCallDepth;154 return;155 }156 157 if (m_currentNode == m_head) {158 m_currentNode = ProfileNode::create(callIdentifier, m_head.get(), m_head.get());159 m_currentNode->setStartTime(m_head->startTime());160 m_currentNode->didExecute();161 162 if (m_stoppedProfiling) {163 m_currentNode->setTotalTime(m_head->totalTime());164 m_currentNode->setSelfTime(m_head->selfTime());165 m_head->setSelfTime(0.0);166 }167 168 m_head->insertNode(m_currentNode.release());169 m_currentNode = m_stoppedProfiling ? 0 : m_head;170 171 return;172 }173 174 // Set m_currentNode to the parent (which didExecute returns). If stopped, just set the175 // m_currentNode to the parent and don't call didExecute.176 m_currentNode = m_stoppedProfiling ? m_currentNode->parent() : m_currentNode->didExecute();177 53 } 178 54
Note:
See TracChangeset
for help on using the changeset viewer.