Commit bf3b5969 authored by eric@webkit.org's avatar eric@webkit.org

2009-10-26 Kelly Norton <knorton@google.com>

        Reviewed by Pavel Feldman.

        Adds DOMTimer support to InspectorTimelineAgent.
        https://bugs.webkit.org/show_bug.cgi?id=30467

        * inspector/InspectorTimelineAgent.cpp: Added timer support and fixed some method names.
        (WebCore::InspectorTimelineAgent::didDispatchDOMEvent):
        (WebCore::InspectorTimelineAgent::didLayout):
        (WebCore::InspectorTimelineAgent::didRecalculateStyle):
        (WebCore::InspectorTimelineAgent::didPaint):
        (WebCore::InspectorTimelineAgent::didWriteHTML):
        (WebCore::InspectorTimelineAgent::didInstallTimer): Added.
        (WebCore::InspectorTimelineAgent::didRemoveTimer): Added.
        (WebCore::InspectorTimelineAgent::willFireTimer): Added.
        (WebCore::InspectorTimelineAgent::didFireTimer): Added.
        (WebCore::InspectorTimelineAgent::addItemToTimeline): Added.
        (WebCore::InspectorTimelineAgent::didCompleteCurrentTimelineItem): Renamed.
        * inspector/InspectorTimelineAgent.h:
        (WebCore::):
        * inspector/TimelineItemFactory.cpp: Add methods for timer-related ScriptObjects.
        (WebCore::TimelineItemFactory::createGenericTimerTimelineItem):
        (WebCore::TimelineItemFactory::createTimerInstallTimelineItem):
        * inspector/TimelineItemFactory.h:
        * page/DOMTimer.cpp: Added instrumentation points.
        (WebCore::DOMTimer::install):
        (WebCore::DOMTimer::removeById):
        (WebCore::DOMTimer::fired):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@50068 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 8110a530
