Changeset 211120 in webkit
- Timestamp:
- Jan 24, 2017, 4:15:00 PM (10 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 9 edited
-
ChangeLog (modified) (1 diff)
-
page/DiagnosticLoggingKeys.cpp (modified) (2 diffs)
-
page/DiagnosticLoggingKeys.h (modified) (2 diffs)
-
page/PerformanceLogging.cpp (modified) (1 diff)
-
page/PerformanceLogging.h (modified) (1 diff)
-
page/PerformanceMonitor.cpp (modified) (7 diffs)
-
page/PerformanceMonitor.h (modified) (2 diffs)
-
page/Settings.h (modified) (2 diffs)
-
page/cocoa/PerformanceLoggingCocoa.mm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r211118 r211120 1 2017-01-24 Andreas Kling <akling@apple.com> 2 3 Add memory footprint reporting using diagnostic logging. 4 <https://webkit.org/b/167285> 5 <rdar://problem/30151767> 6 7 Reviewed by Chris Dumez. 8 9 Add some basic logging of physical memory footprint post-load and post-backgrounding. 10 The logging works similarly to the CPU usage logging, though with slightly longer 11 delays to allow the measurement to stabilize. 12 13 * page/DiagnosticLoggingKeys.cpp: 14 (WebCore::DiagnosticLoggingKeys::memoryUsageKey): 15 (WebCore::DiagnosticLoggingKeys::memoryUsageToDiagnosticLoggingKey): 16 * page/DiagnosticLoggingKeys.h: 17 * page/PerformanceLogging.cpp: 18 (WebCore::PerformanceLogging::physicalFootprint): 19 * page/PerformanceLogging.h: 20 * page/PerformanceMonitor.cpp: 21 (WebCore::PerformanceMonitor::PerformanceMonitor): 22 (WebCore::PerformanceMonitor::didFinishLoad): 23 (WebCore::PerformanceMonitor::activityStateChanged): 24 (WebCore::PerformanceMonitor::measurePostLoadMemoryUsage): 25 (WebCore::PerformanceMonitor::measurePostBackgroundingMemoryUsage): 26 * page/PerformanceMonitor.h: 27 * page/Settings.h: 28 (WebCore::Settings::isPostLoadMemoryUsageMeasurementEnabled): 29 (WebCore::Settings::isPostBackgroundingMemoryUsageMeasurementEnabled): 30 * page/cocoa/PerformanceLoggingCocoa.mm: 31 (WebCore::PerformanceLogging::physicalFootprint): 32 1 33 2017-01-24 Joseph Pecoraro <pecoraro@apple.com> 2 34 -
trunk/Source/WebCore/page/DiagnosticLoggingKeys.cpp
r210936 r211120 329 329 } 330 330 331 String DiagnosticLoggingKeys::memoryUsageKey() 332 { 333 return ASCIILiteral("memoryUsage"); 334 } 335 331 336 String DiagnosticLoggingKeys::createSharedBufferFailedKey() 332 337 { … … 672 677 { 673 678 return ASCIILiteral("webGL"); 679 } 680 681 String DiagnosticLoggingKeys::memoryUsageToDiagnosticLoggingKey(uint64_t memoryUsage) 682 { 683 if (memoryUsage < 32 * MB) 684 return ASCIILiteral("below32"); 685 if (memoryUsage < 64 * MB) 686 return ASCIILiteral("32to64"); 687 if (memoryUsage < 128 * MB) 688 return ASCIILiteral("64to128"); 689 if (memoryUsage < 256 * MB) 690 return ASCIILiteral("128to256"); 691 if (memoryUsage < 512 * MB) 692 return ASCIILiteral("256to512"); 693 if (memoryUsage < 1024 * MB) 694 return ASCIILiteral("512to1024"); 695 if (memoryUsage < 2048 * MB) 696 return ASCIILiteral("1024to2048"); 697 if (memoryUsage < 4096llu * MB) 698 return ASCIILiteral("2048to4096"); 699 if (memoryUsage < 8192llu * MB) 700 return ASCIILiteral("4096to8192"); 701 if (memoryUsage < 16384llu * MB) 702 return ASCIILiteral("8192to16384"); 703 if (memoryUsage < 32768llu * MB) 704 return ASCIILiteral("16384to32768"); 705 return ASCIILiteral("over32768"); 674 706 } 675 707 -
trunk/Source/WebCore/page/DiagnosticLoggingKeys.h
r210936 r211120 42 42 static String cannotSuspendActiveDOMObjectsKey(); 43 43 WEBCORE_EXPORT static String cpuUsageKey(); 44 WEBCORE_EXPORT static String memoryUsageKey(); 44 45 WEBCORE_EXPORT static String createSharedBufferFailedKey(); 45 46 WEBCORE_EXPORT static String deltaKey(); … … 160 161 WEBCORE_EXPORT static String zoomedKey(); 161 162 163 WEBCORE_EXPORT static String memoryUsageToDiagnosticLoggingKey(uint64_t memoryUsage); 162 164 WEBCORE_EXPORT static String foregroundCPUUsageToDiagnosticLoggingKey(double cpuUsage); 163 165 WEBCORE_EXPORT static String backgroundCPUUsageToDiagnosticLoggingKey(double cpuUsage); -
trunk/Source/WebCore/page/PerformanceLogging.cpp
r209683 r211120 104 104 #if !PLATFORM(COCOA) 105 105 void PerformanceLogging::getPlatformMemoryUsageStatistics(HashMap<const char*, size_t>&) { } 106 std::optional<uint64_t> PerformanceLogging::physicalFootprint() { return std::nullopt; } 106 107 #endif 107 108 -
trunk/Source/WebCore/page/PerformanceLogging.h
r209346 r211120 50 50 WEBCORE_EXPORT static HashCountedSet<const char*> javaScriptObjectCounts(); 51 51 WEBCORE_EXPORT static HashMap<const char*, size_t> memoryUsageStatistics(ShouldIncludeExpensiveComputations); 52 WEBCORE_EXPORT static std::optional<uint64_t> physicalFootprint(); 52 53 53 54 private: -
trunk/Source/WebCore/page/PerformanceMonitor.cpp
r210936 r211120 33 33 #include "Logging.h" 34 34 #include "Page.h" 35 #include "PerformanceLogging.h" 35 36 #include "Settings.h" 36 37 … … 43 44 static const std::chrono::minutes backgroundCPUUsageMeasurementDuration { 5 }; 44 45 static const std::chrono::minutes cpuUsageSamplingInterval { 10 }; 46 47 static const std::chrono::seconds memoryUsageMeasurementDelay { 10 }; 45 48 46 49 static inline ActivityStateForCPUSampling activityStateForCPUSampling(ActivityState::Flags state) … … 58 61 , m_postBackgroundingCPUUsageTimer(*this, &PerformanceMonitor::measurePostBackgroundingCPUUsage) 59 62 , m_perActivityStateCPUUsageTimer(*this, &PerformanceMonitor::measurePerActivityStateCPUUsage) 63 , m_postPageLoadMemoryUsageTimer(*this, &PerformanceMonitor::measurePostLoadMemoryUsage) 64 , m_postBackgroundingMemoryUsageTimer(*this, &PerformanceMonitor::measurePostBackgroundingMemoryUsage) 60 65 { 61 66 ASSERT(!page.isUtilityPage()); … … 71 76 m_postLoadCPUTime = std::nullopt; 72 77 m_postPageLoadCPUUsageTimer.stop(); 78 m_postPageLoadMemoryUsageTimer.stop(); 73 79 } 74 80 … … 80 86 m_postPageLoadCPUUsageTimer.startOneShot(cpuUsageMeasurementDelay); 81 87 } 88 89 // Likewise for post-load memory usage measurement. 90 if (Settings::isPostLoadMemoryUsageMeasurementEnabled() && m_page.isOnlyNonUtilityPage()) 91 m_postPageLoadMemoryUsageTimer.startOneShot(memoryUsageMeasurementDelay); 82 92 } 83 93 … … 104 114 } 105 115 } 116 117 if (Settings::isPostBackgroundingMemoryUsageMeasurementEnabled() && visibilityChanged) { 118 if (newState & ActivityState::IsVisible) 119 m_postBackgroundingMemoryUsageTimer.stop(); 120 else if (m_page.isOnlyNonUtilityPage()) 121 m_postBackgroundingMemoryUsageTimer.startOneShot(memoryUsageMeasurementDelay); 122 } 106 123 } 107 124 … … 126 143 RELEASE_LOG_IF_ALLOWED(PerformanceLogging, "measurePostLoadCPUUsage: Process was using %.1f%% CPU after the page load.", cpuUsage); 127 144 m_page.diagnosticLoggingClient().logDiagnosticMessageWithValue(DiagnosticLoggingKeys::postPageLoadKey(), DiagnosticLoggingKeys::cpuUsageKey(), DiagnosticLoggingKeys::foregroundCPUUsageToDiagnosticLoggingKey(cpuUsage), ShouldSample::No); 145 } 146 147 void PerformanceMonitor::measurePostLoadMemoryUsage() 148 { 149 if (!m_page.isOnlyNonUtilityPage()) 150 return; 151 152 std::optional<uint64_t> memoryUsage = PerformanceLogging::physicalFootprint(); 153 if (!memoryUsage) 154 return; 155 156 RELEASE_LOG_IF_ALLOWED(PerformanceLogging, "measurePostLoadMemoryUsage: Process was using %llu bytes of memory after the page load.", memoryUsage.value()); 157 m_page.diagnosticLoggingClient().logDiagnosticMessageWithValue(DiagnosticLoggingKeys::postPageLoadKey(), DiagnosticLoggingKeys::memoryUsageKey(), DiagnosticLoggingKeys::memoryUsageToDiagnosticLoggingKey(memoryUsage.value()), ShouldSample::No); 158 } 159 160 void PerformanceMonitor::measurePostBackgroundingMemoryUsage() 161 { 162 if (!m_page.isOnlyNonUtilityPage()) 163 return; 164 165 std::optional<uint64_t> memoryUsage = PerformanceLogging::physicalFootprint(); 166 if (!memoryUsage) 167 return; 168 169 RELEASE_LOG_IF_ALLOWED(PerformanceLogging, "measurePostBackgroundingMemoryUsage: Process was using %llu bytes of memory after becoming non visible.", memoryUsage.value()); 170 m_page.diagnosticLoggingClient().logDiagnosticMessageWithValue(DiagnosticLoggingKeys::postPageBackgroundingKey(), DiagnosticLoggingKeys::memoryUsageKey(), DiagnosticLoggingKeys::memoryUsageToDiagnosticLoggingKey(memoryUsage.value()), ShouldSample::No); 128 171 } 129 172 -
trunk/Source/WebCore/page/PerformanceMonitor.h
r210936 r211120 49 49 void measureCPUUsageInActivityState(ActivityStateForCPUSampling); 50 50 51 void measurePostLoadMemoryUsage(); 52 void measurePostBackgroundingMemoryUsage(); 53 51 54 Page& m_page; 52 55 … … 57 60 Timer m_perActivityStateCPUUsageTimer; 58 61 std::optional<CPUTime> m_perActivityStateCPUTime; 62 63 Timer m_postPageLoadMemoryUsageTimer; 64 Timer m_postBackgroundingMemoryUsageTimer; 59 65 }; 60 66 -
trunk/Source/WebCore/page/Settings.h
r210936 r211120 204 204 static bool isPerActivityStateCPUUsageMeasurementEnabled(); 205 205 206 static bool isPostLoadMemoryUsageMeasurementEnabled(); 207 static bool isPostBackgroundingMemoryUsageMeasurementEnabled(); 208 206 209 static bool globalConstRedeclarationShouldThrow(); 207 210 … … 452 455 } 453 456 457 inline bool Settings::isPostLoadMemoryUsageMeasurementEnabled() 458 { 459 #if PLATFORM(COCOA) 460 return true; 461 #else 462 return false; 463 #endif 464 } 465 466 inline bool Settings::isPostBackgroundingMemoryUsageMeasurementEnabled() 467 { 468 #if PLATFORM(MAC) 469 return true; 470 #else 471 return false; 472 #endif 473 } 474 454 475 } // namespace WebCore -
trunk/Source/WebCore/page/cocoa/PerformanceLoggingCocoa.mm
r209346 r211120 32 32 namespace WebCore { 33 33 34 std::optional<uint64_t> PerformanceLogging::physicalFootprint() 35 { 36 task_vm_info_data_t vmInfo; 37 mach_msg_type_number_t count = TASK_VM_INFO_COUNT; 38 kern_return_t result = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t) &vmInfo, &count); 39 if (result != KERN_SUCCESS) 40 return std::nullopt; 41 return vmInfo.phys_footprint; 42 } 43 34 44 void PerformanceLogging::getPlatformMemoryUsageStatistics(HashMap<const char*, size_t>& stats) 35 45 {
Note:
See TracChangeset
for help on using the changeset viewer.