Changeset 174319 in webkit for trunk/Source/JavaScriptCore/profiler
- Timestamp:
- Oct 4, 2014, 12:18:38 PM (11 years ago)
- Location:
- trunk/Source/JavaScriptCore/profiler
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/profiler/LegacyProfiler.cpp
r174095 r174319 33 33 #include "CodeBlock.h" 34 34 #include "CommonIdentifiers.h" 35 #include "DebuggerCallFrame.h"36 35 #include "InternalFunction.h" 37 36 #include "JSFunction.h" … … 51 50 static CallIdentifier createCallIdentifierFromFunctionImp(ExecState*, JSObject*, const String& defaultSourceURL, unsigned defaultLineNumber, unsigned defaultColumnNumber); 52 51 53 LegacyProfiler* LegacyProfiler::s_sharedLegacyProfiler = 0;52 LegacyProfiler* LegacyProfiler::s_sharedLegacyProfiler = nullptr; 54 53 55 54 LegacyProfiler* LegacyProfiler::profiler() … … 58 57 s_sharedLegacyProfiler = new LegacyProfiler(); 59 58 return s_sharedLegacyProfiler; 60 } 61 62 void LegacyProfiler::startProfiling(ExecState* exec, const String& title )59 } 60 61 void LegacyProfiler::startProfiling(ExecState* exec, const String& title, PassRefPtr<Stopwatch> stopwatch) 63 62 { 64 63 if (!exec) … … 76 75 77 76 exec->vm().setEnabledProfiler(this); 78 RefPtr<ProfileGenerator> profileGenerator = ProfileGenerator::create(exec, title, ++ProfilesUID );77 RefPtr<ProfileGenerator> profileGenerator = ProfileGenerator::create(exec, title, ++ProfilesUID, stopwatch); 79 78 m_currentProfiles.append(profileGenerator); 80 79 } … … 83 82 { 84 83 if (!exec) 85 return 0;84 return nullptr; 86 85 87 86 JSGlobalObject* origin = exec->lexicalGlobalObject(); … … 95 94 if (!m_currentProfiles.size()) 96 95 exec->vm().setEnabledProfiler(nullptr); 97 96 98 97 return returnProfile; 99 98 } 100 99 } 101 100 102 return 0;101 return nullptr; 103 102 } 104 103 … … 183 182 184 183 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());207 184 } 208 185 -
trunk/Source/JavaScriptCore/profiler/LegacyProfiler.h
r174095 r174319 33 33 #include <wtf/PassRefPtr.h> 34 34 #include <wtf/RefPtr.h> 35 #include <wtf/Stopwatch.h> 35 36 #include <wtf/Vector.h> 36 37 37 38 namespace JSC { 38 39 39 class DebuggerCallFrame;40 40 class ExecState; 41 class VM;42 41 class JSGlobalObject; 43 42 class JSObject; … … 49 48 WTF_MAKE_FAST_ALLOCATED; 50 49 public: 51 JS_EXPORT_PRIVATE static LegacyProfiler* profiler(); 50 JS_EXPORT_PRIVATE static LegacyProfiler* profiler(); 52 51 static CallIdentifier createCallIdentifier(ExecState*, JSValue, const WTF::String& sourceURL, unsigned defaultLineNumber, unsigned defaultColumnNumber); 53 52 54 JS_EXPORT_PRIVATE void startProfiling(ExecState*, const WTF::String& title );53 JS_EXPORT_PRIVATE void startProfiling(ExecState*, const WTF::String& title, PassRefPtr<Stopwatch>); 55 54 JS_EXPORT_PRIVATE PassRefPtr<Profile> stopProfiling(ExecState*, const WTF::String& title); 56 55 void stopProfiling(JSGlobalObject*); … … 67 66 void exceptionUnwind(ExecState* handlerCallFrame); 68 67 69 void didPause(PassRefPtr<DebuggerCallFrame>);70 void didContinue(PassRefPtr<DebuggerCallFrame>);71 72 68 const Vector<RefPtr<ProfileGenerator>>& currentProfiles() { return m_currentProfiles; }; 73 69 -
trunk/Source/JavaScriptCore/profiler/ProfileGenerator.cpp
r174095 r174319 29 29 #include "CallFrame.h" 30 30 #include "CodeBlock.h" 31 #include "Debugger.h"32 31 #include "JSGlobalObject.h" 33 32 #include "JSStringRef.h" … … 41 40 namespace JSC { 42 41 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 )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) 49 48 : m_origin(exec ? exec->lexicalGlobalObject() : nullptr) 50 49 , m_profileGroup(exec ? exec->lexicalGlobalObject()->profileGroup() : 0) 51 , m_ debuggerPausedTimestamp(NAN)50 , m_stopwatch(stopwatch) 52 51 , m_foundConsoleStartParent(false) 53 52 , m_suspended(false) 54 53 { 55 if (Debugger* debugger = exec->lexicalGlobalObject()->debugger())56 m_debuggerPausedTimestamp = debugger->isPaused() ? currentTime() : NAN;57 58 54 m_profile = Profile::create(title, uid); 59 55 m_currentNode = m_rootNode = m_profile->rootNode(); … … 119 115 120 116 if (isnan(startTime)) 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; 117 startTime = m_stopwatch->elapsedTime(); 127 118 128 119 node->appendCall(ProfileNode::Call(startTime)); … … 134 125 135 126 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 will142 // 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.150 127 double previousElapsedTime = isnan(last.elapsedTime()) ? 0.0 : last.elapsedTime(); 151 double newlyElapsedTime = currentTime() - last.startTime();128 double newlyElapsedTime = m_stopwatch->elapsedTime() - last.startTime(); 152 129 last.setElapsedTime(previousElapsedTime + newlyElapsedTime); 153 130 } … … 224 201 } 225 202 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 253 203 void ProfileGenerator::stopProfiling() 254 204 { -
trunk/Source/JavaScriptCore/profiler/ProfileGenerator.h
r174095 r174319 30 30 #include <wtf/RefCounted.h> 31 31 #include <wtf/RefPtr.h> 32 #include <wtf/Stopwatch.h> 32 33 #include <wtf/text/WTFString.h> 33 34 … … 43 44 class ProfileGenerator : public RefCounted<ProfileGenerator> { 44 45 public: 45 static PassRefPtr<ProfileGenerator> create(ExecState*, const WTF::String& title, unsigned uid );46 static PassRefPtr<ProfileGenerator> create(ExecState*, const WTF::String& title, unsigned uid, PassRefPtr<Stopwatch>); 46 47 47 48 // Members … … 55 56 void exceptionUnwind(ExecState* handlerCallFrame, const CallIdentifier&); 56 57 57 void didPause(PassRefPtr<DebuggerCallFrame>, const CallIdentifier&);58 void didContinue(PassRefPtr<DebuggerCallFrame>, const CallIdentifier&);59 60 58 void setIsSuspended(bool suspended) { ASSERT(m_suspended != suspended); m_suspended = suspended; } 61 59 … … 63 61 64 62 private: 65 ProfileGenerator(ExecState*, const WTF::String& title, unsigned uid );63 ProfileGenerator(ExecState*, const WTF::String& title, unsigned uid, PassRefPtr<Stopwatch>); 66 64 void addParentForConsoleStart(ExecState*); 67 65 … … 75 73 JSGlobalObject* m_origin; 76 74 unsigned m_profileGroup; 77 // Timestamp is set to NAN when the debugger is not currently paused. 78 double m_debuggerPausedTimestamp; 75 RefPtr<Stopwatch> m_stopwatch; 79 76 RefPtr<ProfileNode> m_rootNode; 80 77 RefPtr<ProfileNode> m_currentNode;
Note:
See TracChangeset
for help on using the changeset viewer.