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

Unified Diff: Source/core/timing/PerformanceBase.cpp

Issue 1198863006: First version of PerformanceObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Switch from microtask to timer for firing events. Created 5 years, 5 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
Index: Source/core/timing/PerformanceBase.cpp
diff --git a/Source/core/timing/PerformanceBase.cpp b/Source/core/timing/PerformanceBase.cpp
index 219f3f5b51331991db0f63fb8f2a52bb9ffdd724..8cd4c8d97d4e1b989d843cfb965fc08cd884ab91 100644
--- a/Source/core/timing/PerformanceBase.cpp
+++ b/Source/core/timing/PerformanceBase.cpp
@@ -35,6 +35,7 @@
#include "core/dom/Document.h"
#include "core/events/Event.h"
#include "core/timing/PerformanceCompositeTiming.h"
+#include "core/timing/PerformanceObserver.h"
#include "core/timing/PerformanceRenderTiming.h"
#include "core/timing/PerformanceResourceTiming.h"
#include "core/timing/PerformanceUserTiming.h"
@@ -52,6 +53,7 @@ PerformanceBase::PerformanceBase(double timeOrigin)
, m_resourceTimingBufferSize(defaultResourceTimingBufferSize)
, m_timeOrigin(timeOrigin)
, m_userTiming(nullptr)
+ , m_observerFilterOptions(PerformanceEntry::Invalid)
{
}
@@ -88,25 +90,28 @@ PerformanceEntryVector PerformanceBase::getEntries() const
PerformanceEntryVector PerformanceBase::getEntriesByType(const String& entryType)
{
PerformanceEntryVector entries;
+ PerformanceEntry::EntryType entryTypeEnum = PerformanceEntry::toEntryTypeEnum(entryType);
esprehn 2015/07/24 08:23:12 Maybe just |type| ?
MikeB 2015/07/24 19:30:38 Done.
- if (equalIgnoringCase(entryType, "resource")) {
+ if (entryTypeEnum == PerformanceEntry::Invalid)
+ return entries;
+
+ if (entryTypeEnum == PerformanceEntry::Resource) {
for (const auto& resource : m_resourceTimingBuffer)
entries.append(resource);
}
- if (equalIgnoringCase(entryType, "composite")
- || equalIgnoringCase(entryType, "render")) {
+if (entryTypeEnum == PerformanceEntry::Composite || entryTypeEnum == PerformanceEntry::Render) {
for (const auto& frame : m_frameTimingBuffer) {
- if (equalIgnoringCase(entryType, frame->entryType())) {
+ if (entryTypeEnum == frame->entryTypeEnum()) {
entries.append(frame);
}
}
}
if (m_userTiming) {
- if (equalIgnoringCase(entryType, "mark"))
+ if (entryTypeEnum == PerformanceEntry::Mark)
entries.appendVector(m_userTiming->getMarks());
- else if (equalIgnoringCase(entryType, "measure"))
+ else if (entryTypeEnum == PerformanceEntry::Measure)
entries.appendVector(m_userTiming->getMeasures());
}
@@ -117,16 +122,19 @@ PerformanceEntryVector PerformanceBase::getEntriesByType(const String& entryType
PerformanceEntryVector PerformanceBase::getEntriesByName(const String& name, const String& entryType)
{
PerformanceEntryVector entries;
+ PerformanceEntry::EntryType entryTypeEnum = PerformanceEntry::toEntryTypeEnum(entryType);
+
+ if (!entryType.isNull() && entryTypeEnum == PerformanceEntry::Invalid)
+ return entries;
- if (entryType.isNull() || equalIgnoringCase(entryType, "resource")) {
+ if (entryType.isNull() || entryTypeEnum == PerformanceEntry::Resource) {
for (const auto& resource : m_resourceTimingBuffer) {
if (resource->name() == name)
entries.append(resource);
}
}
- if (entryType.isNull() || equalIgnoringCase(entryType, "composite")
- || equalIgnoringCase(entryType, "render")) {
+ if (entryType.isNull() || entryTypeEnum == PerformanceEntry::Composite || entryTypeEnum == PerformanceEntry::Render) {
for (const auto& frame : m_frameTimingBuffer) {
if (frame->name() == name && (entryType.isNull()
|| equalIgnoringCase(entryType, frame->entryType()))) {
@@ -136,9 +144,9 @@ PerformanceEntryVector PerformanceBase::getEntriesByName(const String& name, con
}
if (m_userTiming) {
- if (entryType.isNull() || equalIgnoringCase(entryType, "mark"))
+ if (entryType.isNull() || entryTypeEnum == PerformanceEntry::Mark)
entries.appendVector(m_userTiming->getMarks(name));
- if (entryType.isNull() || equalIgnoringCase(entryType, "measure"))
+ if (entryType.isNull() || entryTypeEnum == PerformanceEntry::Measure)
entries.appendVector(m_userTiming->getMeasures(name));
}
@@ -211,7 +219,7 @@ static bool allowsTimingRedirect(const Vector<ResourceResponse>& redirectChain,
void PerformanceBase::addResourceTiming(const ResourceTimingInfo& info)
{
- if (isResourceTimingBufferFull())
+ if (isResourceTimingBufferFull() && !hasObserverFor(PerformanceEntry::Resource))
return;
SecurityOrigin* securityOrigin = nullptr;
if (ExecutionContext* context = executionContext())
@@ -244,7 +252,9 @@ void PerformanceBase::addResourceTiming(const ResourceTimingInfo& info)
double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd();
PerformanceEntry* entry = PerformanceResourceTiming::create(info, timeOrigin(), startTime, lastRedirectEndTime, allowTimingDetails, allowRedirectDetails);
- addResourceTimingBuffer(entry);
+ notifyObserversOfEntry(entry);
+ if (!isResourceTimingBufferFull())
+ addResourceTimingBuffer(entry);
}
void PerformanceBase::addResourceTimingBuffer(PerformanceEntry* entry)
@@ -262,20 +272,24 @@ bool PerformanceBase::isResourceTimingBufferFull()
void PerformanceBase::addRenderTiming(Document* initiatorDocument, unsigned sourceFrame, double startTime, double finishTime)
{
- if (isFrameTimingBufferFull())
+ if (isFrameTimingBufferFull() && !hasObserverFor(PerformanceEntry::Render))
return;
PerformanceEntry* entry = PerformanceRenderTiming::create(initiatorDocument, sourceFrame, startTime, finishTime);
- addFrameTimingBuffer(entry);
+ notifyObserversOfEntry(entry);
+ if (!isFrameTimingBufferFull())
+ addFrameTimingBuffer(entry);
}
void PerformanceBase::addCompositeTiming(Document* initiatorDocument, unsigned sourceFrame, double startTime)
{
- if (isFrameTimingBufferFull())
+ if (isFrameTimingBufferFull() && !hasObserverFor(PerformanceEntry::Composite))
return;
PerformanceEntry* entry = PerformanceCompositeTiming::create(initiatorDocument, sourceFrame, startTime);
- addFrameTimingBuffer(entry);
+ notifyObserversOfEntry(entry);
+ if (!isFrameTimingBufferFull())
+ addFrameTimingBuffer(entry);
}
void PerformanceBase::addFrameTimingBuffer(PerformanceEntry* entry)
@@ -295,7 +309,8 @@ void PerformanceBase::mark(const String& markName, ExceptionState& exceptionStat
{
if (!m_userTiming)
m_userTiming = UserTiming::create(this);
- m_userTiming->mark(markName, exceptionState);
+ NewPerformanceEntryCallback callback = WTF::bind<PerformanceEntry*>(&PerformanceBase::notifyObserversOfEntry, this);
+ m_userTiming->mark(markName, callback, exceptionState);
}
void PerformanceBase::clearMarks(const String& markName)
@@ -309,7 +324,8 @@ void PerformanceBase::measure(const String& measureName, const String& startMark
{
if (!m_userTiming)
m_userTiming = UserTiming::create(this);
- m_userTiming->measure(measureName, startMark, endMark, exceptionState);
+ NewPerformanceEntryCallback callback = WTF::bind<PerformanceEntry*>(&PerformanceBase::notifyObserversOfEntry, this);
+ m_userTiming->measure(measureName, startMark, endMark, callback, exceptionState);
}
void PerformanceBase::clearMeasures(const String& measureName)
@@ -319,6 +335,34 @@ void PerformanceBase::clearMeasures(const String& measureName)
m_userTiming->clearMeasures(measureName);
}
+void PerformanceBase::registerPerformanceObserver(PerformanceObserver* observer)
+{
+ m_observerFilterOptions |= observer->filterOptions();
+ m_observers.add(observer);
+}
+
+void PerformanceBase::unregisterPerformanceObserver(PerformanceObserver* oldObserver)
+{
+ m_observers.remove(oldObserver);
+ m_observerFilterOptions = PerformanceEntry::Invalid;
+ for (auto& observer : m_observers) {
esprehn 2015/07/24 08:23:12 const auto&
MikeB 2015/07/24 19:30:38 Done.
+ m_observerFilterOptions |= observer->filterOptions();
+ }
+}
+
+void PerformanceBase::notifyObserversOfEntry(PerformanceEntry* entry)
+{
+ for (auto& observer : m_observers) {
+ if (observer->filterOptions() & entry->entryTypeEnum())
+ observer->enqueuePerformanceEntry(entry);
+ }
+}
+
+bool PerformanceBase::hasObserverFor(PerformanceEntry::EntryType filterType)
+{
+ return m_observerFilterOptions & filterType;
+}
+
double PerformanceBase::now() const
{
double nowSeconds = monotonicallyIncreasingTime() - m_timeOrigin;
@@ -331,6 +375,7 @@ DEFINE_TRACE(PerformanceBase)
visitor->trace(m_frameTimingBuffer);
visitor->trace(m_resourceTimingBuffer);
visitor->trace(m_userTiming);
+ visitor->trace(m_observers);
EventTargetWithInlineData::trace(visitor);
}

Powered by Google App Engine
This is Rietveld 408576698