From 833b19582dbbf5acd78c5a7ced103e993037dab7 Mon Sep 17 00:00:00 2001 From: "caseq@chromium.org" Date: Thu, 5 Jul 2012 16:13:48 +0000 Subject: [PATCH] Web Inspector: added low-level instrumentation support for TimelineAgent https://bugs.webkit.org/show_bug.cgi?id=90264 Patch by Sergey Rogulenko on 2012-07-05 Reviewed by Pavel Feldman. * inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::timelineAgentForOrphanEvents): (WebCore::InspectorInstrumentation::setTimelineAgentForOrphanEvents): (WebCore::InspectorInstrumentation::threadSpecificTimelineAgentForOrphanEvents): * inspector/InspectorInstrumentation.h: (InspectorInstrumentation): * inspector/InspectorTimelineAgent.cpp: (WebCore::InspectorTimelineAgent::didCompleteCurrentRecord): (WebCore::InspectorTimelineAgent::InspectorTimelineAgent): (WebCore::InspectorTimelineAgent::pushCurrentRecord): * inspector/InspectorTimelineAgent.h: (InspectorTimelineAgent): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@121908 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebCore/ChangeLog | 20 ++++++++++++++++++++ .../WebCore/inspector/InspectorInstrumentation.cpp | 17 +++++++++++++++++ Source/WebCore/inspector/InspectorInstrumentation.h | 4 ++++ Source/WebCore/inspector/InspectorTimelineAgent.cpp | 19 +++++++++++++++---- Source/WebCore/inspector/InspectorTimelineAgent.h | 3 ++- 5 files changed, 58 insertions(+), 5 deletions(-) diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 683e9c8..80ca8cd 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,23 @@ +2012-07-05 Sergey Rogulenko + + Web Inspector: added low-level instrumentation support for TimelineAgent + https://bugs.webkit.org/show_bug.cgi?id=90264 + + Reviewed by Pavel Feldman. + + * inspector/InspectorInstrumentation.cpp: + (WebCore::InspectorInstrumentation::timelineAgentForOrphanEvents): + (WebCore::InspectorInstrumentation::setTimelineAgentForOrphanEvents): + (WebCore::InspectorInstrumentation::threadSpecificTimelineAgentForOrphanEvents): + * inspector/InspectorInstrumentation.h: + (InspectorInstrumentation): + * inspector/InspectorTimelineAgent.cpp: + (WebCore::InspectorTimelineAgent::didCompleteCurrentRecord): + (WebCore::InspectorTimelineAgent::InspectorTimelineAgent): + (WebCore::InspectorTimelineAgent::pushCurrentRecord): + * inspector/InspectorTimelineAgent.h: + (InspectorTimelineAgent): + 2012-07-05 John Mellor Text Autosizing: Add test framework and simple test. diff --git a/Source/WebCore/inspector/InspectorInstrumentation.cpp b/Source/WebCore/inspector/InspectorInstrumentation.cpp index 78b0847..325a4c4 100644 --- a/Source/WebCore/inspector/InspectorInstrumentation.cpp +++ b/Source/WebCore/inspector/InspectorInstrumentation.cpp @@ -68,6 +68,7 @@ #include "WorkerThread.h" #include "XMLHttpRequest.h" #include +#include #include namespace WebCore { @@ -1136,6 +1137,22 @@ void InspectorInstrumentation::didFireAnimationFrameImpl(const InspectorInstrume timelineAgent->didFireAnimationFrame(); } +InspectorTimelineAgent* InspectorInstrumentation::timelineAgentForOrphanEvents() +{ + return *threadSpecificTimelineAgentForOrphanEvents(); +} + +void InspectorInstrumentation::setTimelineAgentForOrphanEvents(InspectorTimelineAgent* inspectorTimelineAgent) +{ + *threadSpecificTimelineAgentForOrphanEvents() = inspectorTimelineAgent; +} + +WTF::ThreadSpecific& InspectorInstrumentation::threadSpecificTimelineAgentForOrphanEvents() +{ + AtomicallyInitializedStatic(WTF::ThreadSpecific*, instance = new WTF::ThreadSpecific()); + return *instance; +} + InspectorTimelineAgent* InspectorInstrumentation::retrieveTimelineAgent(const InspectorInstrumentationCookie& cookie) { if (!cookie.first) diff --git a/Source/WebCore/inspector/InspectorInstrumentation.h b/Source/WebCore/inspector/InspectorInstrumentation.h index 6d17fd1..4350e9c 100644 --- a/Source/WebCore/inspector/InspectorInstrumentation.h +++ b/Source/WebCore/inspector/InspectorInstrumentation.h @@ -252,6 +252,8 @@ public: static bool hasFrontends() { return s_frontendCounter; } static bool hasFrontendForScriptContext(ScriptExecutionContext*); static bool collectingHTMLParseErrors(Page*); + static InspectorTimelineAgent* timelineAgentForOrphanEvents(); + static void setTimelineAgentForOrphanEvents(InspectorTimelineAgent*); #else static bool hasFrontends() { return false; } static bool hasFrontendForScriptContext(ScriptExecutionContext*) { return false; } @@ -260,6 +262,8 @@ public: private: #if ENABLE(INSPECTOR) + static WTF::ThreadSpecific& threadSpecificTimelineAgentForOrphanEvents(); + static void didClearWindowObjectInWorldImpl(InstrumentingAgents*, Frame*, DOMWrapperWorld*); static bool isDebuggerPausedImpl(InstrumentingAgents*); diff --git a/Source/WebCore/inspector/InspectorTimelineAgent.cpp b/Source/WebCore/inspector/InspectorTimelineAgent.cpp index 30ed7cd..b2634f2 100644 --- a/Source/WebCore/inspector/InspectorTimelineAgent.cpp +++ b/Source/WebCore/inspector/InspectorTimelineAgent.cpp @@ -40,6 +40,7 @@ #include "InspectorClient.h" #include "InspectorCounters.h" #include "InspectorFrontend.h" +#include "InspectorInstrumentation.h" #include "InspectorPageAgent.h" #include "InspectorState.h" #include "InstrumentingAgents.h" @@ -244,7 +245,7 @@ void InspectorTimelineAgent::didRecalculateStyle() void InspectorTimelineAgent::willPaint(const LayoutRect& rect, Frame* frame) { - pushCurrentRecord(TimelineRecordFactory::createPaintData(rect), TimelineRecordType::Paint, true, frame); + pushCurrentRecord(TimelineRecordFactory::createPaintData(rect), TimelineRecordType::Paint, true, frame, true); } void InspectorTimelineAgent::didPaint() @@ -320,7 +321,7 @@ void InspectorTimelineAgent::willEvaluateScript(const String& url, int lineNumbe { pushCurrentRecord(TimelineRecordFactory::createEvaluateScriptData(url, lineNumber), TimelineRecordType::EvaluateScript, true, frame); } - + void InspectorTimelineAgent::didEvaluateScript() { didCompleteCurrentRecord(TimelineRecordType::EvaluateScript); @@ -358,7 +359,7 @@ void InspectorTimelineAgent::didReceiveResourceData() { didCompleteCurrentRecord(TimelineRecordType::ResourceReceivedData); } - + void InspectorTimelineAgent::willReceiveResourceResponse(unsigned long identifier, const ResourceResponse& response, Frame* frame) { String requestId = IdentifiersFactory::requestId(identifier); @@ -481,6 +482,11 @@ void InspectorTimelineAgent::didCompleteCurrentRecord(const String& type) // An empty stack could merely mean that the timeline agent was turned on in the middle of // an event. Don't treat as an error. if (!m_recordStack.isEmpty()) { + if (m_orphanEventsEnabledStackMark == m_recordStack.size()) { + m_orphanEventsEnabledStackMark = 0; + InspectorInstrumentation::setTimelineAgentForOrphanEvents(0); + } + pushGCEventRecords(); TimelineRecordEntry entry = m_recordStack.last(); m_recordStack.removeLast(); @@ -499,6 +505,7 @@ InspectorTimelineAgent::InspectorTimelineAgent(InstrumentingAgents* instrumentin , m_timestampOffset(0) , m_id(1) , m_maxCallStackDepth(5) + , m_orphanEventsEnabledStackMark(0) , m_inspectorType(type) , m_client(client) { @@ -516,7 +523,7 @@ void InspectorTimelineAgent::appendRecord(PassRefPtr data, cons addRecordToTimeline(record.release(), type, frameId); } -void InspectorTimelineAgent::pushCurrentRecord(PassRefPtr data, const String& type, bool captureCallStack, Frame* frame) +void InspectorTimelineAgent::pushCurrentRecord(PassRefPtr data, const String& type, bool captureCallStack, Frame* frame, bool hasOrphanDetails) { pushGCEventRecords(); commitCancelableRecords(); @@ -525,6 +532,10 @@ void InspectorTimelineAgent::pushCurrentRecord(PassRefPtr data, if (frame && m_pageAgent) frameId = m_pageAgent->frameId(frame); m_recordStack.append(TimelineRecordEntry(record.release(), data, InspectorArray::create(), type, frameId)); + if (hasOrphanDetails && !m_orphanEventsEnabledStackMark && !InspectorInstrumentation::timelineAgentForOrphanEvents()) { + m_orphanEventsEnabledStackMark = m_recordStack.size(); + InspectorInstrumentation::setTimelineAgentForOrphanEvents(this); + } } void InspectorTimelineAgent::pushCancelableRecord(PassRefPtr data, const String& type, Frame* frame) diff --git a/Source/WebCore/inspector/InspectorTimelineAgent.h b/Source/WebCore/inspector/InspectorTimelineAgent.h index e447b79..8692fc3 100644 --- a/Source/WebCore/inspector/InspectorTimelineAgent.h +++ b/Source/WebCore/inspector/InspectorTimelineAgent.h @@ -162,7 +162,7 @@ private: InspectorTimelineAgent(InstrumentingAgents*, InspectorPageAgent*, InspectorState*, InspectorType, InspectorClient*); - void pushCurrentRecord(PassRefPtr, const String& type, bool captureCallStack, Frame*); + void pushCurrentRecord(PassRefPtr, const String& type, bool captureCallStack, Frame*, bool hasOrphanDetails = false); void setHeapSizeStatistic(InspectorObject* record); void didCompleteCurrentRecord(const String& type); @@ -199,6 +199,7 @@ private: typedef Vector GCEvents; GCEvents m_gcEvents; int m_maxCallStackDepth; + unsigned m_orphanEventsEnabledStackMark; InspectorType m_inspectorType; InspectorClient* m_client; }; -- 2.7.4