Diff
Modified: branches/safari-603-branch/Source/WebCore/ChangeLog (210878 => 210879)
--- branches/safari-603-branch/Source/WebCore/ChangeLog 2017-01-18 20:43:40 UTC (rev 210878)
+++ branches/safari-603-branch/Source/WebCore/ChangeLog 2017-01-18 20:43:44 UTC (rev 210879)
@@ -1,5 +1,40 @@
2017-01-18 Matthew Hanson <matthew_han...@apple.com>
+ Merge r210774. rdar://problem/30019773
+
+ 2017-01-14 Chris Dumez <cdu...@apple.com>
+
+ Report CPU usage of tabs after they become non-visible using diagnostic logging
+ https://bugs.webkit.org/show_bug.cgi?id=167019
+ <rdar://problem/30019773>
+
+ Reviewed by Darin Adler.
+
+ Report CPU usage of tabs after they become non-visible using diagnostic logging.
+ We start measure CPU usage 5 seconds after a tab goes to the background, for 5
+ minutes and report how much CPU the tab used during those 5 minutes. We will
+ not log if the tab gets closed or moved to the foreground during those 5
+ minutes.
+
+ * page/DiagnosticLoggingKeys.cpp:
+ (WebCore::DiagnosticLoggingKeys::postPageBackgroundingKey):
+ * page/DiagnosticLoggingKeys.h:
+ * page/Page.cpp:
+ (WebCore::Page::Page):
+ (WebCore::Page::didStartProvisionalLoad):
+ (WebCore::Page::didFinishLoad):
+ (WebCore::foregroundCPUUsageToDiagnosticLogginKey):
+ (WebCore::Page::measurePostLoadCPUUsage):
+ (WebCore::backgroundCPUUsageToDiagnosticLogginKey):
+ (WebCore::Page::measurePostBackgroundingCPUUsage):
+ (WebCore::Page::setIsVisibleInternal):
+ * page/Page.h:
+ * page/Settings.cpp:
+ (WebCore::Settings::isPostBackgroundingCPUUsageMeasurementEnabled):
+ * page/Settings.h:
+
+2017-01-18 Matthew Hanson <matthew_han...@apple.com>
+
Merge r210733. rdar://problem/30014496
2017-01-13 Chris Dumez <cdu...@apple.com>
Modified: branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.cpp (210878 => 210879)
--- branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.cpp 2017-01-18 20:43:40 UTC (rev 210878)
+++ branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.cpp 2017-01-18 20:43:44 UTC (rev 210879)
@@ -53,6 +53,11 @@
return ASCIILiteral("pluginFailedLoading");
}
+String DiagnosticLoggingKeys::postPageBackgroundingKey()
+{
+ return ASCIILiteral("postPageBackgrounding");
+}
+
String DiagnosticLoggingKeys::postPageLoadKey()
{
return ASCIILiteral("postPageLoad");
Modified: branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.h (210878 => 210879)
--- branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.h 2017-01-18 20:43:40 UTC (rev 210878)
+++ branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.h 2017-01-18 20:43:44 UTC (rev 210879)
@@ -101,6 +101,7 @@
static String playedKey();
static String pluginLoadedKey();
static String pluginLoadingFailedKey();
+ static String postPageBackgroundingKey();
static String postPageLoadKey();
static String provisionalLoadKey();
static String prunedDueToMaxSizeReached();
Modified: branches/safari-603-branch/Source/WebCore/page/Page.cpp (210878 => 210879)
--- branches/safari-603-branch/Source/WebCore/page/Page.cpp 2017-01-18 20:43:40 UTC (rev 210878)
+++ branches/safari-603-branch/Source/WebCore/page/Page.cpp 2017-01-18 20:43:44 UTC (rev 210879)
@@ -131,7 +131,8 @@
static HashSet<Page*>* allPages;
static const std::chrono::seconds cpuUsageMeasurementDelay { 5 };
-static const std::chrono::seconds cpuUsageMeasurementDuration { 10 };
+static const std::chrono::seconds postLoadCPUUsageMeasurementDuration { 10 };
+static const std::chrono::minutes backgroundCPUUsageMeasurementDuration { 5 };
DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, pageCounter, ("Page"));
@@ -251,7 +252,8 @@
, m_visitedLinkStore(*WTFMove(pageConfiguration.visitedLinkStore))
, m_sessionID(SessionID::defaultSessionID())
, m_isClosing(false)
- , m_cpuUsageMeasurementTimer(*this, &Page::measurePostLoadCPUUsage)
+ , m_postPageLoadCPUUsageTimer(*this, &Page::measurePostLoadCPUUsage)
+ , m_postBackgroundingCPUUsageTimer(*this, &Page::measurePostBackgroundingCPUUsage)
{
updateTimerThrottlingState();
@@ -936,7 +938,7 @@
void Page::didStartProvisionalLoad()
{
m_postLoadCPUTime = std::nullopt;
- m_cpuUsageMeasurementTimer.stop();
+ m_postPageLoadCPUUsageTimer.stop();
}
void Page::didFinishLoad()
@@ -946,11 +948,11 @@
// Only do post-load CPU usage measurement if there is a single Page in the process in order to reduce noise.
if (Settings::isPostLoadCPUUsageMeasurementEnabled() && allPages->size() == 1) {
m_postLoadCPUTime = std::nullopt;
- m_cpuUsageMeasurementTimer.startOneShot(cpuUsageMeasurementDelay);
+ m_postPageLoadCPUUsageTimer.startOneShot(cpuUsageMeasurementDelay);
}
}
-static String cpuUsageToDiagnosticLogginKey(double cpuUsage)
+static String foregroundCPUUsageToDiagnosticLogginKey(double cpuUsage)
{
if (cpuUsage < 10)
return ASCIILiteral("Below10");
@@ -967,10 +969,13 @@
void Page::measurePostLoadCPUUsage()
{
+ if (allPages->size() != 1)
+ return;
+
if (!m_postLoadCPUTime) {
m_postLoadCPUTime = getCPUTime();
if (m_postLoadCPUTime)
- m_cpuUsageMeasurementTimer.startOneShot(cpuUsageMeasurementDuration);
+ m_postPageLoadCPUUsageTimer.startOneShot(postLoadCPUUsageMeasurementDuration);
return;
}
std::optional<CPUTime> cpuTime = getCPUTime();
@@ -979,9 +984,46 @@
double cpuUsage = cpuTime.value().percentageCPUUsageSince(*m_postLoadCPUTime);
RELEASE_LOG_IF_ALLOWED(PerformanceLogging, "measurePostLoadCPUUsage: Process was using %.1f%% percent CPU after the page load.", cpuUsage);
- diagnosticLoggingClient().logDiagnosticMessageWithValue(DiagnosticLoggingKeys::postPageLoadKey(), DiagnosticLoggingKeys::cpuUsageKey(), cpuUsageToDiagnosticLogginKey(cpuUsage), ShouldSample::No);
+ diagnosticLoggingClient().logDiagnosticMessageWithValue(DiagnosticLoggingKeys::postPageLoadKey(), DiagnosticLoggingKeys::cpuUsageKey(), foregroundCPUUsageToDiagnosticLogginKey(cpuUsage), ShouldSample::No);
}
+static String backgroundCPUUsageToDiagnosticLogginKey(double cpuUsage)
+{
+ if (cpuUsage < 1)
+ return ASCIILiteral("Below1");
+ if (cpuUsage < 5)
+ return ASCIILiteral("1to5");
+ if (cpuUsage < 10)
+ return ASCIILiteral("5to10");
+ if (cpuUsage < 30)
+ return ASCIILiteral("10to30");
+ if (cpuUsage < 50)
+ return ASCIILiteral("30to50");
+ if (cpuUsage < 70)
+ return ASCIILiteral("50to70");
+ return ASCIILiteral("over70");
+}
+
+void Page::measurePostBackgroundingCPUUsage()
+{
+ if (allPages->size() != 1)
+ return;
+
+ if (!m_postBackgroundingCPUTime) {
+ m_postBackgroundingCPUTime = getCPUTime();
+ if (m_postBackgroundingCPUTime)
+ m_postBackgroundingCPUUsageTimer.startOneShot(backgroundCPUUsageMeasurementDuration);
+ return;
+ }
+ std::optional<CPUTime> cpuTime = getCPUTime();
+ if (!cpuTime)
+ return;
+
+ double cpuUsage = cpuTime.value().percentageCPUUsageSince(*m_postBackgroundingCPUTime);
+ RELEASE_LOG_IF_ALLOWED(PerformanceLogging, "measurePostBackgroundingCPUUsage: Process was using %.1f%% percent CPU after becoming non visible.", cpuUsage);
+ diagnosticLoggingClient().logDiagnosticMessageWithValue(DiagnosticLoggingKeys::postPageBackgroundingKey(), DiagnosticLoggingKeys::cpuUsageKey(), backgroundCPUUsageToDiagnosticLogginKey(cpuUsage), ShouldSample::No);
+}
+
void Page::setTopContentInset(float contentInset)
{
if (m_topContentInset == contentInset)
@@ -1590,6 +1632,13 @@
if (FrameView* view = mainFrame().view())
view->hide();
}
+
+ // Measure CPU usage of pages when they are no longer visible.
+ m_postBackgroundingCPUTime = std::nullopt;
+ if (isVisible)
+ m_postBackgroundingCPUUsageTimer.stop();
+ else if (Settings::isPostBackgroundingCPUUsageMeasurementEnabled() && allPages->size() == 1)
+ m_postBackgroundingCPUUsageTimer.startOneShot(cpuUsageMeasurementDelay);
}
void Page::setIsPrerender()
Modified: branches/safari-603-branch/Source/WebCore/page/Page.h (210878 => 210879)
--- branches/safari-603-branch/Source/WebCore/page/Page.h 2017-01-18 20:43:40 UTC (rev 210878)
+++ branches/safari-603-branch/Source/WebCore/page/Page.h 2017-01-18 20:43:44 UTC (rev 210879)
@@ -573,6 +573,7 @@
#endif
void measurePostLoadCPUUsage();
+ void measurePostBackgroundingCPUUsage();
enum ShouldHighlightMatches { DoNotHighlightMatches, HighlightMatches };
enum ShouldMarkMatches { DoNotMarkMatches, MarkMatches };
@@ -760,8 +761,10 @@
// For testing.
std::optional<EventThrottlingBehavior> m_eventThrottlingBehaviorOverride;
- Timer m_cpuUsageMeasurementTimer;
+ Timer m_postPageLoadCPUUsageTimer;
std::optional<CPUTime> m_postLoadCPUTime;
+ Timer m_postBackgroundingCPUUsageTimer;
+ std::optional<CPUTime> m_postBackgroundingCPUTime;
};
inline PageGroup& Page::group()
Modified: branches/safari-603-branch/Source/WebCore/page/Settings.cpp (210878 => 210879)
--- branches/safari-603-branch/Source/WebCore/page/Settings.cpp 2017-01-18 20:43:40 UTC (rev 210878)
+++ branches/safari-603-branch/Source/WebCore/page/Settings.cpp 2017-01-18 20:43:44 UTC (rev 210879)
@@ -787,6 +787,15 @@
#endif
}
+bool Settings::isPostBackgroundingCPUUsageMeasurementEnabled()
+{
+#if PLATFORM(MAC)
+ return true;
+#else
+ return false;
+#endif
+}
+
void Settings::setAllowsAnySSLCertificate(bool allowAnySSLCertificate)
{
gAllowsAnySSLCertificate = allowAnySSLCertificate;
Modified: branches/safari-603-branch/Source/WebCore/page/Settings.h (210878 => 210879)
--- branches/safari-603-branch/Source/WebCore/page/Settings.h 2017-01-18 20:43:40 UTC (rev 210878)
+++ branches/safari-603-branch/Source/WebCore/page/Settings.h 2017-01-18 20:43:44 UTC (rev 210879)
@@ -200,6 +200,7 @@
#endif
static bool isPostLoadCPUUsageMeasurementEnabled();
+ static bool isPostBackgroundingCPUUsageMeasurementEnabled();
static bool globalConstRedeclarationShouldThrow();