Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1052)

Unified Diff: Source/core/inspector/TimelineTraceEventProcessor.cpp

Issue 27524002: DevTools: process trace events from background threads by a timed task. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: replaced !Vector::size() with Vector::isEmpty() Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/inspector/TimelineTraceEventProcessor.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/inspector/TimelineTraceEventProcessor.cpp
diff --git a/Source/core/inspector/TimelineTraceEventProcessor.cpp b/Source/core/inspector/TimelineTraceEventProcessor.cpp
index 14ea5c38852b474e65dc7606227fa41a38f8fee6..6403a5665bc5515ab3954ffc1276c0fd24761cf7 100644
--- a/Source/core/inspector/TimelineTraceEventProcessor.cpp
+++ b/Source/core/inspector/TimelineTraceEventProcessor.cpp
@@ -38,6 +38,7 @@
#include "core/rendering/RenderImage.h"
#include "wtf/CurrentTime.h"
+#include "wtf/Functional.h"
#include "wtf/MainThread.h"
#include "wtf/Vector.h"
@@ -156,6 +157,8 @@ TimelineTraceEventProcessor::TimelineTraceEventProcessor(WeakPtr<InspectorTimeli
, m_layerId(0)
, m_paintSetupStart(0)
, m_paintSetupEnd(0)
+ , m_lastEventProcessingTime(0)
+ , m_processEventsTaskPosted(false)
{
registerHandler(InstrumentationEvents::BeginFrame, TRACE_EVENT_PHASE_INSTANT, &TimelineTraceEventProcessor::onBeginFrame);
registerHandler(InstrumentationEvents::UpdateLayer, TRACE_EVENT_PHASE_BEGIN, &TimelineTraceEventProcessor::onUpdateLayerBegin);
@@ -220,19 +223,28 @@ void TimelineTraceEventProcessor::processEventOnAnyThread(char phase, const char
if (it == m_handlersByType.end())
return;
- TraceEvent event(WTF::monotonicallyIncreasingTime(), phase, name, id, currentThread(), numArgs, argNames, argTypes, argValues);
+ double timestamp = WTF::monotonicallyIncreasingTime();
+ TraceEvent event(timestamp, phase, name, id, currentThread(), numArgs, argNames, argTypes, argValues);
if (!isMainThread()) {
MutexLocker locker(m_backgroundEventsMutex);
+ const float EventProcessingThresholdInSeconds = 0.1;
pfeldman 2013/10/17 17:19:23 eventProcessingThresholdInSeconds
m_backgroundEvents.append(event);
+ if (!m_processEventsTaskPosted && timestamp - m_lastEventProcessingTime > EventProcessingThresholdInSeconds) {
+ m_processEventsTaskPosted = true;
+ callOnMainThread(bind(&TimelineTraceEventProcessor::processBackgroundEventsTask, this));
+ }
return;
}
+ processBackgroundEvents();
(this->*(it->value))(event);
}
void TimelineTraceEventProcessor::onBeginFrame(const TraceEvent&)
{
- processBackgroundEvents();
+ // We don't handle BeginFrame explicitly now, but it still implicitly helps
+ // to pump the background events regularly (as opponsed to a special task),
+ // as this is only done upon events we recognize.
}
void TimelineTraceEventProcessor::onUpdateLayerBegin(const TraceEvent& event)
@@ -283,8 +295,7 @@ void TimelineTraceEventProcessor::onRasterTaskBegin(const TraceEvent& event)
return;
unsigned long long layerId = event.asUInt(InstrumentationEventArguments::LayerId);
ASSERT(layerId);
- RefPtr<JSONObject> record = createRecord(event, TimelineRecordType::Rasterize);
- record->setObject("data", TimelineRecordFactory::createLayerData(m_layerToNodeMap.get(layerId)));
+ RefPtr<JSONObject> record = createRecord(event, TimelineRecordType::Rasterize, TimelineRecordFactory::createLayerData(m_layerToNodeMap.get(layerId)));
state.recordStack.addScopedRecord(record.release());
}
@@ -422,6 +433,9 @@ void TimelineTraceEventProcessor::processBackgroundEvents()
Vector<TraceEvent> events;
{
MutexLocker locker(m_backgroundEventsMutex);
+ m_lastEventProcessingTime = WTF::monotonicallyIncreasingTime();
+ if (m_backgroundEvents.isEmpty())
+ return;
events.reserveCapacity(m_backgroundEvents.capacity());
m_backgroundEvents.swap(events);
}
@@ -433,5 +447,11 @@ void TimelineTraceEventProcessor::processBackgroundEvents()
}
}
+void TimelineTraceEventProcessor::processBackgroundEventsTask()
+{
+ m_processEventsTaskPosted = false;
+ processBackgroundEvents();
+}
+
} // namespace WebCore
« no previous file with comments | « Source/core/inspector/TimelineTraceEventProcessor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698