From 130bd87ffb1a926f53aa3b45766f99675b1779e2 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Fri, 8 May 2015 01:00:00 +0200 Subject: [PATCH] Bug 1158731 - Buffer for Performance APIs (Resource Timing, User Timing) should be separeted. r=baku --- dom/base/nsPerformance.cpp | 115 ++++++++++-------- dom/base/nsPerformance.h | 20 +-- dom/tests/mochitest/general/mochitest.ini | 3 + .../performance_timeline_main_test.html | 100 +++++++++++++++ .../general/resource_timing_main_test.html | 2 +- .../general/test_performance_timeline.html | 36 ++++++ 6 files changed, 217 insertions(+), 59 deletions(-) create mode 100644 dom/tests/mochitest/general/performance_timeline_main_test.html create mode 100644 dom/tests/mochitest/general/test_performance_timeline.html diff --git a/dom/base/nsPerformance.cpp b/dom/base/nsPerformance.cpp index e00f648c3b48..104523ec0e32 100644 --- a/dom/base/nsPerformance.cpp +++ b/dom/base/nsPerformance.cpp @@ -400,7 +400,8 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsPerformance) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsPerformance, DOMEventTargetHelper) NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow, mTiming, - mNavigation, mEntries, + mNavigation, mUserEntries, + mResourceEntries, mParentPerformance) tmp->mMozMemory = nullptr; mozilla::DropJSObjects(this); @@ -408,7 +409,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsPerformance, DOMEventTargetHelper) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow, mTiming, - mNavigation, mEntries, + mNavigation, mUserEntries, + mResourceEntries, mParentPerformance) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END @@ -429,7 +431,7 @@ nsPerformance::nsPerformance(nsPIDOMWindow* aWindow, mDOMTiming(aDOMTiming), mChannel(aChannel), mParentPerformance(aParentPerformance), - mPrimaryBufferSize(kDefaultBufferSize) + mResourceTimingBufferSize(kDefaultResourceTimingBufferSize) { MOZ_ASSERT(aWindow, "Parent window object should be provided"); } @@ -509,24 +511,30 @@ nsPerformance::WrapObject(JSContext *cx, JS::Handle aGivenProto) } void -nsPerformance::GetEntries(nsTArray >& retval) +nsPerformance::GetEntries(nsTArray>& retval) { MOZ_ASSERT(NS_IsMainThread()); - retval = mEntries; + retval = mResourceEntries; + retval.AppendElements(mUserEntries); + retval.Sort(PerformanceEntryComparator()); } void nsPerformance::GetEntriesByType(const nsAString& entryType, - nsTArray >& retval) + nsTArray>& retval) { MOZ_ASSERT(NS_IsMainThread()); retval.Clear(); - uint32_t count = mEntries.Length(); - for (uint32_t i = 0 ; i < count; i++) { - if (mEntries[i]->GetEntryType().Equals(entryType)) { - retval.AppendElement(mEntries[i]); + if (entryType.EqualsLiteral("resource")) { + retval = mResourceEntries; + } else if (entryType.EqualsLiteral("mark") || + entryType.EqualsLiteral("measure")) { + for (PerformanceEntry* entry : mUserEntries) { + if (entry->GetEntryType().Equals(entryType)) { + retval.AppendElement(entry); + } } } } @@ -534,31 +542,38 @@ nsPerformance::GetEntriesByType(const nsAString& entryType, void nsPerformance::GetEntriesByName(const nsAString& name, const Optional& entryType, - nsTArray >& retval) + nsTArray>& retval) { MOZ_ASSERT(NS_IsMainThread()); retval.Clear(); - uint32_t count = mEntries.Length(); - for (uint32_t i = 0 ; i < count; i++) { - if (mEntries[i]->GetName().Equals(name) && + for (PerformanceEntry* entry : mResourceEntries) { + if (entry->GetName().Equals(name) && (!entryType.WasPassed() || - mEntries[i]->GetEntryType().Equals(entryType.Value()))) { - retval.AppendElement(mEntries[i]); + entry->GetEntryType().Equals(entryType.Value()))) { + retval.AppendElement(entry); } } + for (PerformanceEntry* entry : mUserEntries) { + if (entry->GetName().Equals(name) && + (!entryType.WasPassed() || + entry->GetEntryType().Equals(entryType.Value()))) { + retval.AppendElement(entry); + } + } + retval.Sort(PerformanceEntryComparator()); } void -nsPerformance::ClearEntries(const Optional& aEntryName, - const nsAString& aEntryType) +nsPerformance::ClearUserEntries(const Optional& aEntryName, + const nsAString& aEntryType) { - for (uint32_t i = 0; i < mEntries.Length();) { + for (uint32_t i = 0; i < mUserEntries.Length();) { if ((!aEntryName.WasPassed() || - mEntries[i]->GetName().Equals(aEntryName.Value())) && + mUserEntries[i]->GetName().Equals(aEntryName.Value())) && (aEntryType.IsEmpty() || - mEntries[i]->GetEntryType().Equals(aEntryType))) { - mEntries.RemoveElementAt(i); + mUserEntries[i]->GetEntryType().Equals(aEntryType))) { + mUserEntries.RemoveElementAt(i); } else { ++i; } @@ -569,15 +584,14 @@ void nsPerformance::ClearResourceTimings() { MOZ_ASSERT(NS_IsMainThread()); - ClearEntries(Optional(), - NS_LITERAL_STRING("resource")); + mResourceEntries.Clear(); } void nsPerformance::SetResourceTimingBufferSize(uint64_t maxSize) { MOZ_ASSERT(NS_IsMainThread()); - mPrimaryBufferSize = maxSize; + mResourceTimingBufferSize = maxSize; } /** @@ -595,7 +609,7 @@ nsPerformance::AddEntry(nsIHttpChannel* channel, } // Don't add the entry if the buffer is full - if (mEntries.Length() >= mPrimaryBufferSize) { + if (mResourceEntries.Length() >= mResourceTimingBufferSize) { return; } @@ -634,7 +648,7 @@ nsPerformance::AddEntry(nsIHttpChannel* channel, initiatorType = NS_LITERAL_STRING("other"); } performanceEntry->SetInitiatorType(initiatorType); - InsertPerformanceEntry(performanceEntry, false); + InsertResourceEntry(performanceEntry); } } @@ -659,16 +673,25 @@ nsPerformance::PerformanceEntryComparator::LessThan( } void -nsPerformance::InsertPerformanceEntry(PerformanceEntry* aEntry, - bool aShouldPrint) +nsPerformance::InsertResourceEntry(PerformanceEntry* aEntry) { MOZ_ASSERT(aEntry); - MOZ_ASSERT(mEntries.Length() < mPrimaryBufferSize); - if (mEntries.Length() == mPrimaryBufferSize) { - NS_WARNING("Performance Entry buffer size maximum reached!"); + MOZ_ASSERT(mResourceEntries.Length() < mResourceTimingBufferSize); + if (mResourceEntries.Length() >= mResourceTimingBufferSize) { return; } - if (aShouldPrint && nsContentUtils::IsUserTimingLoggingEnabled()) { + mResourceEntries.InsertElementSorted(aEntry, + PerformanceEntryComparator()); + if (mResourceEntries.Length() == mResourceTimingBufferSize) { + // call onresourcetimingbufferfull + DispatchBufferFullEvent(); + } +} + +void +nsPerformance::InsertUserEntry(PerformanceEntry* aEntry) +{ + if (nsContentUtils::IsUserTimingLoggingEnabled()) { nsAutoCString uri; nsresult rv = mWindow->GetDocumentURI()->GetHost(uri); if(NS_FAILED(rv)) { @@ -683,21 +706,16 @@ nsPerformance::InsertPerformanceEntry(PerformanceEntry* aEntry, aEntry->Duration(), static_cast(PR_Now() / PR_USEC_PER_MSEC)); } - mEntries.InsertElementSorted(aEntry, - PerformanceEntryComparator()); - if (mEntries.Length() == mPrimaryBufferSize) { - // call onresourcetimingbufferfull - DispatchBufferFullEvent(); - } + mUserEntries.InsertElementSorted(aEntry, + PerformanceEntryComparator()); } void nsPerformance::Mark(const nsAString& aName, ErrorResult& aRv) { MOZ_ASSERT(NS_IsMainThread()); - // Don't add the entry if the buffer is full - if (mEntries.Length() >= mPrimaryBufferSize) { - NS_WARNING("Performance Entry buffer size maximum reached!"); + // Don't add the entry if the buffer is full. XXX should be removed by bug 1159003. + if (mUserEntries.Length() >= mResourceTimingBufferSize) { return; } if (IsPerformanceTimingAttribute(aName)) { @@ -706,14 +724,14 @@ nsPerformance::Mark(const nsAString& aName, ErrorResult& aRv) } nsRefPtr performanceMark = new PerformanceMark(this, aName); - InsertPerformanceEntry(performanceMark, true); + InsertUserEntry(performanceMark); } void nsPerformance::ClearMarks(const Optional& aName) { MOZ_ASSERT(NS_IsMainThread()); - ClearEntries(aName, NS_LITERAL_STRING("mark")); + ClearUserEntries(aName, NS_LITERAL_STRING("mark")); } DOMHighResTimeStamp @@ -749,9 +767,8 @@ nsPerformance::Measure(const nsAString& aName, ErrorResult& aRv) { MOZ_ASSERT(NS_IsMainThread()); - // Don't add the entry if the buffer is full - if (mEntries.Length() >= mPrimaryBufferSize) { - NS_WARNING("Performance Entry buffer size maximum reached!"); + // Don't add the entry if the buffer is full. XXX should be removed by bug 1159003. + if (mUserEntries.Length() >= mResourceTimingBufferSize) { return; } DOMHighResTimeStamp startTime; @@ -783,14 +800,14 @@ nsPerformance::Measure(const nsAString& aName, } nsRefPtr performanceMeasure = new PerformanceMeasure(this, aName, startTime, endTime); - InsertPerformanceEntry(performanceMeasure, true); + InsertUserEntry(performanceMeasure); } void nsPerformance::ClearMeasures(const Optional& aName) { MOZ_ASSERT(NS_IsMainThread()); - ClearEntries(aName, NS_LITERAL_STRING("measure")); + ClearUserEntries(aName, NS_LITERAL_STRING("measure")); } DOMHighResTimeStamp diff --git a/dom/base/nsPerformance.h b/dom/base/nsPerformance.h index b4b4f5a855a0..b727653c118c 100644 --- a/dom/base/nsPerformance.h +++ b/dom/base/nsPerformance.h @@ -328,12 +328,12 @@ public: nsPerformanceTiming* Timing(); nsPerformanceNavigation* Navigation(); - void GetEntries(nsTArray >& retval); + void GetEntries(nsTArray>& retval); void GetEntriesByType(const nsAString& entryType, - nsTArray >& retval); + nsTArray>& retval); void GetEntriesByName(const nsAString& name, const mozilla::dom::Optional< nsAString >& entryType, - nsTArray >& retval); + nsTArray>& retval); void AddEntry(nsIHttpChannel* channel, nsITimedChannel* timedChannel); void ClearResourceTimings(); @@ -357,20 +357,22 @@ private: DOMTimeMilliSec GetPerformanceTimingFromString(const nsAString& aTimingName); DOMHighResTimeStamp ConvertDOMMilliSecToHighRes(const DOMTimeMilliSec aTime); void DispatchBufferFullEvent(); - void InsertPerformanceEntry(PerformanceEntry* aEntry, bool aShouldPrint); - void ClearEntries(const mozilla::dom::Optional& aEntryName, - const nsAString& aEntryType); + void InsertUserEntry(PerformanceEntry* aEntry); + void ClearUserEntries(const mozilla::dom::Optional& aEntryName, + const nsAString& aEntryType); + void InsertResourceEntry(PerformanceEntry* aEntry); nsCOMPtr mWindow; nsRefPtr mDOMTiming; nsCOMPtr mChannel; nsRefPtr mTiming; nsRefPtr mNavigation; - nsTArray > mEntries; + nsTArray> mResourceEntries; + nsTArray> mUserEntries; nsRefPtr mParentPerformance; - uint64_t mPrimaryBufferSize; + uint64_t mResourceTimingBufferSize; JS::Heap mMozMemory; - static const uint64_t kDefaultBufferSize = 150; + static const uint64_t kDefaultResourceTimingBufferSize = 150; // Helper classes class PerformanceEntryComparator { diff --git a/dom/tests/mochitest/general/mochitest.ini b/dom/tests/mochitest/general/mochitest.ini index 5cd5f731391e..3c102822399f 100644 --- a/dom/tests/mochitest/general/mochitest.ini +++ b/dom/tests/mochitest/general/mochitest.ini @@ -14,6 +14,7 @@ support-files = image_50.png image_100.png image_200.png + performance_timeline_main_test.html resource_timing_iframe.html resource_timing_main_test.html resource_timing_cross_origin.html @@ -79,8 +80,10 @@ support-files = test_offsets.js skip-if = buildapp == 'mulet' [test_paste_selection.html] skip-if = buildapp == 'mulet' +[test_performance_timeline.html] [test_picture_mutations.html] [test_picture_pref.html] +skip-if = buildapp == 'b2g' || buildapp == 'mulet' [test_resource_timing.html] skip-if = buildapp == 'b2g' || buildapp == 'mulet' [test_resource_timing_cross_origin.html] diff --git a/dom/tests/mochitest/general/performance_timeline_main_test.html b/dom/tests/mochitest/general/performance_timeline_main_test.html new file mode 100644 index 000000000000..7b4339997c0f --- /dev/null +++ b/dom/tests/mochitest/general/performance_timeline_main_test.html @@ -0,0 +1,100 @@ + + + + + + + + + + + Bug #1158731 - Buffer for Performance APIs (Resource Timing, User Timing) should be separeted + +

+
+ + + + + + diff --git a/dom/tests/mochitest/general/resource_timing_main_test.html b/dom/tests/mochitest/general/resource_timing_main_test.html index e8fe52820486..465b5e7fedf5 100644 --- a/dom/tests/mochitest/general/resource_timing_main_test.html +++ b/dom/tests/mochitest/general/resource_timing_main_test.html @@ -76,7 +76,7 @@ window.onload = function() { bufferFullCounter += 1; } - // Here, we should have 6 entries (1 css, 3 png, 1 html) since the image was loaded. + // Here, we should have 5 entries (1 css, 3 png, 1 html) since the image was loaded. is(window.performance.getEntries().length, 5, "Performance.getEntries() returned wrong number of entries."); checkStringify(window.performance.getEntries()[0]); diff --git a/dom/tests/mochitest/general/test_performance_timeline.html b/dom/tests/mochitest/general/test_performance_timeline.html new file mode 100644 index 000000000000..0db8a19b4237 --- /dev/null +++ b/dom/tests/mochitest/general/test_performance_timeline.html @@ -0,0 +1,36 @@ + + + + + + + + + + +
+
+
+ + +