Ignore:
Timestamp:
Sep 3, 2008, 10:35:42 AM (17 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2008-09-02 Kevin McCullough <[email protected]>

Reviewed by Darin and Tim.

Remove most of the "zombie" mode from the profiler. Next we will need
to remove the client callback mechanism in profiles.

  • This simplifies the code, leverages the recent changes I've made in getting line numbers from SquirrelFish, and is a slight speed improvement on SunSpider.
  • Also the "zombie" mode was a constant source of odd edge cases and obscure bugs so it's good to remove since all of its issues may not have been found.
  • API/JSProfilerPrivate.cpp: No need to call didFinishAllExecution() any more. (JSEndProfiling):
  • JavaScriptCore.exp: Export the new signature of retrieveLastCaller()
  • VM/Machine.cpp: (KJS::Machine::execute): No need to call didFinishAllExecution() any more. (KJS::Machine::retrieveCaller): Now operates on InternalFunctions now since the RegisterFile is no longer guaranteeded to store only JSFunctions (KJS::Machine::retrieveLastCaller): Now also retrieve the function's name (KJS::Machine::callFrame): A result of changing retrieveCaller()
  • VM/Machine.h:
  • VM/Register.h:
  • kjs/JSGlobalObject.cpp: (KJS::JSGlobalObject::~JSGlobalObject):
  • kjs/nodes.h:
  • profiler/ProfileGenerator.cpp: (KJS::ProfileGenerator::create): Now pass the original exec and get the global exec and client when necessary. We need the original exec so we can have the stack frame where profiling started. (KJS::ProfileGenerator::ProfileGenerator): ditto. (KJS::ProfileGenerator::addParentForConsoleStart): This is where the parent to star of the profile is added, if there is one. (KJS::ProfileGenerator::willExecute): Remove uglyness! (KJS::ProfileGenerator::didExecute): Ditto! (KJS::ProfileGenerator::stopProfiling): (KJS::ProfileGenerator::removeProfileStart): Use a better way to find and remove the function we are looking for. (KJS::ProfileGenerator::removeProfileEnd): Ditto.
  • profiler/ProfileGenerator.h: (KJS::ProfileGenerator::client):
  • profiler/ProfileNode.cpp: (KJS::ProfileNode::removeChild): Add a better way to remove a child from a ProfileNode. (KJS::ProfileNode::stopProfiling): (KJS::ProfileNode::debugPrintData): Modified a debug-only diagnostic function to be sane.
  • profiler/ProfileNode.h:
  • profiler/Profiler.cpp: Change to pass the original exec state. (KJS::Profiler::startProfiling): (KJS::Profiler::stopProfiling): (KJS::Profiler::willExecute): (KJS::Profiler::didExecute): (KJS::Profiler::createCallIdentifier):
  • profiler/Profiler.h:

WebCore:

2008-09-03 Kevin McCullough <[email protected]>

Reviewed by Darin and Tim.

Remove most of the "zombie" mode from the profiler. Next we will need
to remove the client callback mechanism in profiles.

  • These changes are a result of changes to JSCore.
  • manual-tests/inspector/profiler-test-nested-start-and-stop-profiler.html:
  • page/Console.cpp: (WebCore::retrieveLastCaller): (WebCore::Console::profileEnd):
  • page/InspectorController.cpp: (WebCore::InspectorController::stopUserInitiatedProfiling):
File:
1 edited

Legend:

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

    r35847 r36058  
    2727#include "ProfileGenerator.h"
    2828
     29#include "ExecState.h"
     30#include "JSGlobalObject.h"
     31#include "JSStringRef.h"
     32#include "JSFunction.h"
     33#include "Machine.h"
    2934#include "Profile.h"
    3035#include "Profiler.h"
     
    3540static const char* NonJSExecution = "(idle)";
    3641
    37 PassRefPtr<ProfileGenerator> ProfileGenerator::create(const UString& title, ExecState* originatingGlobalExec, unsigned profileGroup, ProfilerClient* client, unsigned uid)
     42PassRefPtr<ProfileGenerator> ProfileGenerator::create(const UString& title, ExecState* originatingExec, ProfilerClient* client, unsigned uid)
    3843{
    39     return adoptRef(new ProfileGenerator(title, originatingGlobalExec, profileGroup, client, uid));
     44    return adoptRef(new ProfileGenerator(title, originatingExec, client, uid));
    4045}
    4146
    42 ProfileGenerator::ProfileGenerator(const UString& title, ExecState* originatingGlobalExec, unsigned profileGroup, ProfilerClient* client, unsigned uid)
    43     : m_originatingGlobalExec(originatingGlobalExec)
    44     , m_profileGroup(profileGroup)
     47ProfileGenerator::ProfileGenerator(const UString& title, ExecState* originatingExec, ProfilerClient* client, unsigned uid)
     48    : m_originatingGlobalExec(originatingExec->lexicalGlobalObject()->globalExec())
     49    , m_profileGroup(originatingExec->lexicalGlobalObject()->profileGroup())
    4550    , m_client(client)
    46     , m_stoppedProfiling(false)
    47     , m_stoppedCallDepth(0)
    4851{
    4952    m_profile = Profile::create(title, uid);
    5053    m_currentNode = m_head = m_profile->head();
     54
     55    addParentForConsoleStart(originatingExec);
     56}
     57
     58void 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());
    5168}
    5269
     
    6481    }
    6582
    66     if (m_stoppedProfiling) {
    67         ++m_stoppedCallDepth;
    68         return;
    69     }
    70 
    71     ASSERT(m_currentNode);
     83    ASSERT_ARG(m_currentNode, m_currentNode);
    7284    m_currentNode = m_currentNode->willExecute(callIdentifier);
    7385}
     
    8193    }
    8294
    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());
    88101        return;
    89102    }
    90103
    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();
    111105}
    112106
     
    118112    removeProfileEnd();
    119113
    120     ASSERT(m_currentNode);
     114    ASSERT_ARG(m_currentNode, m_currentNode);
    121115
    122116    // Set the current node to the parent, because we are in a call that
     
    124118    m_currentNode = m_currentNode->parent();
    125119
    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()) {
    135121        RefPtr<ProfileNode> idleNode = ProfileNode::create(CallIdentifier(NonJSExecution, 0, 0), m_head.get(), m_head.get());
    136122
     
    142128        m_head->addChild(idleNode.release());
    143129    }
    144 
    145     m_currentNode = 0;
    146     m_originatingGlobalExec = 0;
    147 
    148     m_profile->setHead(m_head.release());
    149     return true;
    150130}
    151131
     
    160140        return;
    161141
    162     // Increment m_stoppedCallDepth to account for didExecute not being called for console.ProfileGenerator.
    163     ++m_stoppedCallDepth;
    164 
    165142    // Attribute the time of the node aobut to be removed to the self time of its parent
    166143    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);
    170145}
    171146
     
    184159
    185160    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);
    187162}
    188163
Note: See TracChangeset for help on using the changeset viewer.