diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 967bcafb5dd..08d1b60c5da 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -242,6 +242,7 @@ bool nsContentUtils::sTrustedFullScreenOnly = true; bool nsContentUtils::sFullscreenApiIsContentOnly = false; bool nsContentUtils::sIsPerformanceTimingEnabled = false; bool nsContentUtils::sIsResourceTimingEnabled = false; +bool nsContentUtils::sIsUserTimingLoggingEnabled = false; bool nsContentUtils::sIsExperimentalAutocompleteEnabled = false; bool nsContentUtils::sEncodeDecodeURLHash = false; @@ -515,6 +516,9 @@ nsContentUtils::Init() Preferences::AddBoolVarCache(&sIsResourceTimingEnabled, "dom.enable_resource_timing", true); + Preferences::AddBoolVarCache(&sIsUserTimingLoggingEnabled, + "dom.performance.enable_user_timing_logging", false); + Preferences::AddBoolVarCache(&sIsExperimentalAutocompleteEnabled, "dom.forms.autocomplete.experimental", false); diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 0bb2f9b4fbe..5a016728974 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -1880,6 +1880,14 @@ public: return sIsPerformanceTimingEnabled; } + /* + * Returns true if user timing API should print to console. + */ + static bool IsUserTimingLoggingEnabled() + { + return sIsUserTimingLoggingEnabled; + } + /* * Returns true if the performance timing APIs are enabled. */ @@ -2360,6 +2368,7 @@ private: static uint32_t sHandlingInputTimeout; static bool sIsPerformanceTimingEnabled; static bool sIsResourceTimingEnabled; + static bool sIsUserTimingLoggingEnabled; static bool sIsExperimentalAutocompleteEnabled; static bool sEncodeDecodeURLHash; diff --git a/dom/base/nsPerformance.cpp b/dom/base/nsPerformance.cpp index 57f005cad5b..1ecdc487323 100644 --- a/dom/base/nsPerformance.cpp +++ b/dom/base/nsPerformance.cpp @@ -22,8 +22,15 @@ #include "mozilla/dom/PerformanceBinding.h" #include "mozilla/dom/PerformanceTimingBinding.h" #include "mozilla/dom/PerformanceNavigationBinding.h" +#include "mozilla/IntegerPrintfMacros.h" #include "mozilla/TimeStamp.h" +#ifdef MOZ_WIDGET_GONK +#define PERFLOG(msg, ...) __android_log_print(ANDROID_LOG_INFO, "PerformanceTiming", msg, ##__VA_ARGS__) +#else +#define PERFLOG(msg, ...) printf_stderr(msg, ##__VA_ARGS__) +#endif + using namespace mozilla; using namespace mozilla::dom; @@ -589,7 +596,7 @@ nsPerformance::AddEntry(nsIHttpChannel* channel, initiatorType = NS_LITERAL_STRING("other"); } performanceEntry->SetInitiatorType(initiatorType); - InsertPerformanceEntry(performanceEntry); + InsertPerformanceEntry(performanceEntry, false); } } @@ -614,7 +621,8 @@ nsPerformance::PerformanceEntryComparator::LessThan( } void -nsPerformance::InsertPerformanceEntry(PerformanceEntry* aEntry) +nsPerformance::InsertPerformanceEntry(PerformanceEntry* aEntry, + bool aShouldPrint) { MOZ_ASSERT(aEntry); MOZ_ASSERT(mEntries.Length() < mPrimaryBufferSize); @@ -622,6 +630,21 @@ nsPerformance::InsertPerformanceEntry(PerformanceEntry* aEntry) NS_WARNING("Performance Entry buffer size maximum reached!"); return; } + if (aShouldPrint && nsContentUtils::IsUserTimingLoggingEnabled()) { + nsAutoCString uri; + nsresult rv = mWindow->GetDocumentURI()->GetHost(uri); + if(NS_FAILED(rv)) { + // If we have no URI, just put in "none". + uri.AssignLiteral("none"); + } + PERFLOG("Performance Entry: %s|%s|%s|%f|%f|%" PRIu64 "\n", + uri.get(), + NS_ConvertUTF16toUTF8(aEntry->GetEntryType()).get(), + NS_ConvertUTF16toUTF8(aEntry->GetName()).get(), + aEntry->StartTime(), + aEntry->Duration(), + static_cast(PR_Now() / PR_USEC_PER_MSEC)); + } mEntries.InsertElementSorted(aEntry, PerformanceEntryComparator()); if (mEntries.Length() == mPrimaryBufferSize) { @@ -645,7 +668,7 @@ nsPerformance::Mark(const nsAString& aName, ErrorResult& aRv) } nsRefPtr performanceMark = new PerformanceMark(this, aName); - InsertPerformanceEntry(performanceMark); + InsertPerformanceEntry(performanceMark, true); } void @@ -722,7 +745,7 @@ nsPerformance::Measure(const nsAString& aName, } nsRefPtr performanceMeasure = new PerformanceMeasure(this, aName, startTime, endTime); - InsertPerformanceEntry(performanceMeasure); + InsertPerformanceEntry(performanceMeasure, true); } void diff --git a/dom/base/nsPerformance.h b/dom/base/nsPerformance.h index 22b01538e35..4d79b9e2732 100644 --- a/dom/base/nsPerformance.h +++ b/dom/base/nsPerformance.h @@ -353,7 +353,7 @@ private: DOMTimeMilliSec GetPerformanceTimingFromString(const nsAString& aTimingName); DOMHighResTimeStamp ConvertDOMMilliSecToHighRes(const DOMTimeMilliSec aTime); void DispatchBufferFullEvent(); - void InsertPerformanceEntry(PerformanceEntry* aEntry); + void InsertPerformanceEntry(PerformanceEntry* aEntry, bool aShouldPrint); void ClearEntries(const mozilla::dom::Optional& aEntryName, const nsAString& aEntryType); nsCOMPtr mWindow; diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 3bc8a1ab037..ce0d18244fc 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -147,6 +147,9 @@ pref("dom.enable_resource_timing", true); // Enable high-resolution timing markers for users pref("dom.enable_user_timing", true); +// Enable printing performance marks/measures to log +pref("dom.performance.enable_user_timing_logging", false); + // Whether the Gamepad API is enabled pref("dom.gamepad.enabled", true); #ifdef RELEASE_BUILD