Ignore:
Timestamp:
Jul 7, 2008, 11:12:09 AM (17 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2008-07-07 Kevin McCullough <[email protected]>

Reviewed by Darin.

When the profiler is running it gathers information and creates a
Profile. After it finishes the Profile can be sorted and have other
data refinements run over it. Both of these were done in the same class
before. Now I split the gathering operations into a new class called
ProfileGenerator.

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • profiler/Profile.cpp: Removed code related to the gather stage of a Profile's creation. (KJS::Profile::create): (KJS::Profile::Profile):
  • profiler/Profile.h: Ditto. (KJS::Profile::title): (KJS::Profile::callTree): (KJS::Profile::setHead):
  • profiler/ProfileGenerator.cpp: Added. This is the class that will handle the stage of creating a Profile. Once the Profile is finished being created, this class goes away. (KJS::ProfileGenerator::create): (KJS::ProfileGenerator::ProfileGenerator): (KJS::ProfileGenerator::title): (KJS::ProfileGenerator::willExecute): (KJS::ProfileGenerator::didExecute): (KJS::ProfileGenerator::stopProfiling): (KJS::ProfileGenerator::didFinishAllExecution): (KJS::ProfileGenerator::removeProfileStart): (KJS::ProfileGenerator::removeProfileEnd):
  • profiler/ProfileGenerator.h: Added. (KJS::ProfileGenerator::profile): (KJS::ProfileGenerator::originatingGlobalExec): (KJS::ProfileGenerator::pageGroupIdentifier): (KJS::ProfileGenerator::client): (KJS::ProfileGenerator::stoppedProfiling):
  • profiler/Profiler.cpp: Now operates with the ProfileGenerator instead of the Profile. (KJS::Profiler::startProfiling): (KJS::Profiler::stopProfiling): (KJS::Profiler::didFinishAllExecution): It is here that the Profile is handed off to its client and the Profile Generator is no longer needed. (KJS::dispatchFunctionToProfiles): (KJS::Profiler::willExecute): (KJS::Profiler::didExecute):
  • profiler/Profiler.h: Cleaned up the includes and subsequently the forward declarations. Also use the new ProfileGenerator. (KJS::ProfilerClient::~ProfilerClient): (KJS::Profiler::currentProfiles):
  • profiler/TreeProfile.cpp: Use Profile's new interface. (KJS::TreeProfile::create): (KJS::TreeProfile::TreeProfile):
  • profiler/TreeProfile.h:

WebCore:

2008-07-07 Kevin McCullough <[email protected]>

Reviewed by Darin.

Because profiler.h no longer #includes profile.h we need to explicitly
include it in console.cpp.

  • page/Console.cpp:
File:
1 edited

Legend:

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

    r35037 r35039  
    2727#include "Profile.h"
    2828
    29 #include "ExecState.h"
    30 #include "JSFunction.h"
    31 #include "JSGlobalObject.h"
     29//#include "ExecState.h"
     30//#include "JSFunction.h"
     31//#include "JSGlobalObject.h"
    3232#include "ProfileNode.h"
    3333#include "TreeProfile.h"
     
    3636namespace KJS {
    3737
    38 static const char* NonJSExecution = "(idle)";
    39 
    40 PassRefPtr<Profile> Profile::create(const UString& title, ExecState* originatingGlobalExec, unsigned pageGroupIdentifier, ProfilerClient* client)
     38PassRefPtr<Profile> Profile::create(const UString& title)
    4139{
    42     return TreeProfile::create(title, originatingGlobalExec, pageGroupIdentifier, client);
     40    return TreeProfile::create(title);
    4341}
    4442
    45 Profile::Profile(const UString& title, ExecState* originatingGlobalExec, unsigned pageGroupIdentifier, ProfilerClient* client)
     43Profile::Profile(const UString& title)
    4644    : m_title(title)
    47     , m_originatingGlobalExec(originatingGlobalExec)
    48     , m_pageGroupIdentifier(pageGroupIdentifier)
    49     , m_stoppedCallDepth(0)
    50     , m_client(client)
    51     , m_stoppedProfiling(false)
    5245{
    5346    // FIXME: When multi-threading is supported this will be a vector and calls
    5447    // into the profiler will need to know which thread it is executing on.
    5548    m_head = ProfileNode::create(CallIdentifier("Thread_1", 0, 0), 0, 0);
    56     m_currentNode = m_head;
    5749}
    5850
    5951Profile::~Profile()
    6052{
    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 that
    72     // 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 parent
    113     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 parent
    130     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 the
    175     // m_currentNode to the parent and don't call didExecute.
    176     m_currentNode = m_stoppedProfiling ? m_currentNode->parent() : m_currentNode->didExecute();
    17753}
    17854
Note: See TracChangeset for help on using the changeset viewer.