Commit 1e1baa1f authored by kmccullough@apple.com's avatar kmccullough@apple.com

JavaScriptCore:

2008-07-07  Kevin McCullough  <kmccullough@apple.com>

        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  <kmccullough@apple.com>

        Reviewed by Darin.

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

        * page/Console.cpp:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@35039 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 632fe153
2008-07-07 Kevin McCullough <kmccullough@apple.com>
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:
2008-07-07 Sam Weinig <sam@webkit.org>
Reviewed by Cameron Zwarich.
......@@ -91,6 +91,8 @@
95AB83560DA43C3000BC83F3 /* ProfileNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95AB83540DA43B4400BC83F3 /* ProfileNode.cpp */; };
95CD41B30E1BF6560085358E /* TreeProfile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95CD41B10E1BF6560085358E /* TreeProfile.cpp */; };
95CD41B40E1BF6560085358E /* TreeProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 95CD41B20E1BF6560085358E /* TreeProfile.h */; };
95CD45760E1C4FDD0085358E /* ProfileGenerator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95CD45740E1C4FDD0085358E /* ProfileGenerator.cpp */; };
95CD45770E1C4FDD0085358E /* ProfileGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 95CD45750E1C4FDD0085358E /* ProfileGenerator.h */; settings = {ATTRIBUTES = (); }; };
95E3BC050E1AE68200B2D1C1 /* CallIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 95E3BC040E1AE68200B2D1C1 /* CallIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
A72700900DAC6BBC00E548D7 /* JSNotAnObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A72700780DAC605600E548D7 /* JSNotAnObject.cpp */; };
A72701B60DADE94900E548D7 /* ExceptionHelpers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A72701B40DADE94900E548D7 /* ExceptionHelpers.cpp */; };
......@@ -592,6 +594,8 @@
95C18D3E0C90E7EF00E72F73 /* JSRetainPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSRetainPtr.h; sourceTree = "<group>"; };
95CD41B10E1BF6560085358E /* TreeProfile.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TreeProfile.cpp; path = profiler/TreeProfile.cpp; sourceTree = "<group>"; };
95CD41B20E1BF6560085358E /* TreeProfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TreeProfile.h; path = profiler/TreeProfile.h; sourceTree = "<group>"; };
95CD45740E1C4FDD0085358E /* ProfileGenerator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ProfileGenerator.cpp; path = profiler/ProfileGenerator.cpp; sourceTree = "<group>"; };
95CD45750E1C4FDD0085358E /* ProfileGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ProfileGenerator.h; path = profiler/ProfileGenerator.h; sourceTree = "<group>"; };
95E3BC040E1AE68200B2D1C1 /* CallIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CallIdentifier.h; path = profiler/CallIdentifier.h; sourceTree = "<group>"; };
A72700770DAC605600E548D7 /* JSNotAnObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSNotAnObject.h; sourceTree = "<group>"; };
A72700780DAC605600E548D7 /* JSNotAnObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSNotAnObject.cpp; sourceTree = "<group>"; };
......@@ -1255,15 +1259,17 @@
95AB831A0DA42C6900BC83F3 /* profiler */ = {
isa = PBXGroup;
children = (
95CD41B10E1BF6560085358E /* TreeProfile.cpp */,
95CD41B20E1BF6560085358E /* TreeProfile.h */,
95E3BC040E1AE68200B2D1C1 /* CallIdentifier.h */,
95AB83540DA43B4400BC83F3 /* ProfileNode.cpp */,
95AB83550DA43B4400BC83F3 /* ProfileNode.h */,
95742F630DD11F5A000917FB /* Profile.cpp */,
95742F640DD11F5A000917FB /* Profile.h */,
95CD45740E1C4FDD0085358E /* ProfileGenerator.cpp */,
95CD45750E1C4FDD0085358E /* ProfileGenerator.h */,
95AB83540DA43B4400BC83F3 /* ProfileNode.cpp */,
95AB83550DA43B4400BC83F3 /* ProfileNode.h */,
95AB832E0DA42CAD00BC83F3 /* Profiler.cpp */,
95AB832F0DA42CAD00BC83F3 /* Profiler.h */,
95CD41B10E1BF6560085358E /* TreeProfile.cpp */,
95CD41B20E1BF6560085358E /* TreeProfile.h */,
);
name = profiler;
sourceTree = "<group>";
......@@ -1475,6 +1481,7 @@
BC1167DA0E19BCC9008066DD /* JSCell.h in Headers */,
BC7F8FB90E19D1C3008632C0 /* JSNumberCell.h in Headers */,
95CD41B40E1BF6560085358E /* TreeProfile.h in Headers */,
95CD45770E1C4FDD0085358E /* ProfileGenerator.h in Headers */,
5D53726F0E1C54880021E549 /* Tracing.h in Headers */,
5D53727E0E1C55EC0021E549 /* TracingDtrace.h in Headers */,
BC6AAAE50E1F426500AD87D8 /* ClassInfo.h in Headers */,
......@@ -1785,6 +1792,7 @@
149559EE0DDCDDF700648087 /* DebuggerCallFrame.cpp in Sources */,
E18E3A590DF9278C00D90B34 /* JSGlobalData.cpp in Sources */,
95CD41B30E1BF6560085358E /* TreeProfile.cpp in Sources */,
95CD45760E1C4FDD0085358E /* ProfileGenerator.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -26,156 +26,32 @@
#include "config.h"
#include "Profile.h"
#include "ExecState.h"
#include "JSFunction.h"
#include "JSGlobalObject.h"
//#include "ExecState.h"
//#include "JSFunction.h"
//#include "JSGlobalObject.h"
#include "ProfileNode.h"
#include "TreeProfile.h"
#include <stdio.h>
namespace KJS {
static const char* NonJSExecution = "(idle)";
PassRefPtr<Profile> Profile::create(const UString& title, ExecState* originatingGlobalExec, unsigned pageGroupIdentifier, ProfilerClient* client)
PassRefPtr<Profile> Profile::create(const UString& title)
{
return TreeProfile::create(title, originatingGlobalExec, pageGroupIdentifier, client);
return TreeProfile::create(title);
}
Profile::Profile(const UString& title, ExecState* originatingGlobalExec, unsigned pageGroupIdentifier, ProfilerClient* client)
Profile::Profile(const UString& title)
: m_title(title)
, m_originatingGlobalExec(originatingGlobalExec)
, m_pageGroupIdentifier(pageGroupIdentifier)
, m_stoppedCallDepth(0)
, m_client(client)
, m_stoppedProfiling(false)
{
// FIXME: When multi-threading is supported this will be a vector and calls
// into the profiler will need to know which thread it is executing on.
m_head = ProfileNode::create(CallIdentifier("Thread_1", 0, 0), 0, 0);
m_currentNode = m_head;
}
Profile::~Profile()
{
}
void Profile::stopProfiling()
{
forEach(&ProfileNode::stopProfiling);
removeProfileStart();
removeProfileEnd();
ASSERT(m_currentNode);
// Set the current node to the parent, because we are in a call that
// will not get didExecute call.
m_currentNode = m_currentNode->parent();
m_stoppedProfiling = true;
}
bool Profile::didFinishAllExecution()
{
if (!m_stoppedProfiling)
return false;
if (double headSelfTime = m_head->selfTime()) {
RefPtr<ProfileNode> idleNode = ProfileNode::create(CallIdentifier(NonJSExecution, 0, 0), m_head.get(), m_head.get());
idleNode->setTotalTime(headSelfTime);
idleNode->setSelfTime(headSelfTime);
idleNode->setVisible(true);
m_head->setSelfTime(0.0);
m_head->addChild(idleNode.release());
}
m_currentNode = 0;
m_originatingGlobalExec = 0;
return true;
}
// The console.profile that started this profile will be the first child.
void Profile::removeProfileStart()
{
ProfileNode* currentNode = 0;
for (ProfileNode* next = m_head.get(); next; next = next->firstChild())
currentNode = next;
if (currentNode->callIdentifier().m_name != "profile")
return;
// Increment m_stoppedCallDepth to account for didExecute not being called for console.profile.
++m_stoppedCallDepth;
// Attribute the time of the node aobut to be removed to the self time of its parent
currentNode->parent()->setSelfTime(currentNode->parent()->selfTime() + currentNode->totalTime());
ASSERT(currentNode->callIdentifier() == (currentNode->parent()->children()[0])->callIdentifier());
currentNode->parent()->removeChild(0);
}
// The console.profileEnd that stopped this profile will be the last child.
void Profile::removeProfileEnd()
{
ProfileNode* currentNode = 0;
for (ProfileNode* next = m_head.get(); next; next = next->lastChild())
currentNode = next;
if (currentNode->callIdentifier().m_name != "profileEnd")
return;
// Attribute the time of the node aobut to be removed to the self time of its parent
currentNode->parent()->setSelfTime(currentNode->parent()->selfTime() + currentNode->totalTime());
ASSERT(currentNode->callIdentifier() == (currentNode->parent()->children()[currentNode->parent()->children().size() - 1])->callIdentifier());
currentNode->parent()->removeChild(currentNode->parent()->children().size() - 1);
}
void Profile::willExecute(const CallIdentifier& callIdentifier)
{
if (m_stoppedProfiling) {
++m_stoppedCallDepth;
return;
}
ASSERT(m_currentNode);
m_currentNode = m_currentNode->willExecute(callIdentifier);
}
void Profile::didExecute(const CallIdentifier& callIdentifier)
{
if (!m_currentNode)
return;
if (m_stoppedProfiling && m_stoppedCallDepth > 0) {
--m_stoppedCallDepth;
return;
}
if (m_currentNode == m_head) {
m_currentNode = ProfileNode::create(callIdentifier, m_head.get(), m_head.get());
m_currentNode->setStartTime(m_head->startTime());
m_currentNode->didExecute();
if (m_stoppedProfiling) {
m_currentNode->setTotalTime(m_head->totalTime());
m_currentNode->setSelfTime(m_head->selfTime());
m_head->setSelfTime(0.0);
}
m_head->insertNode(m_currentNode.release());
m_currentNode = m_stoppedProfiling ? 0 : m_head;
return;
}
// Set m_currentNode to the parent (which didExecute returns). If stopped, just set the
// m_currentNode to the parent and don't call didExecute.
m_currentNode = m_stoppedProfiling ? m_currentNode->parent() : m_currentNode->didExecute();
}
void Profile::forEach(void (ProfileNode::*function)())
{
ProfileNode* currentNode = m_head->firstChild();
......
......@@ -27,33 +27,24 @@
#define Profile_h
#include "ProfileNode.h"
#include <kjs/ustring.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
namespace KJS {
class ExecState;
class ProfilerClient;
class Profile : public RefCounted<Profile> {
public:
static PassRefPtr<Profile> create(const UString& title, ExecState* originatingGlobalExec, unsigned pageGroupIdentifier, ProfilerClient*);
static PassRefPtr<Profile> create(const UString& title);
virtual ~Profile();
void willExecute(const CallIdentifier&);
void didExecute(const CallIdentifier&);
void stopProfiling();
bool didFinishAllExecution();
const UString& title() const { return m_title; };
ProfileNode* callTree() const { return m_head.get(); };
const UString& title() const { return m_title; }
ProfileNode* callTree() const { return m_head.get(); }
void setHead(PassRefPtr<ProfileNode> head) { m_head = head; }
double totalTime() const { return m_head->totalTime(); }
ExecState* originatingGlobalExec() const { return m_originatingGlobalExec; }
unsigned pageGroupIdentifier() const { return m_pageGroupIdentifier; }
ProfilerClient* client() { return m_client; }
void forEach(void (ProfileNode::*)());
void sortTotalTimeDescending() { forEach(&ProfileNode::sortTotalTimeDescending); }
void sortTotalTimeAscending() { forEach(&ProfileNode::sortTotalTimeAscending); }
......@@ -64,12 +55,10 @@ namespace KJS {
void sortFunctionNameDescending() { forEach(&ProfileNode::sortFunctionNameDescending); }
void sortFunctionNameAscending() { forEach(&ProfileNode::sortFunctionNameAscending); }
void focus(const ProfileNode* profileNode);
void exclude(const ProfileNode* profileNode);
void focus(const ProfileNode*);
void exclude(const ProfileNode*);
void restoreAll();
bool stoppedProfiling() { return m_stoppedProfiling; }
virtual Profile* heavyProfile() = 0;
virtual Profile* treeProfile() = 0;
......@@ -77,25 +66,18 @@ namespace KJS {
void debugPrintData() const;
void debugPrintDataSampleStyle() const;
#endif
typedef void (Profile::*ProfileFunction)(const CallIdentifier& callIdentifier);
protected:
Profile(const UString& title, ExecState* originatingGlobalExec, unsigned pageGroupIdentifier, ProfilerClient*);
Profile(const UString& title);
private:
void removeProfileStart();
void removeProfileEnd();
UString m_title;
ExecState* m_originatingGlobalExec;
unsigned m_pageGroupIdentifier;
unsigned m_stoppedCallDepth;
RefPtr<ProfileNode> m_head;
RefPtr<ProfileNode> m_currentNode;
ProfilerClient* m_client;
bool m_stoppedProfiling;
};
} // namespace KJS
#endif // Profiler_h
#endif // Profile_h
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "ProfileGenerator.h"
#include "Profile.h"
#include "Profiler.h"
namespace KJS {
static const char* NonJSExecution = "(idle)";
PassRefPtr<ProfileGenerator> ProfileGenerator::create(const UString& title, ExecState* originatingGlobalExec, unsigned pageGroupIdentifier, ProfilerClient* client)
{
return adoptRef(new ProfileGenerator(title, originatingGlobalExec, pageGroupIdentifier, client));
}
ProfileGenerator::ProfileGenerator(const UString& title, ExecState* originatingGlobalExec, unsigned pageGroupIdentifier, ProfilerClient* client)
: m_originatingGlobalExec(originatingGlobalExec)
, m_pageGroupIdentifier(pageGroupIdentifier)
, m_client(client)
, m_stoppedProfiling(false)
, m_stoppedCallDepth(0)
{
m_profile = Profile::create(title);
m_currentNode = m_head = m_profile->callTree();
}
const UString& ProfileGenerator::title() const
{
return m_profile->title();
}
void ProfileGenerator::willExecute(const CallIdentifier& callIdentifier)
{
if (m_stoppedProfiling) {
++m_stoppedCallDepth;
return;
}
ASSERT(m_currentNode);
m_currentNode = m_currentNode->willExecute(callIdentifier);
}
void ProfileGenerator::didExecute(const CallIdentifier& callIdentifier)
{
if (!m_currentNode)
return;
if (m_stoppedProfiling && m_stoppedCallDepth > 0) {
--m_stoppedCallDepth;
return;
}
if (m_currentNode == m_head) {
m_currentNode = ProfileNode::create(callIdentifier, m_head.get(), m_head.get());
m_currentNode->setStartTime(m_head->startTime());
m_currentNode->didExecute();
if (m_stoppedProfiling) {
m_currentNode->setTotalTime(m_head->totalTime());
m_currentNode->setSelfTime(m_head->selfTime());
m_head->setSelfTime(0.0);
}
m_head->insertNode(m_currentNode.release());
m_currentNode = m_stoppedProfiling ? 0 : m_head;
return;
}
// Set m_currentNode to the parent (which didExecute returns). If stopped, just set the
// m_currentNode to the parent and don't call didExecute.
m_currentNode = m_stoppedProfiling ? m_currentNode->parent() : m_currentNode->didExecute();
}
void ProfileGenerator::stopProfiling()
{
m_profile->setHead(m_head.get());
m_profile->forEach(&ProfileNode::stopProfiling);
removeProfileStart();
removeProfileEnd();
ASSERT(m_currentNode);
// Set the current node to the parent, because we are in a call that
// will not get didExecute call.
m_currentNode = m_currentNode->parent();
m_stoppedProfiling = true;
}
bool ProfileGenerator::didFinishAllExecution()
{
if (!m_stoppedProfiling)
return false;
if (double headSelfTime = m_head->selfTime()) {
RefPtr<ProfileNode> idleNode = ProfileNode::create(CallIdentifier(NonJSExecution, 0, 0), m_head.get(), m_head.get());
idleNode->setTotalTime(headSelfTime);
idleNode->setSelfTime(headSelfTime);
idleNode->setVisible(true);
m_head->setSelfTime(0.0);
m_head->addChild(idleNode.release());
}
m_currentNode = 0;
m_originatingGlobalExec = 0;
m_profile->setHead(m_head.release());
return true;
}
// The console.ProfileGenerator that started this ProfileGenerator will be the first child.
void ProfileGenerator::removeProfileStart()
{
ProfileNode* currentNode = 0;
for (ProfileNode* next = m_head.get(); next; next = next->firstChild())
currentNode = next;
if (currentNode->callIdentifier().m_name != "profile")
return;
// Increment m_stoppedCallDepth to account for didExecute not being called for console.ProfileGenerator.
++m_stoppedCallDepth;
// Attribute the time of the node aobut to be removed to the self time of its parent
currentNode->parent()->setSelfTime(currentNode->parent()->selfTime() + currentNode->totalTime());
ASSERT(currentNode->callIdentifier() == (currentNode->parent()->children()[0])->callIdentifier());
currentNode->parent()->removeChild(0);
}
// The console.ProfileGeneratorEnd that stopped this ProfileGenerator will be the last child.
void ProfileGenerator::removeProfileEnd()
{
ProfileNode* currentNode = 0;
for (ProfileNode* next = m_head.get(); next; next = next->lastChild())
currentNode = next;
if (currentNode->callIdentifier().m_name != "profileEnd")
return;
// Attribute the time of the node aobut to be removed to the self time of its parent
currentNode->parent()->setSelfTime(currentNode->parent()->selfTime() + currentNode->totalTime());
ASSERT(currentNode->callIdentifier() == (currentNode->parent()->children()[currentNode->parent()->children().size() - 1])->callIdentifier());
currentNode->parent()->removeChild(currentNode->parent()->children().size() - 1);
}
} // namespace KJS
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ProfileGenerator_h
#define ProfileGenerator_h
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
namespace KJS {
class CallIdentifier;
class ExecState;
class Profile;
class ProfileNode;
class ProfilerClient;
class UString;
class ProfileGenerator : public RefCounted<ProfileGenerator> {
public:
static PassRefPtr<ProfileGenerator> create(const UString& title, ExecState* originatingGlobalExec, unsigned pageGroupIdentifier, ProfilerClient*);
// Members
const UString& title() const;
PassRefPtr<Profile> profile() const { return m_profile; }
ExecState* originatingGlobalExec() const { return m_originatingGlobalExec; }
unsigned pageGroupIdentifier() const { return m_pageGroupIdentifier; }
ProfilerClient* client() { return m_client; }
bool stoppedProfiling() { return m_stoppedProfiling; }
// Collecting
void willExecute(const CallIdentifier&);
void didExecute(const CallIdentifier&);
// Stopping Profiling
void stopProfiling();
bool didFinishAllExecution();
typedef void (ProfileGenerator::*ProfileFunction)(const CallIdentifier& callIdentifier);
private:
ProfileGenerator(const UString& title, ExecState* originatingGlobalExec, unsigned pageGroupIdentifier, ProfilerClient*);
void removeProfileStart();
void removeProfileEnd();
RefPtr<Profile> m_profile;
ExecState* m_originatingGlobalExec;
unsigned m_pageGroupIdentifier;
ProfilerClient* m_client;
RefPtr<ProfileNode> m_head;
RefPtr<ProfileNode> m_currentNode;
// Stopping Profiling
bool m_stoppedProfiling;
unsigned m_stoppedCallDepth;
};
} // namespace KJS