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

2008-05-13 Kevin McCullough <kmccullough@apple.com>

        Reviewed by Sam.

        <rdar://problem/5770054> JavaScript profiler (10928)
        - Made some functions static (as per Adam) and changed from using raw
        pointers to RefPtr for making these JavaScript Objects.

        * profiler/FunctionCallProfile.cpp:
        (KJS::FunctionCallProfile::addChild):
        (KJS::FunctionCallProfile::findChild):
        * profiler/FunctionCallProfile.h:
        (KJS::FunctionCallProfile::create):
        * profiler/Profile.cpp:
        (KJS::Profile::Profile):
        (KJS::Profile::willExecute):
        (KJS::Profile::didExecute):
        (KJS::functionNameCountPairComparator):
        * profiler/Profile.h:
        (KJS::Profile::create):
        (KJS::Profile::title):
        (KJS::Profile::callTree):
        * profiler/Profiler.cpp:
        (KJS::Profiler::startProfiling):
        * profiler/Profiler.h:
        (KJS::Profiler::allProfiles):
        (KJS::Profiler::clearProfiles):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@33382 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 8664726f
2008-05-13 Kevin McCullough <kmccullough@apple.com>
Reviewed by Sam.
<rdar://problem/5770054> JavaScript profiler (10928)
- Made some functions static (as per Adam) and changed from using raw
pointers to RefPtr for making these JavaScript Objects.
* profiler/FunctionCallProfile.cpp:
(KJS::FunctionCallProfile::addChild):
(KJS::FunctionCallProfile::findChild):
* profiler/FunctionCallProfile.h:
(KJS::FunctionCallProfile::create):
* profiler/Profile.cpp:
(KJS::Profile::Profile):
(KJS::Profile::willExecute):
(KJS::Profile::didExecute):
(KJS::functionNameCountPairComparator):
* profiler/Profile.h:
(KJS::Profile::create):
(KJS::Profile::title):
(KJS::Profile::callTree):
* profiler/Profiler.cpp:
(KJS::Profiler::startProfiling):
* profiler/Profiler.h:
(KJS::Profiler::allProfiles):
(KJS::Profiler::clearProfiles):
2008-05-13 Alexey Proskuryakov <ap@webkit.org>
Reviewed by Geoffrey Garen.
......
......@@ -44,12 +44,6 @@ FunctionCallProfile::FunctionCallProfile(const UString& name)
m_startTime = getCurrentUTCTime();
}
FunctionCallProfile::~FunctionCallProfile()
{
deleteAllValues(m_children);
}
void FunctionCallProfile::willExecute()
{
m_startTime = getCurrentUTCTime();
......@@ -71,7 +65,7 @@ void FunctionCallProfile::didExecute(Vector<UString> stackNames, unsigned int st
}
}
void FunctionCallProfile::addChild(FunctionCallProfile* child)
void FunctionCallProfile::addChild(RefPtr<FunctionCallProfile>& child)
{
if (!child)
return;
......@@ -88,7 +82,7 @@ FunctionCallProfile* FunctionCallProfile::findChild(const UString& name)
{
for (StackIterator currentChild = m_children.begin(); currentChild != m_children.end(); ++currentChild) {
if ((*currentChild)->functionName() == name)
return *currentChild;
return (*currentChild).get();
}
return 0;
......
......@@ -31,24 +31,25 @@
#include <kjs/ustring.h>
#include <wtf/Deque.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#include <wtf/StrHash.h>
namespace KJS {
class FunctionCallProfile;
typedef Deque<FunctionCallProfile*>::const_iterator StackIterator;
typedef Deque<RefPtr<FunctionCallProfile> >::const_iterator StackIterator;
typedef HashCountedSet<UString::Rep*> FunctionCallHashCount;
class FunctionCallProfile {
class FunctionCallProfile : public RefCounted<FunctionCallProfile> {
public:
FunctionCallProfile(const UString& name);
~FunctionCallProfile();
static PassRefPtr<FunctionCallProfile> create(const UString& name) { return adoptRef(new FunctionCallProfile(name)); }
void willExecute();
void didExecute(Vector<UString> stackNames, unsigned int stackIndex);
void addChild(FunctionCallProfile* child);
void addChild(RefPtr<FunctionCallProfile>& child);
FunctionCallProfile* findChild(const UString& name);
void stopProfiling();
......@@ -56,11 +57,14 @@ namespace KJS {
UString functionName() const { return m_functionName; }
double milliSecs() const { return m_timeSum; }
unsigned numberOfCalls() const { return m_numberOfCalls; }
const Deque<RefPtr<FunctionCallProfile> >& children() { return m_children; }
void printDataInspectorStyle(int indentLevel) const;
double printDataSampleStyle(int indentLevel, FunctionCallHashCount&) const;
private:
FunctionCallProfile(const UString& name);
void endAndRecordCall();
UString m_functionName;
......@@ -68,7 +72,7 @@ namespace KJS {
double m_startTime;
unsigned m_numberOfCalls;
Deque<FunctionCallProfile*> m_children;
Deque<RefPtr<FunctionCallProfile> > m_children;
};
} // namespace KJS
......
......@@ -42,13 +42,13 @@ Profile::Profile(const UString& title)
{
// 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_callTree.set(new FunctionCallProfile("Thread_1"));
m_callTree = FunctionCallProfile::create("Thread_1");
}
void Profile::willExecute(const Vector<UString>& callStackNames)
{
FunctionCallProfile* callTreeInsertionPoint = 0;
FunctionCallProfile* foundNameInTree = m_callTree.get();
RefPtr<FunctionCallProfile> callTreeInsertionPoint;
RefPtr<FunctionCallProfile> foundNameInTree = m_callTree;
NameIterator callStackLocation = callStackNames.begin();
while (callStackLocation != callStackNames.end() && foundNameInTree) {
......@@ -59,8 +59,8 @@ void Profile::willExecute(const Vector<UString>& callStackNames)
if (!foundNameInTree) { // Insert remains of the stack into the call tree.
--callStackLocation;
for (FunctionCallProfile* next; callStackLocation != callStackNames.end(); ++callStackLocation) {
next = new FunctionCallProfile(*callStackLocation);
for (RefPtr<FunctionCallProfile> next; callStackLocation != callStackNames.end(); ++callStackLocation) {
next = FunctionCallProfile::create(*callStackLocation);
callTreeInsertionPoint->addChild(next);
callTreeInsertionPoint = next;
}
......@@ -68,7 +68,7 @@ void Profile::willExecute(const Vector<UString>& callStackNames)
foundNameInTree->willExecute();
}
void Profile::didExecute(Vector<UString> stackNames)
void Profile::didExecute(const Vector<UString>& stackNames)
{
m_callTree->didExecute(stackNames, 0);
}
......@@ -81,7 +81,7 @@ void Profile::printDataInspectorStyle() const
typedef pair<UString::Rep*, unsigned> NameCountPair;
static inline bool functionNameCountPairComparator(const NameCountPair a, const NameCountPair b)
static inline bool functionNameCountPairComparator(const NameCountPair& a, const NameCountPair& b)
{
return a.second > b.second;
}
......
......@@ -27,7 +27,8 @@
#define Profile_h
#include "FunctionCallProfile.h"
#include <wtf/OwnPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
namespace KJS {
......@@ -35,24 +36,28 @@ namespace KJS {
class FunctionImp;
class JSObject;
class Profile {
class Profile : public RefCounted<Profile> {
public:
Profile(const UString& title);
static PassRefPtr<Profile> create(const UString& title) { return adoptRef(new Profile(title)); }
void willExecute(const Vector<UString>& callStackNames);
void didExecute(Vector<UString> stackNames);
void didExecute(const Vector<UString>& stackNames);
void stopProfiling() { m_callTree->stopProfiling(); };
const UString& title() const { return m_title; };
RefPtr<FunctionCallProfile> callTree() const { return m_callTree; };
void printDataInspectorStyle() const;
void printDataSampleStyle() const;
private:
const UString& m_title;
Profile(const UString& title);
UString m_title;
void insertStackNamesInTree(const Vector<UString>& callStackNames);
OwnPtr<FunctionCallProfile> m_callTree;
RefPtr<FunctionCallProfile> m_callTree;
};
} // namespace KJS
......
......@@ -61,7 +61,7 @@ void Profiler::startProfiling(unsigned pageGroupIdentifier, const UString& title
m_pageGroupIdentifier = pageGroupIdentifier;
m_currentProfile.set(new Profile(title));
m_currentProfile = Profile::create(title);
m_profiling = true;
}
......
......@@ -30,7 +30,7 @@
#define Profiler_h
#include "Profile.h"
#include <wtf/OwnPtr.h>
#include <wtf/RefPtr.h>
namespace KJS {
......@@ -43,8 +43,6 @@ namespace KJS {
static Profiler* profiler();
static void debugLog(UString);
~Profiler() { deleteAllValues(m_allProfiles); }
void startProfiling(unsigned pageGroupIdentifier, const UString&);
void stopProfiling();
......@@ -53,8 +51,8 @@ namespace KJS {
void didExecute(ExecState*, JSObject* calledFunction);
void didExecute(ExecState*, const UString& sourceURL, int startingLineNumber);
Vector<Profile*>& allProfiles() { return m_allProfiles; };
void clearProfiles() { if (!m_profiling) deleteAllValues(m_allProfiles); };
const Vector<RefPtr<Profile> >& allProfiles() { return m_allProfiles; };
void clearProfiles() { if (!m_profiling) m_allProfiles.clear(); };
void printDataInspectorStyle(unsigned whichProfile) const;
void printDataSampleStyle(unsigned whichProfile) const;
......@@ -69,8 +67,8 @@ namespace KJS {
bool m_profiling;
unsigned m_pageGroupIdentifier;
OwnPtr<Profile> m_currentProfile;
Vector<Profile*> m_allProfiles;
RefPtr<Profile> m_currentProfile;
Vector<RefPtr<Profile> > m_allProfiles;
};
} // namespace KJS
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment