Commit 6f24f536 authored by kmccullough@apple.com's avatar kmccullough@apple.com

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

        Reviewed by Adam.

        <rdar://problem/5950538> JSProfiler: Keep track of non-JS execution time
        We now have an extra node that represents the excess non-JS time.
        - Also changed "SCRIPT" and "anonymous function" to be more consistent
        with the debugger.

        * profiler/ProfileNode.cpp:
        (KJS::ProfileNode::stopProfiling): If this ProfileNode is the head node
        create a new child that has the excess execution time.
        (KJS::ProfileNode::calculatePercentages): Moved calculation of the
        percentages into a function since it's called from multiple places.
        * profiler/ProfileNode.h: Add the newly needed functions used above.
        (KJS::ProfileNode::setTotalTime):
        (KJS::ProfileNode::setSelfTime):
        (KJS::ProfileNode::setNumberOfCalls):
        * profiler/Profiler.cpp: renamed "SCRIPT" and "anonymous function" to be
        consistent with the debugger and use constants that can be localized
        more easily.
        (KJS::getCallIdentifiers):
        (KJS::getCallIdentifierFromFunctionImp):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@33945 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0be4b5e5
2008-05-20 Kevin McCullough <kmccullough@apple.com>
Reviewed by Adam.
<rdar://problem/5950538> JSProfiler: Keep track of non-JS execution time
We now have an extra node that represents the excess non-JS time.
- Also changed "SCRIPT" and "anonymous function" to be more consistent
with the debugger.
* profiler/ProfileNode.cpp:
(KJS::ProfileNode::stopProfiling): If this ProfileNode is the head node
create a new child that has the excess execution time.
(KJS::ProfileNode::calculatePercentages): Moved calculation of the
percentages into a function since it's called from multiple places.
* profiler/ProfileNode.h: Add the newly needed functions used above.
(KJS::ProfileNode::setTotalTime):
(KJS::ProfileNode::setSelfTime):
(KJS::ProfileNode::setNumberOfCalls):
* profiler/Profiler.cpp: renamed "SCRIPT" and "anonymous function" to be
consistent with the debugger and use constants that can be localized
more easily.
(KJS::getCallIdentifiers):
(KJS::getCallIdentifierFromFunctionImp):
2008-05-20 Kevin McCullough <kmccullough@apple.com>
Reviewed by Tim.
......
......@@ -36,6 +36,8 @@
namespace KJS {
static const char* NonJSExecution = "(non-JavaScript)";
ProfileNode::ProfileNode(const CallIdentifier& callIdentifier)
: m_callIdentifier(callIdentifier)
, m_totalTime (0.0)
......@@ -112,8 +114,19 @@ void ProfileNode::stopProfiling(double totalProfileTime, bool headProfileNode)
ASSERT(m_selfTime <= m_totalTime);
m_selfTime = m_totalTime - m_selfTime;
m_totalPercent = (m_totalTime / totalProfileTime) * 100.0;
m_selfPercent = (m_selfTime / totalProfileTime) * 100.0;
if (headProfileNode && m_selfTime) {
RefPtr<ProfileNode> idleNode = ProfileNode::create(CallIdentifier(NonJSExecution, 0, 0));
idleNode->setTotalTime(m_selfTime);
idleNode->setSelfTime(m_selfTime);
idleNode->setNumberOfCalls(0);
idleNode->calculatePercentages(totalProfileTime);
addChild(idleNode.release());
m_selfTime = 0.0;
}
calculatePercentages(totalProfileTime);
}
#pragma mark Sorting methods
......@@ -230,6 +243,13 @@ void ProfileNode::endAndRecordCall()
++m_numberOfCalls;
}
void ProfileNode::calculatePercentages(double totalProfileTime)
{
m_totalPercent = (m_totalTime / totalProfileTime) * 100.0;
m_selfPercent = (m_selfTime / totalProfileTime) * 100.0;
}
void ProfileNode::printDataInspectorStyle(int indentLevel) const
{
// Print function names
......
......@@ -71,10 +71,13 @@ namespace KJS {
unsigned lineNumber() const { return m_callIdentifier.lineNumber; }
double totalTime() const { return m_totalTime; }
void setTotalTime(double time) { m_totalTime = time; }
double selfTime() const { return m_selfTime; }
void setSelfTime(double time) { m_selfTime = time; }
double totalPercent() const { return m_totalPercent; }
double selfPercent() const { return m_selfPercent; }
unsigned numberOfCalls() const { return m_numberOfCalls; }
void setNumberOfCalls(unsigned number) { m_numberOfCalls = number; }
const Vector<RefPtr<ProfileNode> >& children() { return m_children; }
// Sorting functions
......@@ -89,6 +92,8 @@ namespace KJS {
void endAndRecordCall();
void calculatePercentages(double totalProfileTime);
void printDataInspectorStyle(int indentLevel) const;
double printDataSampleStyle(int indentLevel, FunctionCallHashCount&) const;
......
......@@ -40,7 +40,8 @@
namespace KJS {
static Profiler* sharedProfiler = 0;
static const char* Script = "[SCRIPT] ";
static const char* GlobalCodeExecution = "(global code)";
static const char* AnonymousFunction = "(anonymous function)";
static void getCallIdentifiers(ExecState*, Vector<CallIdentifier>& callIdentifiers);
static void getCallIdentifiers(ExecState*, JSObject*, Vector<CallIdentifier>& callIdentifiers);
......@@ -145,7 +146,7 @@ void getCallIdentifiers(ExecState* exec, Vector<CallIdentifier>& callIdentifiers
if (FunctionImp* functionImp = currentState->function())
getCallIdentifierFromFunctionImp(functionImp, callIdentifiers);
else if (ScopeNode* scopeNode = currentState->scopeNode())
callIdentifiers.append(CallIdentifier(Script, scopeNode->sourceURL(), (scopeNode->lineNo() + 1)) ); // FIXME: Why is the line number always off by one?
callIdentifiers.append(CallIdentifier(GlobalCodeExecution, scopeNode->sourceURL(), (scopeNode->lineNo() + 1)) ); // FIXME: Why is the line number always off by one?
}
}
......@@ -160,7 +161,7 @@ void getCallIdentifiers(ExecState* exec, JSObject* calledFunction, Vector<CallId
void getCallIdentifiers(ExecState* exec, const UString& sourceURL, int startingLineNumber, Vector<CallIdentifier>& callIdentifiers)
{
callIdentifiers.append(CallIdentifier(Script, sourceURL, (startingLineNumber + 1)) );
callIdentifiers.append(CallIdentifier(GlobalCodeExecution, sourceURL, (startingLineNumber + 1)) );
getCallIdentifiers(exec, callIdentifiers);
}
......@@ -168,7 +169,7 @@ void getCallIdentifierFromFunctionImp(FunctionImp* functionImp, Vector<CallIdent
{
UString name = functionImp->functionName().ustring();
if (name.isEmpty())
name = "[anonymous function]";
name = AnonymousFunction;
callIdentifiers.append(CallIdentifier(name, functionImp->body->sourceURL(), functionImp->body->lineNo()) );
}
......
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