Changeset 196780 in webkit


Ignore:
Timestamp:
Feb 18, 2016 3:35:42 PM (8 years ago)
Author:
akling@apple.com
Message:

Fake memory pressure handler should log detailed memory breakdown.
<https://webkit.org/b/154415>

Reviewed by Antti Koivisto.

Piggyback on the RESOURCE_USAGE code to implement some detailed memory footprint diffing
and have the fake memory handler dump before/after/diff after it runs.

  • page/ResourceUsageThread.h:

(WebCore::TagInfo::TagInfo):

  • page/cocoa/ResourceUsageThreadCocoa.mm:

(WebCore::logFootprintComparison):
(WebCore::displayNameForVMTag):
(WebCore::pagesPerVMTag):
(WebCore::TagInfo::TagInfo): Deleted.

  • platform/cocoa/MemoryPressureHandlerCocoa.mm:

(WebCore::MemoryPressureHandler::install):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r196779 r196780  
     12016-02-18  Andreas Kling  <akling@apple.com>
     2
     3        Fake memory pressure handler should log detailed memory breakdown.
     4        <https://webkit.org/b/154415>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Piggyback on the RESOURCE_USAGE code to implement some detailed memory footprint diffing
     9        and have the fake memory handler dump before/after/diff after it runs.
     10
     11        * page/ResourceUsageThread.h:
     12        (WebCore::TagInfo::TagInfo):
     13        * page/cocoa/ResourceUsageThreadCocoa.mm:
     14        (WebCore::logFootprintComparison):
     15        (WebCore::displayNameForVMTag):
     16        (WebCore::pagesPerVMTag):
     17        (WebCore::TagInfo::TagInfo): Deleted.
     18        * platform/cocoa/MemoryPressureHandlerCocoa.mm:
     19        (WebCore::MemoryPressureHandler::install):
     20
    1212016-02-18  Brady Eidson  <beidson@apple.com>
    222
  • trunk/Source/WebCore/page/ResourceUsageThread.h

    r195644 r196780  
    3030
    3131#include "ResourceUsageData.h"
     32#include <array>
    3233#include <functional>
    3334#include <wtf/Condition.h>
     
    7374};
    7475
     76#if PLATFORM(COCOA)
     77struct TagInfo {
     78    TagInfo() { }
     79    size_t dirty { 0 };
     80    size_t reclaimable { 0 };
     81};
     82
     83const char* displayNameForVMTag(unsigned);
     84std::array<TagInfo, 256> pagesPerVMTag();
     85void logFootprintComparison(const std::array<TagInfo, 256>&, const std::array<TagInfo, 256>&);
     86#endif
     87
    7588} // namespace WebCore
    7689
  • trunk/Source/WebCore/page/cocoa/ResourceUsageThreadCocoa.mm

    r195644 r196780  
    5252}
    5353
    54 struct TagInfo {
    55     TagInfo() { }
    56     size_t dirty { 0 };
    57     size_t reclaimable { 0 };
    58 };
    59 
    60 static std::array<TagInfo, 256> pagesPerVMTag()
     54void logFootprintComparison(const std::array<TagInfo, 256>& before, const std::array<TagInfo, 256>& after)
     55{
     56    const size_t pageSize = vmPageSize();
     57
     58    WTFLogAlways("Per-tag breakdown of memory reclaimed by pressure handler:");
     59    WTFLogAlways("  ## %16s %10s %10s %10s", "VM Tag", "Before", "After", "Diff");
     60    for (unsigned i = 0; i < 256; ++i) {
     61        ssize_t dirtyBefore = before[i].dirty * pageSize;
     62        ssize_t dirtyAfter = after[i].dirty * pageSize;
     63        ssize_t dirtyDiff = dirtyAfter - dirtyBefore;
     64        if (!dirtyBefore && !dirtyAfter)
     65            continue;
     66        String tagName = displayNameForVMTag(i);
     67        if (!tagName)
     68            tagName = String::format("Tag %u", i);
     69        WTFLogAlways("  %02X %16s %10ld %10ld %10ld",
     70            i,
     71            tagName.ascii().data(),
     72            dirtyBefore,
     73            dirtyAfter,
     74            dirtyDiff
     75        );
     76    }
     77}
     78
     79const char* displayNameForVMTag(unsigned tag)
     80{
     81    switch (tag) {
     82    case VM_MEMORY_IOKIT: return "IOKit";
     83    case VM_MEMORY_LAYERKIT: return "CoreAnimation";
     84    case VM_MEMORY_IMAGEIO: return "ImageIO";
     85    case VM_MEMORY_CGIMAGE: return "CG image";
     86    case VM_MEMORY_JAVASCRIPT_JIT_EXECUTABLE_ALLOCATOR: return "JSC JIT";
     87    case VM_MEMORY_MALLOC: return "malloc";
     88    case VM_MEMORY_MALLOC_HUGE: return "malloc (huge)";
     89    case VM_MEMORY_MALLOC_LARGE: return "malloc (large)";
     90    case VM_MEMORY_MALLOC_SMALL: return "malloc (small)";
     91    case VM_MEMORY_MALLOC_TINY: return "malloc (tiny)";
     92    case VM_MEMORY_MALLOC_NANO: return "malloc (nano)";
     93    case VM_MEMORY_TCMALLOC: return "bmalloc";
     94    case VM_MEMORY_FOUNDATION: return "Foundation";
     95    case VM_MEMORY_STACK: return "Stack";
     96    case VM_MEMORY_SQLITE: return "SQLite";
     97    case VM_MEMORY_UNSHARED_PMAP: return "pmap (unshared)";
     98    case VM_MEMORY_DYLIB: return "dylib";
     99    case VM_MEMORY_CORESERVICES: return "CoreServices";
     100    case VM_MEMORY_OS_ALLOC_ONCE: return "os_alloc_once";
     101    case VM_MEMORY_LIBDISPATCH: return "libdispatch";
     102    default: return nullptr;
     103    }
     104}
     105
     106std::array<TagInfo, 256> pagesPerVMTag()
    61107{
    62108    std::array<TagInfo, 256> tags;
  • trunk/Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm

    r196753 r196780  
    3333#import "LayerPool.h"
    3434#import "Logging.h"
     35#import "ResourceUsageThread.h"
    3536#import "WebCoreSystemInterface.h"
    3637#import <mach/mach.h>
     
    3940#import <notify.h>
    4041#import <wtf/CurrentTime.h>
     42#import <sys/sysctl.h>
    4143
    4244#if PLATFORM(IOS)
     
    129131    // Allow simulation of memory pressure with "notifyutil -p org.WebKit.lowMemory"
    130132    notify_register_dispatch("org.WebKit.lowMemory", &_notifyToken, dispatch_get_main_queue(), ^(int) {
     133#if ENABLE(RESOURCE_USAGE)
     134        auto footprintBefore = pagesPerVMTag();
     135#endif
     136
    131137        bool wasUnderMemoryPressure = m_underMemoryPressure;
    132138        m_underMemoryPressure = true;
     
    137143
    138144        malloc_zone_pressure_relief(nullptr, 0);
     145
     146#if ENABLE(RESOURCE_USAGE)
     147        auto footprintAfter = pagesPerVMTag();
     148        logFootprintComparison(footprintBefore, footprintAfter);
     149#endif
    139150
    140151        // Since this is a simulation, unset the "under memory pressure" flag on next runloop.
Note: See TracChangeset for help on using the changeset viewer.