2009-10-26 Kelly Norton <knorton@google.com>
Reviewed by Pavel Feldman.
Adds DOMTimer support to InspectorTimelineAgent.
https://bugs.webkit.org/show_bug.cgi?id=30467
* inspector/InspectorTimelineAgent.cpp: Added timer support and fixed some method names.
(WebCore::InspectorTimelineAgent::didDispatchDOMEvent):
(WebCore::InspectorTimelineAgent::didLayout):
(WebCore::InspectorTimelineAgent::didRecalculateStyle):
(WebCore::InspectorTimelineAgent::didPaint):
(WebCore::InspectorTimelineAgent::didWriteHTML):
(WebCore::InspectorTimelineAgent::didInstallTimer): Added.
(WebCore::InspectorTimelineAgent::didRemoveTimer): Added.
(WebCore::InspectorTimelineAgent::willFireTimer): Added.
(WebCore::InspectorTimelineAgent::didFireTimer): Added.
(WebCore::InspectorTimelineAgent::addItemToTimeline): Added.
(WebCore::InspectorTimelineAgent::didCompleteCurrentTimelineItem): Renamed.
* inspector/InspectorTimelineAgent.h:
(WebCore::):
* inspector/TimelineItemFactory.cpp: Add methods for timer-related ScriptObjects.
(WebCore::TimelineItemFactory::createGenericTimerTimelineItem):
(WebCore::TimelineItemFactory::createTimerInstallTimelineItem):
* inspector/TimelineItemFactory.h:
* page/DOMTimer.cpp: Added instrumentation points.
(WebCore::DOMTimer::install):
(WebCore::DOMTimer::removeById):
(WebCore::DOMTimer::fired):
2009-10-26 Simon Fraser <simon.fraser@apple.com> 2009-10-26 Simon Fraser <simon.fraser@apple.com>
Reviewed by Sam Weinig. Reviewed by Sam Weinig.
...@@ -58,7 +58,7 @@ void InspectorTimelineAgent::willDispatchDOMEvent(const Event& event) ...@@ -58,7 +58,7 @@ void InspectorTimelineAgent::willDispatchDOMEvent(const Event& event)
void InspectorTimelineAgent::didDispatchDOMEvent() void InspectorTimelineAgent::didDispatchDOMEvent()
{ {
didCompleteCurrentRecord(DOMDispatchTimelineItemType); didCompleteCurrentTimelineItem(DOMDispatchTimelineItemType);
} }
void InspectorTimelineAgent::willLayout() void InspectorTimelineAgent::willLayout()
...@@ -68,7 +68,7 @@ void InspectorTimelineAgent::willLayout() ...@@ -68,7 +68,7 @@ void InspectorTimelineAgent::willLayout()
void InspectorTimelineAgent::didLayout() void InspectorTimelineAgent::didLayout()
{ {
didCompleteCurrentRecord(LayoutTimelineItemType); didCompleteCurrentTimelineItem(LayoutTimelineItemType);
} }
void InspectorTimelineAgent::willRecalculateStyle() void InspectorTimelineAgent::willRecalculateStyle()
...@@ -78,7 +78,7 @@ void InspectorTimelineAgent::willRecalculateStyle() ...@@ -78,7 +78,7 @@ void InspectorTimelineAgent::willRecalculateStyle()
void InspectorTimelineAgent::didRecalculateStyle() void InspectorTimelineAgent::didRecalculateStyle()
{ {
didCompleteCurrentRecord(RecalculateStylesTimelineItemType); didCompleteCurrentTimelineItem(RecalculateStylesTimelineItemType);
} }
void InspectorTimelineAgent::willPaint() void InspectorTimelineAgent::willPaint()
...@@ -88,7 +88,7 @@ void InspectorTimelineAgent::willPaint() ...@@ -88,7 +88,7 @@ void InspectorTimelineAgent::willPaint()
void InspectorTimelineAgent::didPaint() void InspectorTimelineAgent::didPaint()
{ {
didCompleteCurrentRecord(PaintTimelineItemType); didCompleteCurrentTimelineItem(PaintTimelineItemType);
} }
void InspectorTimelineAgent::willWriteHTML() void InspectorTimelineAgent::willWriteHTML()
...@@ -98,7 +98,30 @@ void InspectorTimelineAgent::willWriteHTML() ...@@ -98,7 +98,30 @@ void InspectorTimelineAgent::willWriteHTML()
void InspectorTimelineAgent::didWriteHTML() void InspectorTimelineAgent::didWriteHTML()
{ {
didCompleteCurrentRecord(ParseHTMLTimelineItemType); didCompleteCurrentTimelineItem(ParseHTMLTimelineItemType);
}
void InspectorTimelineAgent::didInstallTimer(int timerId, int timeout, bool singleShot)
{
addItemToTimeline(TimelineItemFactory::createTimerInstallTimelineItem(m_frontend, currentTimeInMilliseconds(), timerId,
timeout, singleShot), TimerInstallTimelineItemType);
}
void InspectorTimelineAgent::didRemoveTimer(int timerId)
{
addItemToTimeline(TimelineItemFactory::createGenericTimerTimelineItem(m_frontend, currentTimeInMilliseconds(), timerId),
TimerRemoveTimelineItemType);
}
void InspectorTimelineAgent::willFireTimer(int timerId)
{
pushCurrentTimelineItem(TimelineItemFactory::createGenericTimerTimelineItem(m_frontend, currentTimeInMilliseconds(), timerId),
TimerFireTimelineItemType);
}
void InspectorTimelineAgent::didFireTimer()
{
didCompleteCurrentTimelineItem(TimerFireTimelineItemType);
} }
void InspectorTimelineAgent::reset() void InspectorTimelineAgent::reset()
...@@ -106,21 +129,26 @@ void InspectorTimelineAgent::reset() ...@@ -106,21 +129,26 @@ void InspectorTimelineAgent::reset()
m_itemStack.clear(); m_itemStack.clear();
} }
void InspectorTimelineAgent::didCompleteCurrentRecord(TimelineItemType type) void InspectorTimelineAgent::addItemToTimeline(ScriptObject item, TimelineItemType type)
{
item.set("type", type);
if (m_itemStack.isEmpty())
m_frontend->addItemToTimeline(item);
else {
TimelineItemEntry parent = m_itemStack.last();
parent.children.set(parent.children.length(), item);
}
}
void InspectorTimelineAgent::didCompleteCurrentTimelineItem(TimelineItemType type)
{ {
ASSERT(!m_itemStack.isEmpty());
TimelineItemEntry entry = m_itemStack.last(); TimelineItemEntry entry = m_itemStack.last();
m_itemStack.removeLast(); m_itemStack.removeLast();
ASSERT(entry.type == type); ASSERT(entry.type == type);
entry.item.set("type", type);
entry.item.set("children", entry.children); entry.item.set("children", entry.children);
entry.item.set("endTime", currentTimeInMilliseconds()); entry.item.set("endTime", currentTimeInMilliseconds());
addItemToTimeline(entry.item, type);
if (m_itemStack.isEmpty()) {
m_frontend->addItemToTimeline(entry.item);
} else {
TimelineItemEntry parent = m_itemStack.last();
parent.children.set(parent.children.length(), entry.item);
}
} }
double InspectorTimelineAgent::currentTimeInMilliseconds() double InspectorTimelineAgent::currentTimeInMilliseconds()
......
...@@ -31,9 +31,10 @@ ...@@ -31,9 +31,10 @@
#ifndef InspectorTimelineAgent_h #ifndef InspectorTimelineAgent_h
#define InspectorTimelineAgent_h #define InspectorTimelineAgent_h
#include "Document.h"
#include "ScriptExecutionContext.h"
#include "ScriptObject.h" #include "ScriptObject.h"
#include "ScriptArray.h" #include "ScriptArray.h"
#include <wtf/Vector.h> #include <wtf/Vector.h>
namespace WebCore { namespace WebCore {
...@@ -47,6 +48,9 @@ namespace WebCore { ...@@ -47,6 +48,9 @@ namespace WebCore {
RecalculateStylesTimelineItemType = 2, RecalculateStylesTimelineItemType = 2,
PaintTimelineItemType = 3, PaintTimelineItemType = 3,
ParseHTMLTimelineItemType = 4, ParseHTMLTimelineItemType = 4,
TimerInstallTimelineItemType = 5,
TimerRemoveTimelineItemType = 6,
TimerFireTimelineItemType = 7,
}; };
class InspectorTimelineAgent { class InspectorTimelineAgent {
...@@ -59,15 +63,25 @@ namespace WebCore { ...@@ -59,15 +63,25 @@ namespace WebCore {
// Methods called from WebCore. // Methods called from WebCore.
void willDispatchDOMEvent(const Event&); void willDispatchDOMEvent(const Event&);
void didDispatchDOMEvent(); void didDispatchDOMEvent();
void willLayout(); void willLayout();
void didLayout(); void didLayout();
void willRecalculateStyle(); void willRecalculateStyle();
void didRecalculateStyle(); void didRecalculateStyle();
void willPaint(); void willPaint();
void didPaint(); void didPaint();
void didWriteHTML();
void willWriteHTML(); void willWriteHTML();
void didWriteHTML();
void didInstallTimer(int timerId, int timeout, bool singleShot);
void didRemoveTimer(int timerId);
void willFireTimer(int timerId);
void didFireTimer();
static InspectorTimelineAgent* retrieve(ScriptExecutionContext*);
private: private:
struct TimelineItemEntry { struct TimelineItemEntry {
TimelineItemEntry(ScriptObject item, ScriptArray children, TimelineItemType type) : item(item), children(children), type(type) { } TimelineItemEntry(ScriptObject item, ScriptArray children, TimelineItemType type) : item(item), children(children), type(type) { }
...@@ -80,13 +94,22 @@ namespace WebCore { ...@@ -80,13 +94,22 @@ namespace WebCore {
static double currentTimeInMilliseconds(); static double currentTimeInMilliseconds();
void didCompleteCurrentRecord(TimelineItemType); void didCompleteCurrentTimelineItem(TimelineItemType);
void addItemToTimeline(ScriptObject, TimelineItemType);
InspectorFrontend* m_frontend; InspectorFrontend* m_frontend;
Vector< TimelineItemEntry > m_itemStack; Vector< TimelineItemEntry > m_itemStack;
}; };
inline InspectorTimelineAgent* InspectorTimelineAgent::retrieve(ScriptExecutionContext* context)
{
if (context->isDocument())
return static_cast<Document*>(context)->inspectorTimelineAgent();
return 0;
}
} // namespace WebCore } // namespace WebCore
#endif // !defined(InspectorTimelineAgent_h) #endif // !defined(InspectorTimelineAgent_h)
...@@ -57,6 +57,28 @@ ScriptObject TimelineItemFactory::createDOMDispatchTimelineItem(InspectorFronten ...@@ -57,6 +57,28 @@ ScriptObject TimelineItemFactory::createDOMDispatchTimelineItem(InspectorFronten
return item; return item;
} }
// static
ScriptObject TimelineItemFactory::createGenericTimerTimelineItem(InspectorFrontend* frontend, double startTime, int timerId)
{
ScriptObject item = createGenericTimelineItem(frontend, startTime);
ScriptObject data = frontend->newScriptObject();
data.set("timerId", timerId);
item.set("data", data);
return item;
}
// static
ScriptObject TimelineItemFactory::createTimerInstallTimelineItem(InspectorFrontend* frontend, double startTime, int timerId, int timeout, bool singleShot)
{
ScriptObject item = createGenericTimelineItem(frontend, startTime);
ScriptObject data = frontend->newScriptObject();
data.set("timerId", timerId);
data.set("timeout", timeout);
data.set("singleShot", singleShot);
item.set("data", data);
return item;
}
} // namespace WebCore } // namespace WebCore
#endif // ENABLE(INSPECTOR) #endif // ENABLE(INSPECTOR)
...@@ -42,6 +42,11 @@ namespace WebCore { ...@@ -42,6 +42,11 @@ namespace WebCore {
static ScriptObject createGenericTimelineItem(InspectorFrontend*, double startTime); static ScriptObject createGenericTimelineItem(InspectorFrontend*, double startTime);
static ScriptObject createDOMDispatchTimelineItem(InspectorFrontend*, double startTime, const Event&); static ScriptObject createDOMDispatchTimelineItem(InspectorFrontend*, double startTime, const Event&);
static ScriptObject createGenericTimerTimelineItem(InspectorFrontend*, double startTime, int timerId);
static ScriptObject createTimerInstallTimelineItem(InspectorFrontend*, double startTime, int timerId, int timeout, bool singleShot);
private: private:
TimelineItemFactory() { } TimelineItemFactory() { }
}; };
......
...@@ -38,7 +38,10 @@ WebInspector.TimelineAgent.ItemType = { ...@@ -38,7 +38,10 @@ WebInspector.TimelineAgent.ItemType = {
Layout : 1, Layout : 1,
RecalculateStyles : 2, RecalculateStyles : 2,
Paint : 3, Paint : 3,
ParseHTML : 4 ParseHTML : 4,
TimerInstall : 5,
TimerRemove : 6,
TimerFire : 7,
}; };
WebInspector.addItemToTimeline = function(record) { WebInspector.addItemToTimeline = function(record) {
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "config.h" #include "config.h"
#include "DOMTimer.h" #include "DOMTimer.h"
#include "InspectorTimelineAgent.h"
#include "ScheduledAction.h" #include "ScheduledAction.h"
#include "ScriptExecutionContext.h" #include "ScriptExecutionContext.h"
#include <wtf/HashSet.h> #include <wtf/HashSet.h>
...@@ -87,6 +88,12 @@ int DOMTimer::install(ScriptExecutionContext* context, ScheduledAction* action, ...@@ -87,6 +88,12 @@ int DOMTimer::install(ScriptExecutionContext* context, ScheduledAction* action,
// The timer is deleted when context is deleted (DOMTimer::contextDestroyed) or explicitly via DOMTimer::removeById(), // The timer is deleted when context is deleted (DOMTimer::contextDestroyed) or explicitly via DOMTimer::removeById(),
// or if it is a one-time timer and it has fired (DOMTimer::fired). // or if it is a one-time timer and it has fired (DOMTimer::fired).
DOMTimer* timer = new DOMTimer(context, action, timeout, singleShot); DOMTimer* timer = new DOMTimer(context, action, timeout, singleShot);
#if ENABLE(INSPECTOR)
if (InspectorTimelineAgent* timelineAgent = InspectorTimelineAgent::retrieve(context))
timelineAgent->didInstallTimer(timer->m_timeoutId, timeout, singleShot);
#endif
return timer->m_timeoutId; return timer->m_timeoutId;
} }
...@@ -97,6 +104,12 @@ void DOMTimer::removeById(ScriptExecutionContext* context, int timeoutId) ...@@ -97,6 +104,12 @@ void DOMTimer::removeById(ScriptExecutionContext* context, int timeoutId)
// respectively // respectively
if (timeoutId <= 0) if (timeoutId <= 0)
return; return;
#if ENABLE(INSPECTOR)
if (InspectorTimelineAgent* timelineAgent = InspectorTimelineAgent::retrieve(context))
timelineAgent->didRemoveTimer(timeoutId);
#endif
delete context->findTimeout(timeoutId); delete context->findTimeout(timeoutId);
} }
...@@ -105,6 +118,12 @@ void DOMTimer::fired() ...@@ -105,6 +118,12 @@ void DOMTimer::fired()
ScriptExecutionContext* context = scriptExecutionContext(); ScriptExecutionContext* context = scriptExecutionContext();
timerNestingLevel = m_nestingLevel; timerNestingLevel = m_nestingLevel;
#if ENABLE(INSPECTOR)
InspectorTimelineAgent* timelineAgent = InspectorTimelineAgent::retrieve(context);
if (timelineAgent)
timelineAgent->willFireTimer(m_timeoutId);
#endif
// Simple case for non-one-shot timers. // Simple case for non-one-shot timers.
if (isActive()) { if (isActive()) {
if (repeatInterval() && repeatInterval() < s_minTimerInterval) { if (repeatInterval() && repeatInterval() < s_minTimerInterval) {
...@@ -115,6 +134,10 @@ void DOMTimer::fired() ...@@ -115,6 +134,10 @@ void DOMTimer::fired()
// No access to member variables after this point, it can delete the timer. // No access to member variables after this point, it can delete the timer.
m_action->execute(context); m_action->execute(context);
#if ENABLE(INSPECTOR)
if (timelineAgent)
timelineAgent->didFireTimer();
#endif
return; return;
} }
...@@ -125,6 +148,10 @@ void DOMTimer::fired() ...@@ -125,6 +148,10 @@ void DOMTimer::fired()
delete this; delete this;
action->execute(context); action->execute(context);
#if ENABLE(INSPECTOR)
if (timelineAgent)
timelineAgent->didFireTimer();
#endif
delete action; delete action;
timerNestingLevel = 0; timerNestingLevel = 0;
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
namespace WebCore { namespace WebCore {
class InspectorTimelineAgent;
class ScheduledAction; class ScheduledAction;
class DOMTimer : public TimerBase, public ActiveDOMObject { class DOMTimer : public TimerBase, public ActiveDOMObject {
......
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