Ignore:
Timestamp:
May 21, 2008, 11:21:59 PM (17 years ago)
Author:
[email protected]
Message:

2008-05-21 Kevin McCullough <[email protected]>

Reviewed by Maciej and Geoff.

<rdar://problem/5951561> Turn on JavaScript Profiler
-As part of the effort to turn on the profiler it would be helpful if it
did not need ExecStates to represent the stack location of the currently
executing statement.
-We now create each node as necessary with a reference to the current
node and each node knows its parent so that the tree can be made without
the entire stack.

  • profiler/Profile.cpp: (KJS::Profile::Profile): The current node starts at the head. (KJS::Profile::stopProfiling): The current node is cleared when profiling stops. (KJS::Profile::willExecute): The current node either adds a new child or starts and returns a reference to an already existing child if the call ID that is requested already exists. (KJS::Profile::didExecute): The current node finishes and returns its parent.
  • profiler/Profile.h: Use a single callIdentifier instead of a vector since we no longer use the whole stack.
  • profiler/ProfileNode.cpp: Now profile nodes keep a reference to their parent. (KJS::ProfileNode::ProfileNode): Initialize the parent. (KJS::ProfileNode::didExecute): Record the time and return the parent. (KJS::ProfileNode::addOrStartChild): If the given callIdentifier is already a child, start it and return it, otherwise create a new one and return that. (KJS::ProfileNode::stopProfiling): Same logic, just use the new function.
  • profiler/ProfileNode.h: Utilize the parent. (KJS::ProfileNode::create): (KJS::ProfileNode::parent):
  • profiler/Profiler.cpp: (KJS::Profiler::startProfiling): Here is the only place where the ExecState is used to figure out where in the stack the profiler is currently profiling. (KJS::dispatchFunctionToProfiles): Only send one CallIdentifier instead of a vector of them. (KJS::Profiler::willExecute): Ditto. (KJS::Profiler::didExecute): Ditto. (KJS::createCallIdentifier): Create only one CallIdentifier. (KJS::createCallIdentifierFromFunctionImp): Ditto.
  • profiler/Profiler.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/profiler/Profiler.cpp

    r33979 r34013  
    4141
    4242static Profiler* sharedProfiler = 0;
    43 static const char* GlobalCodeExecution = "(global code)";
     43static const char* GlobalCodeExecution = "(program)";
    4444static const char* AnonymousFunction = "(anonymous function)";
    4545
    4646static void getCallIdentifiers(ExecState*, Vector<CallIdentifier>& callIdentifiers);
    47 static void getCallIdentifiers(ExecState*, JSObject*, Vector<CallIdentifier>& callIdentifiers);
    48 static void getCallIdentifiers(ExecState*, const UString& sourceURL, int startingLineNumber, Vector<CallIdentifier>& callIdentifiers);
    49 static void getCallIdentifierFromFunctionImp(FunctionImp*, Vector<CallIdentifier>& callIdentifiers);
     47static CallIdentifier createCallIdentifier(JSObject*);
     48static CallIdentifier createCallIdentifier(const UString& sourceURL, int startingLineNumber);
     49static CallIdentifier createCallIdentifierFromFunctionImp(FunctionImp*);
    5050
    5151Profiler* Profiler::profiler()
     
    8282    Vector<CallIdentifier> callIdentifiers;
    8383    getCallIdentifiers(exec, callIdentifiers);
    84     profile->willExecute(callIdentifiers);
     84    for (unsigned i = 0; i< callIdentifiers.size(); ++i)
     85        profile->willExecute(callIdentifiers[i]);
    8586}
    8687
     
    113114}
    114115
    115 static inline void dispatchFunctionToProfiles(const Vector<RefPtr<Profile> >& profiles, Profile::ProfileFunction function, const Vector<CallIdentifier>& callIdentifiers, unsigned currentPageGroupIdentifier)
     116static inline void dispatchFunctionToProfiles(const Vector<RefPtr<Profile> >& profiles, Profile::ProfileFunction function, const CallIdentifier& callIdentifier, unsigned currentPageGroupIdentifier)
    116117{
    117118    for (size_t i = 0; i < profiles.size(); ++i)
    118119        if (profiles[i]->pageGroupIdentifier() == currentPageGroupIdentifier)
    119             (profiles[i].get()->*function)(callIdentifiers);
     120            (profiles[i].get()->*function)(callIdentifier);
    120121}
    121122
     
    128129        return;
    129130
    130     Vector<CallIdentifier> callIdentifiers;
    131     getCallIdentifiers(exec, calledFunction, callIdentifiers);
    132 
    133     dispatchFunctionToProfiles(m_currentProfiles, &Profile::willExecute, callIdentifiers, exec->lexicalGlobalObject()->pageGroupIdentifier());
     131    dispatchFunctionToProfiles(m_currentProfiles, &Profile::willExecute, createCallIdentifier(calledFunction), exec->lexicalGlobalObject()->pageGroupIdentifier());
    134132}
    135133
     
    139137        return;
    140138
    141     Vector<CallIdentifier> callIdentifiers;
    142     getCallIdentifiers(exec, sourceURL, startingLineNumber, callIdentifiers);
    143 
    144     dispatchFunctionToProfiles(m_currentProfiles, &Profile::willExecute, callIdentifiers, exec->lexicalGlobalObject()->pageGroupIdentifier());
     139    CallIdentifier callIdentifier = createCallIdentifier(sourceURL, startingLineNumber);
     140
     141    dispatchFunctionToProfiles(m_currentProfiles, &Profile::willExecute, callIdentifier, exec->lexicalGlobalObject()->pageGroupIdentifier());
    145142}
    146143
     
    153150        return;
    154151
    155     Vector<CallIdentifier> callIdentifiers;
    156     getCallIdentifiers(exec, calledFunction, callIdentifiers);
    157 
    158     dispatchFunctionToProfiles(m_currentProfiles, &Profile::didExecute, callIdentifiers, exec->lexicalGlobalObject()->pageGroupIdentifier());
     152    dispatchFunctionToProfiles(m_currentProfiles, &Profile::didExecute, createCallIdentifier(calledFunction), exec->lexicalGlobalObject()->pageGroupIdentifier());
    159153}
    160154
     
    164158        return;
    165159
    166     Vector<CallIdentifier> callIdentifiers;
    167     getCallIdentifiers(exec, sourceURL, startingLineNumber, callIdentifiers);
    168 
    169     dispatchFunctionToProfiles(m_currentProfiles, &Profile::didExecute, callIdentifiers, exec->lexicalGlobalObject()->pageGroupIdentifier());
     160    dispatchFunctionToProfiles(m_currentProfiles, &Profile::didExecute, createCallIdentifier(sourceURL, startingLineNumber), exec->lexicalGlobalObject()->pageGroupIdentifier());
    170161}
    171162
     
    183174}
    184175
    185 void getCallIdentifiers(ExecState* exec, JSObject* calledFunction, Vector<CallIdentifier>& callIdentifiers)
     176CallIdentifier createCallIdentifier(JSObject* calledFunction)
    186177{
    187178    if (calledFunction->inherits(&FunctionImp::info))
    188         getCallIdentifierFromFunctionImp(static_cast<FunctionImp*>(calledFunction), callIdentifiers);
    189     else if (calledFunction->inherits(&InternalFunctionImp::info))
    190         callIdentifiers.append(CallIdentifier(static_cast<InternalFunctionImp*>(calledFunction)->functionName().ustring(), "", 0) );
    191     getCallIdentifiers(exec, callIdentifiers);
    192 }
    193 
    194 void getCallIdentifiers(ExecState* exec, const UString& sourceURL, int startingLineNumber, Vector<CallIdentifier>& callIdentifiers)
    195 {
    196     callIdentifiers.append(CallIdentifier(GlobalCodeExecution, sourceURL, (startingLineNumber + 1)) );
    197     getCallIdentifiers(exec, callIdentifiers);
    198 }
    199 
    200 void getCallIdentifierFromFunctionImp(FunctionImp* functionImp, Vector<CallIdentifier>& callIdentifiers)
     179        return createCallIdentifierFromFunctionImp(static_cast<FunctionImp*>(calledFunction));
     180    if (calledFunction->inherits(&InternalFunctionImp::info))
     181        return CallIdentifier(static_cast<InternalFunctionImp*>(calledFunction)->functionName().ustring(), "", 0);
     182
     183    ASSERT_NOT_REACHED();
     184    return CallIdentifier("", 0, 0);
     185}
     186
     187CallIdentifier createCallIdentifier(const UString& sourceURL, int startingLineNumber)
     188{
     189    return CallIdentifier(GlobalCodeExecution, sourceURL, (startingLineNumber + 1));
     190}
     191
     192CallIdentifier createCallIdentifierFromFunctionImp(FunctionImp* functionImp)
    201193{
    202194    UString name = functionImp->functionName().ustring();
     
    204196        name = AnonymousFunction;
    205197
    206     callIdentifiers.append(CallIdentifier(name, functionImp->body->sourceURL(), functionImp->body->lineNo()) );
     198    return CallIdentifier(name, functionImp->body->sourceURL(), functionImp->body->lineNo());
    207199}
    208200
Note: See TracChangeset for help on using the changeset viewer.