Diff
Modified: branches/safari-603-branch/Source/WebCore/ChangeLog (211187 => 211188)
--- branches/safari-603-branch/Source/WebCore/ChangeLog 2017-01-26 01:41:00 UTC (rev 211187)
+++ branches/safari-603-branch/Source/WebCore/ChangeLog 2017-01-26 01:41:04 UTC (rev 211188)
@@ -1,5 +1,41 @@
2017-01-25 Matthew Hanson <[email protected]>
+ Merge r211120. rdar://problem/30151767
+
+ 2017-01-24 Andreas Kling <[email protected]>
+
+ Add memory footprint reporting using diagnostic logging.
+ <https://webkit.org/b/167285>
+ <rdar://problem/30151767>
+
+ Reviewed by Chris Dumez.
+
+ Add some basic logging of physical memory footprint post-load and post-backgrounding.
+ The logging works similarly to the CPU usage logging, though with slightly longer
+ delays to allow the measurement to stabilize.
+
+ * page/DiagnosticLoggingKeys.cpp:
+ (WebCore::DiagnosticLoggingKeys::memoryUsageKey):
+ (WebCore::DiagnosticLoggingKeys::memoryUsageToDiagnosticLoggingKey):
+ * page/DiagnosticLoggingKeys.h:
+ * page/PerformanceLogging.cpp:
+ (WebCore::PerformanceLogging::physicalFootprint):
+ * page/PerformanceLogging.h:
+ * page/PerformanceMonitor.cpp:
+ (WebCore::PerformanceMonitor::PerformanceMonitor):
+ (WebCore::PerformanceMonitor::didFinishLoad):
+ (WebCore::PerformanceMonitor::activityStateChanged):
+ (WebCore::PerformanceMonitor::measurePostLoadMemoryUsage):
+ (WebCore::PerformanceMonitor::measurePostBackgroundingMemoryUsage):
+ * page/PerformanceMonitor.h:
+ * page/Settings.h:
+ (WebCore::Settings::isPostLoadMemoryUsageMeasurementEnabled):
+ (WebCore::Settings::isPostBackgroundingMemoryUsageMeasurementEnabled):
+ * page/cocoa/PerformanceLoggingCocoa.mm:
+ (WebCore::PerformanceLogging::physicalFootprint):
+
+2017-01-25 Matthew Hanson <[email protected]>
+
Merge r211125. rdar://problem/30074665
2017-01-24 Brent Fulgham <[email protected]>
Modified: branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.cpp (211187 => 211188)
--- branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.cpp 2017-01-26 01:41:00 UTC (rev 211187)
+++ branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.cpp 2017-01-26 01:41:04 UTC (rev 211188)
@@ -328,6 +328,11 @@
return ASCIILiteral("cpuUsage");
}
+String DiagnosticLoggingKeys::memoryUsageKey()
+{
+ return ASCIILiteral("memoryUsage");
+}
+
String DiagnosticLoggingKeys::createSharedBufferFailedKey()
{
return ASCIILiteral("createSharedBufferFailed");
@@ -673,6 +678,33 @@
return ASCIILiteral("webGL");
}
+String DiagnosticLoggingKeys::memoryUsageToDiagnosticLoggingKey(uint64_t memoryUsage)
+{
+ if (memoryUsage < 32 * MB)
+ return ASCIILiteral("below32");
+ if (memoryUsage < 64 * MB)
+ return ASCIILiteral("32to64");
+ if (memoryUsage < 128 * MB)
+ return ASCIILiteral("64to128");
+ if (memoryUsage < 256 * MB)
+ return ASCIILiteral("128to256");
+ if (memoryUsage < 512 * MB)
+ return ASCIILiteral("256to512");
+ if (memoryUsage < 1024 * MB)
+ return ASCIILiteral("512to1024");
+ if (memoryUsage < 2048 * MB)
+ return ASCIILiteral("1024to2048");
+ if (memoryUsage < 4096llu * MB)
+ return ASCIILiteral("2048to4096");
+ if (memoryUsage < 8192llu * MB)
+ return ASCIILiteral("4096to8192");
+ if (memoryUsage < 16384llu * MB)
+ return ASCIILiteral("8192to16384");
+ if (memoryUsage < 32768llu * MB)
+ return ASCIILiteral("16384to32768");
+ return ASCIILiteral("over32768");
+}
+
String DiagnosticLoggingKeys::foregroundCPUUsageToDiagnosticLoggingKey(double cpuUsage)
{
if (cpuUsage < 10)
Modified: branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.h (211187 => 211188)
--- branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.h 2017-01-26 01:41:00 UTC (rev 211187)
+++ branches/safari-603-branch/Source/WebCore/page/DiagnosticLoggingKeys.h 2017-01-26 01:41:04 UTC (rev 211188)
@@ -41,6 +41,7 @@
static String canCacheKey();
static String cannotSuspendActiveDOMObjectsKey();
WEBCORE_EXPORT static String cpuUsageKey();
+ WEBCORE_EXPORT static String memoryUsageKey();
WEBCORE_EXPORT static String createSharedBufferFailedKey();
WEBCORE_EXPORT static String deltaKey();
static String deniedByClientKey();
@@ -159,6 +160,7 @@
WEBCORE_EXPORT static String webViewKey();
WEBCORE_EXPORT static String zoomedKey();
+ WEBCORE_EXPORT static String memoryUsageToDiagnosticLoggingKey(uint64_t memoryUsage);
WEBCORE_EXPORT static String foregroundCPUUsageToDiagnosticLoggingKey(double cpuUsage);
WEBCORE_EXPORT static String backgroundCPUUsageToDiagnosticLoggingKey(double cpuUsage);
Modified: branches/safari-603-branch/Source/WebCore/page/PerformanceLogging.cpp (211187 => 211188)
--- branches/safari-603-branch/Source/WebCore/page/PerformanceLogging.cpp 2017-01-26 01:41:00 UTC (rev 211187)
+++ branches/safari-603-branch/Source/WebCore/page/PerformanceLogging.cpp 2017-01-26 01:41:04 UTC (rev 211188)
@@ -103,6 +103,7 @@
#if !PLATFORM(COCOA)
void PerformanceLogging::getPlatformMemoryUsageStatistics(HashMap<const char*, size_t>&) { }
+std::optional<uint64_t> PerformanceLogging::physicalFootprint() { return std::nullopt; }
#endif
}
Modified: branches/safari-603-branch/Source/WebCore/page/PerformanceLogging.h (211187 => 211188)
--- branches/safari-603-branch/Source/WebCore/page/PerformanceLogging.h 2017-01-26 01:41:00 UTC (rev 211187)
+++ branches/safari-603-branch/Source/WebCore/page/PerformanceLogging.h 2017-01-26 01:41:04 UTC (rev 211188)
@@ -49,6 +49,7 @@
WEBCORE_EXPORT static HashCountedSet<const char*> _javascript_ObjectCounts();
WEBCORE_EXPORT static HashMap<const char*, size_t> memoryUsageStatistics(ShouldIncludeExpensiveComputations);
+ WEBCORE_EXPORT static std::optional<uint64_t> physicalFootprint();
private:
static void getPlatformMemoryUsageStatistics(HashMap<const char*, size_t>&);
Modified: branches/safari-603-branch/Source/WebCore/page/PerformanceMonitor.cpp (211187 => 211188)
--- branches/safari-603-branch/Source/WebCore/page/PerformanceMonitor.cpp 2017-01-26 01:41:00 UTC (rev 211187)
+++ branches/safari-603-branch/Source/WebCore/page/PerformanceMonitor.cpp 2017-01-26 01:41:04 UTC (rev 211188)
@@ -32,6 +32,7 @@
#include "DiagnosticLoggingKeys.h"
#include "Logging.h"
#include "Page.h"
+#include "PerformanceLogging.h"
#include "Settings.h"
namespace WebCore {
@@ -43,6 +44,8 @@
static const std::chrono::minutes backgroundCPUUsageMeasurementDuration { 5 };
static const std::chrono::minutes cpuUsageSamplingInterval { 10 };
+static const std::chrono::seconds memoryUsageMeasurementDelay { 10 };
+
static inline ActivityStateForCPUSampling activityStateForCPUSampling(ActivityState::Flags state)
{
if (!(state & ActivityState::IsVisible))
@@ -57,6 +60,8 @@
, m_postPageLoadCPUUsageTimer(*this, &PerformanceMonitor::measurePostLoadCPUUsage)
, m_postBackgroundingCPUUsageTimer(*this, &PerformanceMonitor::measurePostBackgroundingCPUUsage)
, m_perActivityStateCPUUsageTimer(*this, &PerformanceMonitor::measurePerActivityStateCPUUsage)
+ , m_postPageLoadMemoryUsageTimer(*this, &PerformanceMonitor::measurePostLoadMemoryUsage)
+ , m_postBackgroundingMemoryUsageTimer(*this, &PerformanceMonitor::measurePostBackgroundingMemoryUsage)
{
ASSERT(!page.isUtilityPage());
@@ -70,6 +75,7 @@
{
m_postLoadCPUTime = std::nullopt;
m_postPageLoadCPUUsageTimer.stop();
+ m_postPageLoadMemoryUsageTimer.stop();
}
void PerformanceMonitor::didFinishLoad()
@@ -79,6 +85,10 @@
m_postLoadCPUTime = std::nullopt;
m_postPageLoadCPUUsageTimer.startOneShot(cpuUsageMeasurementDelay);
}
+
+ // Likewise for post-load memory usage measurement.
+ if (Settings::isPostLoadMemoryUsageMeasurementEnabled() && m_page.isOnlyNonUtilityPage())
+ m_postPageLoadMemoryUsageTimer.startOneShot(memoryUsageMeasurementDelay);
}
void PerformanceMonitor::activityStateChanged(ActivityState::Flags oldState, ActivityState::Flags newState)
@@ -103,6 +113,13 @@
m_perActivityStateCPUUsageTimer.startRepeating(cpuUsageSamplingInterval);
}
}
+
+ if (Settings::isPostBackgroundingMemoryUsageMeasurementEnabled() && visibilityChanged) {
+ if (newState & ActivityState::IsVisible)
+ m_postBackgroundingMemoryUsageTimer.stop();
+ else if (m_page.isOnlyNonUtilityPage())
+ m_postBackgroundingMemoryUsageTimer.startOneShot(memoryUsageMeasurementDelay);
+ }
}
void PerformanceMonitor::measurePostLoadCPUUsage()
@@ -127,6 +144,32 @@
m_page.diagnosticLoggingClient().logDiagnosticMessageWithValue(DiagnosticLoggingKeys::postPageLoadKey(), DiagnosticLoggingKeys::cpuUsageKey(), DiagnosticLoggingKeys::foregroundCPUUsageToDiagnosticLoggingKey(cpuUsage), ShouldSample::No);
}
+void PerformanceMonitor::measurePostLoadMemoryUsage()
+{
+ if (!m_page.isOnlyNonUtilityPage())
+ return;
+
+ std::optional<uint64_t> memoryUsage = PerformanceLogging::physicalFootprint();
+ if (!memoryUsage)
+ return;
+
+ RELEASE_LOG_IF_ALLOWED(PerformanceLogging, "measurePostLoadMemoryUsage: Process was using %llu bytes of memory after the page load.", memoryUsage.value());
+ m_page.diagnosticLoggingClient().logDiagnosticMessageWithValue(DiagnosticLoggingKeys::postPageLoadKey(), DiagnosticLoggingKeys::memoryUsageKey(), DiagnosticLoggingKeys::memoryUsageToDiagnosticLoggingKey(memoryUsage.value()), ShouldSample::No);
+}
+
+void PerformanceMonitor::measurePostBackgroundingMemoryUsage()
+{
+ if (!m_page.isOnlyNonUtilityPage())
+ return;
+
+ std::optional<uint64_t> memoryUsage = PerformanceLogging::physicalFootprint();
+ if (!memoryUsage)
+ return;
+
+ RELEASE_LOG_IF_ALLOWED(PerformanceLogging, "measurePostBackgroundingMemoryUsage: Process was using %llu bytes of memory after becoming non visible.", memoryUsage.value());
+ m_page.diagnosticLoggingClient().logDiagnosticMessageWithValue(DiagnosticLoggingKeys::postPageBackgroundingKey(), DiagnosticLoggingKeys::memoryUsageKey(), DiagnosticLoggingKeys::memoryUsageToDiagnosticLoggingKey(memoryUsage.value()), ShouldSample::No);
+}
+
void PerformanceMonitor::measurePostBackgroundingCPUUsage()
{
if (!m_page.isOnlyNonUtilityPage()) {
Modified: branches/safari-603-branch/Source/WebCore/page/PerformanceMonitor.h (211187 => 211188)
--- branches/safari-603-branch/Source/WebCore/page/PerformanceMonitor.h 2017-01-26 01:41:00 UTC (rev 211187)
+++ branches/safari-603-branch/Source/WebCore/page/PerformanceMonitor.h 2017-01-26 01:41:04 UTC (rev 211188)
@@ -48,6 +48,9 @@
void measurePerActivityStateCPUUsage();
void measureCPUUsageInActivityState(ActivityStateForCPUSampling);
+ void measurePostLoadMemoryUsage();
+ void measurePostBackgroundingMemoryUsage();
+
Page& m_page;
Timer m_postPageLoadCPUUsageTimer;
@@ -56,6 +59,9 @@
std::optional<CPUTime> m_postBackgroundingCPUTime;
Timer m_perActivityStateCPUUsageTimer;
std::optional<CPUTime> m_perActivityStateCPUTime;
+
+ Timer m_postPageLoadMemoryUsageTimer;
+ Timer m_postBackgroundingMemoryUsageTimer;
};
}
Modified: branches/safari-603-branch/Source/WebCore/page/Settings.h (211187 => 211188)
--- branches/safari-603-branch/Source/WebCore/page/Settings.h 2017-01-26 01:41:00 UTC (rev 211187)
+++ branches/safari-603-branch/Source/WebCore/page/Settings.h 2017-01-26 01:41:04 UTC (rev 211188)
@@ -203,6 +203,9 @@
static bool isPostBackgroundingCPUUsageMeasurementEnabled();
static bool isPerActivityStateCPUUsageMeasurementEnabled();
+ static bool isPostLoadMemoryUsageMeasurementEnabled();
+ static bool isPostBackgroundingMemoryUsageMeasurementEnabled();
+
static bool globalConstRedeclarationShouldThrow();
WEBCORE_EXPORT void setBackgroundShouldExtendBeyondPage(bool);
@@ -451,4 +454,22 @@
#endif
}
+inline bool Settings::isPostLoadMemoryUsageMeasurementEnabled()
+{
+#if PLATFORM(COCOA)
+ return true;
+#else
+ return false;
+#endif
+}
+
+inline bool Settings::isPostBackgroundingMemoryUsageMeasurementEnabled()
+{
+#if PLATFORM(MAC)
+ return true;
+#else
+ return false;
+#endif
+}
+
} // namespace WebCore
Modified: branches/safari-603-branch/Source/WebCore/page/cocoa/PerformanceLoggingCocoa.mm (211187 => 211188)
--- branches/safari-603-branch/Source/WebCore/page/cocoa/PerformanceLoggingCocoa.mm 2017-01-26 01:41:00 UTC (rev 211187)
+++ branches/safari-603-branch/Source/WebCore/page/cocoa/PerformanceLoggingCocoa.mm 2017-01-26 01:41:04 UTC (rev 211188)
@@ -31,6 +31,16 @@
namespace WebCore {
+std::optional<uint64_t> PerformanceLogging::physicalFootprint()
+{
+ task_vm_info_data_t vmInfo;
+ mach_msg_type_number_t count = TASK_VM_INFO_COUNT;
+ kern_return_t result = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t) &vmInfo, &count);
+ if (result != KERN_SUCCESS)
+ return std::nullopt;
+ return vmInfo.phys_footprint;
+}
+
void PerformanceLogging::getPlatformMemoryUsageStatistics(HashMap<const char*, size_t>& stats)
{
task_vm_info_data_t vmInfo;