⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 211120 in webkit


Ignore:
Timestamp:
Jan 24, 2017, 4:15:00 PM (10 years ago)
Author:
akling@apple.com
Message:

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):

Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r211118 r211120  
     12017-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
    1332017-01-24  Joseph Pecoraro  <pecoraro@apple.com>
    234
  • trunk/Source/WebCore/page/DiagnosticLoggingKeys.cpp

    r210936 r211120  
    329329}
    330330
     331String DiagnosticLoggingKeys::memoryUsageKey()
     332{
     333    return ASCIILiteral("memoryUsage");
     334}
     335
    331336String DiagnosticLoggingKeys::createSharedBufferFailedKey()
    332337{
     
    672677{
    673678    return ASCIILiteral("webGL");
     679}
     680
     681String 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");
    674706}
    675707
  • trunk/Source/WebCore/page/DiagnosticLoggingKeys.h

    r210936 r211120  
    4242    static String cannotSuspendActiveDOMObjectsKey();
    4343    WEBCORE_EXPORT static String cpuUsageKey();
     44    WEBCORE_EXPORT static String memoryUsageKey();
    4445    WEBCORE_EXPORT static String createSharedBufferFailedKey();
    4546    WEBCORE_EXPORT static String deltaKey();
     
    160161    WEBCORE_EXPORT static String zoomedKey();
    161162
     163    WEBCORE_EXPORT static String memoryUsageToDiagnosticLoggingKey(uint64_t memoryUsage);
    162164    WEBCORE_EXPORT static String foregroundCPUUsageToDiagnosticLoggingKey(double cpuUsage);
    163165    WEBCORE_EXPORT static String backgroundCPUUsageToDiagnosticLoggingKey(double cpuUsage);
  • trunk/Source/WebCore/page/PerformanceLogging.cpp

    r209683 r211120  
    104104#if !PLATFORM(COCOA)
    105105void PerformanceLogging::getPlatformMemoryUsageStatistics(HashMap<const char*, size_t>&) { }
     106std::optional<uint64_t> PerformanceLogging::physicalFootprint() { return std::nullopt; }
    106107#endif
    107108
  • trunk/Source/WebCore/page/PerformanceLogging.h

    r209346 r211120  
    5050    WEBCORE_EXPORT static HashCountedSet<const char*> javaScriptObjectCounts();
    5151    WEBCORE_EXPORT static HashMap<const char*, size_t> memoryUsageStatistics(ShouldIncludeExpensiveComputations);
     52    WEBCORE_EXPORT static std::optional<uint64_t> physicalFootprint();
    5253
    5354private:
  • trunk/Source/WebCore/page/PerformanceMonitor.cpp

    r210936 r211120  
    3333#include "Logging.h"
    3434#include "Page.h"
     35#include "PerformanceLogging.h"
    3536#include "Settings.h"
    3637
     
    4344static const std::chrono::minutes backgroundCPUUsageMeasurementDuration { 5 };
    4445static const std::chrono::minutes cpuUsageSamplingInterval { 10 };
     46
     47static const std::chrono::seconds memoryUsageMeasurementDelay { 10 };
    4548
    4649static inline ActivityStateForCPUSampling activityStateForCPUSampling(ActivityState::Flags state)
     
    5861    , m_postBackgroundingCPUUsageTimer(*this, &PerformanceMonitor::measurePostBackgroundingCPUUsage)
    5962    , m_perActivityStateCPUUsageTimer(*this, &PerformanceMonitor::measurePerActivityStateCPUUsage)
     63    , m_postPageLoadMemoryUsageTimer(*this, &PerformanceMonitor::measurePostLoadMemoryUsage)
     64    , m_postBackgroundingMemoryUsageTimer(*this, &PerformanceMonitor::measurePostBackgroundingMemoryUsage)
    6065{
    6166    ASSERT(!page.isUtilityPage());
     
    7176    m_postLoadCPUTime = std::nullopt;
    7277    m_postPageLoadCPUUsageTimer.stop();
     78    m_postPageLoadMemoryUsageTimer.stop();
    7379}
    7480
     
    8086        m_postPageLoadCPUUsageTimer.startOneShot(cpuUsageMeasurementDelay);
    8187    }
     88
     89    // Likewise for post-load memory usage measurement.
     90    if (Settings::isPostLoadMemoryUsageMeasurementEnabled() && m_page.isOnlyNonUtilityPage())
     91        m_postPageLoadMemoryUsageTimer.startOneShot(memoryUsageMeasurementDelay);
    8292}
    8393
     
    104114        }
    105115    }
     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    }
    106123}
    107124
     
    126143    RELEASE_LOG_IF_ALLOWED(PerformanceLogging, "measurePostLoadCPUUsage: Process was using %.1f%% CPU after the page load.", cpuUsage);
    127144    m_page.diagnosticLoggingClient().logDiagnosticMessageWithValue(DiagnosticLoggingKeys::postPageLoadKey(), DiagnosticLoggingKeys::cpuUsageKey(), DiagnosticLoggingKeys::foregroundCPUUsageToDiagnosticLoggingKey(cpuUsage), ShouldSample::No);
     145}
     146
     147void 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
     160void 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);
    128171}
    129172
  • trunk/Source/WebCore/page/PerformanceMonitor.h

    r210936 r211120  
    4949    void measureCPUUsageInActivityState(ActivityStateForCPUSampling);
    5050
     51    void measurePostLoadMemoryUsage();
     52    void measurePostBackgroundingMemoryUsage();
     53
    5154    Page& m_page;
    5255
     
    5760    Timer m_perActivityStateCPUUsageTimer;
    5861    std::optional<CPUTime> m_perActivityStateCPUTime;
     62
     63    Timer m_postPageLoadMemoryUsageTimer;
     64    Timer m_postBackgroundingMemoryUsageTimer;
    5965};
    6066
  • trunk/Source/WebCore/page/Settings.h

    r210936 r211120  
    204204    static bool isPerActivityStateCPUUsageMeasurementEnabled();
    205205
     206    static bool isPostLoadMemoryUsageMeasurementEnabled();
     207    static bool isPostBackgroundingMemoryUsageMeasurementEnabled();
     208
    206209    static bool globalConstRedeclarationShouldThrow();
    207210
     
    452455}
    453456
     457inline bool Settings::isPostLoadMemoryUsageMeasurementEnabled()
     458{
     459#if PLATFORM(COCOA)
     460    return true;
     461#else
     462    return false;
     463#endif
     464}
     465
     466inline bool Settings::isPostBackgroundingMemoryUsageMeasurementEnabled()
     467{
     468#if PLATFORM(MAC)
     469    return true;
     470#else
     471    return false;
     472#endif
     473}
     474
    454475} // namespace WebCore
  • trunk/Source/WebCore/page/cocoa/PerformanceLoggingCocoa.mm

    r209346 r211120  
    3232namespace WebCore {
    3333
     34std::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
    3444void PerformanceLogging::getPlatformMemoryUsageStatistics(HashMap<const char*, size_t>& stats)
    3545{
Note: See TracChangeset for help on using the changeset viewer.