Changeset 174322 in webkit for trunk/Source/JavaScriptCore/profiler
- Timestamp:
- Oct 4, 2014, 2:55:58 PM (11 years ago)
- Location:
- trunk/Source/JavaScriptCore/profiler
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/profiler/LegacyProfiler.cpp
r174319 r174322 33 33 #include "CodeBlock.h" 34 34 #include "CommonIdentifiers.h" 35 #include "DebuggerCallFrame.h" 35 36 #include "InternalFunction.h" 36 37 #include "JSFunction.h" … … 50 51 static CallIdentifier createCallIdentifierFromFunctionImp(ExecState*, JSObject*, const String& defaultSourceURL, unsigned defaultLineNumber, unsigned defaultColumnNumber); 51 52 52 LegacyProfiler* LegacyProfiler::s_sharedLegacyProfiler = nullptr;53 LegacyProfiler* LegacyProfiler::s_sharedLegacyProfiler = 0; 53 54 54 55 LegacyProfiler* LegacyProfiler::profiler() … … 57 58 s_sharedLegacyProfiler = new LegacyProfiler(); 58 59 return s_sharedLegacyProfiler; 59 } 60 61 void LegacyProfiler::startProfiling(ExecState* exec, const String& title , PassRefPtr<Stopwatch> stopwatch)60 } 61 62 void LegacyProfiler::startProfiling(ExecState* exec, const String& title) 62 63 { 63 64 if (!exec) … … 75 76 76 77 exec->vm().setEnabledProfiler(this); 77 RefPtr<ProfileGenerator> profileGenerator = ProfileGenerator::create(exec, title, ++ProfilesUID , stopwatch);78 RefPtr<ProfileGenerator> profileGenerator = ProfileGenerator::create(exec, title, ++ProfilesUID); 78 79 m_currentProfiles.append(profileGenerator); 79 80 } … … 82 83 { 83 84 if (!exec) 84 return nullptr;85 return 0; 85 86 86 87 JSGlobalObject* origin = exec->lexicalGlobalObject(); … … 94 95 if (!m_currentProfiles.size()) 95 96 exec->vm().setEnabledProfiler(nullptr); 96 97 97 98 return returnProfile; 98 99 } 99 100 } 100 101 101 return nullptr;102 return 0; 102 103 } 103 104 … … 182 183 183 184 callFunctionForProfilesWithGroup(std::bind(&ProfileGenerator::exceptionUnwind, std::placeholders::_1, handlerCallFrame, callIdentifier), m_currentProfiles, handlerCallFrame->lexicalGlobalObject()->profileGroup()); 185 } 186 187 void LegacyProfiler::didPause(PassRefPtr<DebuggerCallFrame> prpCallFrame) 188 { 189 if (m_currentProfiles.isEmpty()) 190 return; 191 192 RefPtr<DebuggerCallFrame> callFrame = prpCallFrame; 193 CallIdentifier callIdentifier = createCallIdentifier(callFrame->exec(), JSValue(), StringImpl::empty(), 0, 0); 194 195 callFunctionForProfilesWithGroup(std::bind(&ProfileGenerator::didPause, std::placeholders::_1, callFrame, callIdentifier), m_currentProfiles, callFrame->vmEntryGlobalObject()->profileGroup()); 196 } 197 198 void LegacyProfiler::didContinue(PassRefPtr<DebuggerCallFrame> prpCallFrame) 199 { 200 if (m_currentProfiles.isEmpty()) 201 return; 202 203 RefPtr<DebuggerCallFrame> callFrame = prpCallFrame; 204 CallIdentifier callIdentifier = createCallIdentifier(callFrame->exec(), JSValue(), StringImpl::empty(), 0, 0); 205 206 callFunctionForProfilesWithGroup(std::bind(&ProfileGenerator::didContinue, std::placeholders::_1, callFrame, callIdentifier), m_currentProfiles, callFrame->vmEntryGlobalObject()->profileGroup()); 184 207 } 185 208 -
trunk/Source/JavaScriptCore/profiler/LegacyProfiler.h
r174319 r174322 33 33 #include <wtf/PassRefPtr.h> 34 34 #include <wtf/RefPtr.h> 35 #include <wtf/Stopwatch.h>36 35 #include <wtf/Vector.h> 37 36 38 37 namespace JSC { 39 38 39 class DebuggerCallFrame; 40 40 class ExecState; 41 class VM; 41 42 class JSGlobalObject; 42 43 class JSObject; … … 48 49 WTF_MAKE_FAST_ALLOCATED; 49 50 public: 50 JS_EXPORT_PRIVATE static LegacyProfiler* profiler(); 51 JS_EXPORT_PRIVATE static LegacyProfiler* profiler(); 51 52 static CallIdentifier createCallIdentifier(ExecState*, JSValue, const WTF::String& sourceURL, unsigned defaultLineNumber, unsigned defaultColumnNumber); 52 53 53 JS_EXPORT_PRIVATE void startProfiling(ExecState*, const WTF::String& title , PassRefPtr<Stopwatch>);54 JS_EXPORT_PRIVATE void startProfiling(ExecState*, const WTF::String& title); 54 55 JS_EXPORT_PRIVATE PassRefPtr<Profile> stopProfiling(ExecState*, const WTF::String& title); 55 56 void stopProfiling(JSGlobalObject*); … … 66 67 void exceptionUnwind(ExecState* handlerCallFrame); 67 68 69 void didPause(PassRefPtr<DebuggerCallFrame>); 70 void didContinue(PassRefPtr<DebuggerCallFrame>); 71 68 72 const Vector<RefPtr<ProfileGenerator>>& currentProfiles() { return m_currentProfiles; }; 69 73 -
trunk/Source/JavaScriptCore/profiler/ProfileGenerator.cpp
r174319 r174322 29 29 #include "CallFrame.h" 30 30 #include "CodeBlock.h" 31 #include "Debugger.h" 31 32 #include "JSGlobalObject.h" 32 33 #include "JSStringRef.h" … … 40 41 namespace JSC { 41 42 42 PassRefPtr<ProfileGenerator> ProfileGenerator::create(ExecState* exec, const String& title, unsigned uid , PassRefPtr<Stopwatch> stopwatch)43 { 44 return adoptRef(new ProfileGenerator(exec, title, uid , stopwatch));45 } 46 47 ProfileGenerator::ProfileGenerator(ExecState* exec, const String& title, unsigned uid , PassRefPtr<Stopwatch> stopwatch)43 PassRefPtr<ProfileGenerator> ProfileGenerator::create(ExecState* exec, const String& title, unsigned uid) 44 { 45 return adoptRef(new ProfileGenerator(exec, title, uid)); 46 } 47 48 ProfileGenerator::ProfileGenerator(ExecState* exec, const String& title, unsigned uid) 48 49 : m_origin(exec ? exec->lexicalGlobalObject() : nullptr) 49 50 , m_profileGroup(exec ? exec->lexicalGlobalObject()->profileGroup() : 0) 50 , m_ stopwatch(stopwatch)51 , m_debuggerPausedTimestamp(NAN) 51 52 , m_foundConsoleStartParent(false) 52 53 , m_suspended(false) 53 54 { 55 if (Debugger* debugger = exec->lexicalGlobalObject()->debugger()) 56 m_debuggerPausedTimestamp = debugger->isPaused() ? currentTime() : NAN; 57 54 58 m_profile = Profile::create(title, uid); 55 59 m_currentNode = m_rootNode = m_profile->rootNode(); … … 115 119 116 120 if (isnan(startTime)) 117 startTime = m_stopwatch->elapsedTime(); 121 startTime = currentTime(); 122 123 // If the debugger is paused when beginning, then don't set the start time. It 124 // will be fixed up when the debugger unpauses or the call entry ends. 125 if (!isnan(m_debuggerPausedTimestamp)) 126 startTime = NAN; 118 127 119 128 node->appendCall(ProfileNode::Call(startTime)); … … 125 134 126 135 ProfileNode::Call& last = node->lastCall(); 136 137 // If the debugger is paused, ignore the interval that ends now. 138 if (!isnan(m_debuggerPausedTimestamp) && !isnan(last.elapsedTime())) 139 return; 140 141 // If paused and no time was accrued then the debugger was never unpaused. The call will 142 // have no time accrued and appear to have started when the debugger was paused. 143 if (!isnan(m_debuggerPausedTimestamp)) { 144 last.setStartTime(m_debuggerPausedTimestamp); 145 last.setElapsedTime(0.0); 146 return; 147 } 148 149 // Otherwise, add the interval ending now to elapsed time. 127 150 double previousElapsedTime = isnan(last.elapsedTime()) ? 0.0 : last.elapsedTime(); 128 double newlyElapsedTime = m_stopwatch->elapsedTime() - last.startTime();151 double newlyElapsedTime = currentTime() - last.startTime(); 129 152 last.setElapsedTime(previousElapsedTime + newlyElapsedTime); 130 153 } … … 201 224 } 202 225 226 void ProfileGenerator::didPause(PassRefPtr<DebuggerCallFrame>, const CallIdentifier&) 227 { 228 ASSERT(isnan(m_debuggerPausedTimestamp)); 229 230 m_debuggerPausedTimestamp = currentTime(); 231 232 for (ProfileNode* node = m_currentNode.get(); node != m_profile->rootNode(); node = node->parent()) { 233 ProfileNode::Call& last = node->lastCall(); 234 ASSERT(!isnan(last.startTime())); 235 236 double previousElapsedTime = isnan(last.elapsedTime()) ? 0.0 : last.elapsedTime(); 237 double additionalElapsedTime = m_debuggerPausedTimestamp - last.startTime(); 238 last.setStartTime(NAN); 239 last.setElapsedTime(previousElapsedTime + additionalElapsedTime); 240 } 241 } 242 243 void ProfileGenerator::didContinue(PassRefPtr<DebuggerCallFrame>, const CallIdentifier&) 244 { 245 ASSERT(!isnan(m_debuggerPausedTimestamp)); 246 247 for (ProfileNode* node = m_currentNode.get(); node != m_profile->rootNode(); node = node->parent()) 248 node->lastCall().setStartTime(m_debuggerPausedTimestamp); 249 250 m_debuggerPausedTimestamp = NAN; 251 } 252 203 253 void ProfileGenerator::stopProfiling() 204 254 { -
trunk/Source/JavaScriptCore/profiler/ProfileGenerator.h
r174319 r174322 30 30 #include <wtf/RefCounted.h> 31 31 #include <wtf/RefPtr.h> 32 #include <wtf/Stopwatch.h>33 32 #include <wtf/text/WTFString.h> 34 33 … … 44 43 class ProfileGenerator : public RefCounted<ProfileGenerator> { 45 44 public: 46 static PassRefPtr<ProfileGenerator> create(ExecState*, const WTF::String& title, unsigned uid , PassRefPtr<Stopwatch>);45 static PassRefPtr<ProfileGenerator> create(ExecState*, const WTF::String& title, unsigned uid); 47 46 48 47 // Members … … 56 55 void exceptionUnwind(ExecState* handlerCallFrame, const CallIdentifier&); 57 56 57 void didPause(PassRefPtr<DebuggerCallFrame>, const CallIdentifier&); 58 void didContinue(PassRefPtr<DebuggerCallFrame>, const CallIdentifier&); 59 58 60 void setIsSuspended(bool suspended) { ASSERT(m_suspended != suspended); m_suspended = suspended; } 59 61 … … 61 63 62 64 private: 63 ProfileGenerator(ExecState*, const WTF::String& title, unsigned uid , PassRefPtr<Stopwatch>);65 ProfileGenerator(ExecState*, const WTF::String& title, unsigned uid); 64 66 void addParentForConsoleStart(ExecState*); 65 67 … … 73 75 JSGlobalObject* m_origin; 74 76 unsigned m_profileGroup; 75 RefPtr<Stopwatch> m_stopwatch; 77 // Timestamp is set to NAN when the debugger is not currently paused. 78 double m_debuggerPausedTimestamp; 76 79 RefPtr<ProfileNode> m_rootNode; 77 80 RefPtr<ProfileNode> m_currentNode;
Note:
See TracChangeset
for help on using the changeset viewer.