Changeset 232098 in webkit


Ignore:
Timestamp:
May 22, 2018 7:36:04 PM (6 years ago)
Author:
Simon Fraser
Message:

Add notifyutil callbacks to dump the memory cache, and the list of live Pages and Documents
https://bugs.webkit.org/show_bug.cgi?id=185853

Reviewed by Keith Miller.
Source/WebCore:

Add a notifyutil callback to dump the PageCache, which dumps the stats, and the list of live pages.
This can be invoked on iOS and macOS via "notifyutil -p com.apple.WebKit.showPageCache".

Add a notifyutil callback that dumps the list of all Pages, and the list of all Documents, with
Document pointer address and URL.
This can be invoked on iOS and macOS via "notifyutil -p com.apple.WebKit.showAllDocuments".

  • history/PageCache.cpp:

(WebCore::PageCache::PageCache):
(WebCore::PageCache::dump const):

  • history/PageCache.h:
  • loader/cache/CachedResource.h:

(WebCore::CachedResource::numberOfClients const):
(WebCore::CachedResource::count const): Deleted.

  • loader/cache/MemoryCache.cpp:

(WebCore::MemoryCache::MemoryCache):
(WebCore::MemoryCache::pruneLiveResourcesToSize):
(WebCore::MemoryCache::dumpStats):
(WebCore::MemoryCache::dumpLRULists const):

  • loader/cache/MemoryCache.h:
  • page/mac/PageMac.mm:

(WebCore::Page::platformInitialize):

Source/WebCore/PAL:

Compile registerNotifyCallback in release builds.

  • pal/Logging.cpp:

(PAL::registerNotifyCallback):

  • pal/Logging.h:
Location:
trunk/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r232094 r232098  
     12018-05-22  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Add notifyutil callbacks to dump the memory cache, and the list of live Pages and Documents
     4        https://bugs.webkit.org/show_bug.cgi?id=185853
     5
     6        Reviewed by Keith Miller.
     7
     8        Add a notifyutil callback to dump the PageCache, which dumps the stats, and the list of live pages.
     9        This can be invoked on iOS and macOS via "notifyutil -p com.apple.WebKit.showPageCache".
     10       
     11        Add a notifyutil callback that dumps the list of all Pages, and the list of all Documents, with
     12        Document pointer address and URL.
     13        This can be invoked on iOS and macOS via "notifyutil -p com.apple.WebKit.showAllDocuments".
     14
     15        * history/PageCache.cpp:
     16        (WebCore::PageCache::PageCache):
     17        (WebCore::PageCache::dump const):
     18        * history/PageCache.h:
     19        * loader/cache/CachedResource.h:
     20        (WebCore::CachedResource::numberOfClients const):
     21        (WebCore::CachedResource::count const): Deleted.
     22        * loader/cache/MemoryCache.cpp:
     23        (WebCore::MemoryCache::MemoryCache):
     24        (WebCore::MemoryCache::pruneLiveResourcesToSize):
     25        (WebCore::MemoryCache::dumpStats):
     26        (WebCore::MemoryCache::dumpLRULists const):
     27        * loader/cache/MemoryCache.h:
     28        * page/mac/PageMac.mm:
     29        (WebCore::Page::platformInitialize):
     30
    1312018-05-22  Dean Jackson  <dino@apple.com>
    232
  • trunk/Source/WebCore/PAL/ChangeLog

    r232069 r232098  
     12018-05-22  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Add notifyutil callbacks to dump the memory cache, and the list of live Pages and Documents
     4        https://bugs.webkit.org/show_bug.cgi?id=185853
     5
     6        Reviewed by Keith Miller.
     7       
     8        Compile registerNotifyCallback in release builds.
     9
     10        * pal/Logging.cpp:
     11        (PAL::registerNotifyCallback):
     12        * pal/Logging.h:
     13
    1142018-05-22  Ryan Haddad  <ryanhaddad@apple.com>
    215
  • trunk/Source/WebCore/PAL/pal/Logging.cpp

    r223206 r232098  
    8282}
    8383
    84 #ifndef NDEBUG
     84#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
     85
    8586void registerNotifyCallback(const String& notifyID, WTF::Function<void()>&& callback)
    8687{
     
    9596#endif
    9697}
    97 #endif
    98 
    99 #endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
    10098
    10199} // namespace WebCore
  • trunk/Source/WebCore/PAL/pal/Logging.h

    r223206 r232098  
    4646bool isLogChannelEnabled(const String& name);
    4747PAL_EXPORT void setLogChannelToAccumulate(const String& name);
    48 #ifndef NDEBUG
    49 void registerNotifyCallback(const String& notifyID, WTF::Function<void()>&& callback);
    50 #endif
    5148
    5249#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
    5350
     51PAL_EXPORT void registerNotifyCallback(const String&, WTF::Function<void()>&&);
     52
    5453} // namespace PAL
    5554
  • trunk/Source/WebCore/history/PageCache.cpp

    r230211 r232098  
    4949#include "Settings.h"
    5050#include "SubframeLoader.h"
     51#include <pal/Logging.h>
    5152#include <wtf/MemoryPressureHandler.h>
    5253#include <wtf/NeverDestroyed.h>
     
    278279    return globalPageCache;
    279280}
    280    
     281
     282PageCache::PageCache()
     283{
     284    static std::once_flag onceFlag;
     285    std::call_once(onceFlag, [] {
     286        PAL::registerNotifyCallback("com.apple.WebKit.showPageCache", [] {
     287            PageCache::singleton().dump();
     288        });
     289    });
     290}
     291
     292void PageCache::dump() const
     293{
     294    WTFLogAlways("\nPage Cache:");
     295    for (auto& item : m_items) {
     296        CachedPage& cachedPage = *item->m_cachedPage;
     297        WTFLogAlways("  Page %p, document %p %s", &cachedPage.page(), cachedPage.document(), cachedPage.document() ? cachedPage.document()->url().string().utf8().data() : "");
     298    }
     299}
     300
    281301bool PageCache::canCache(Page& page) const
    282302{
  • trunk/Source/WebCore/history/PageCache.h

    r219501 r232098  
    6969
    7070private:
    71     PageCache() = default; // Use singleton() instead.
     71    PageCache();
    7272    ~PageCache() = delete; // Make sure nobody accidentally calls delete -- WebCore does not delete singletons.
    7373
     
    7575
    7676    void prune(PruningReason);
     77    void dump() const;
    7778
    7879    ListHashSet<RefPtr<HistoryItem>> m_items;
  • trunk/Source/WebCore/loader/cache/CachedResource.h

    r229585 r232098  
    145145    void destroyDecodedDataIfNeeded();
    146146
    147     unsigned count() const { return m_clients.size(); }
     147    unsigned numberOfClients() const { return m_clients.size(); }
    148148
    149149    Status status() const { return static_cast<Status>(m_status); }
  • trunk/Source/WebCore/loader/cache/MemoryCache.cpp

    r229209 r232098  
    4040#include "WorkerLoaderProxy.h"
    4141#include "WorkerThread.h"
     42#include <pal/Logging.h>
    4243#include <stdio.h>
    4344#include <wtf/MathExtras.h>
     
    6061
    6162MemoryCache::MemoryCache()
    62     : m_disabled(false)
    63     , m_inPruneResources(false)
    64     , m_capacity(cDefaultCacheCapacity)
    65     , m_minDeadCapacity(0)
     63    : m_capacity(cDefaultCacheCapacity)
    6664    , m_maxDeadCapacity(cDefaultCacheCapacity)
    67     , m_liveSize(0)
    68     , m_deadSize(0)
    6965    , m_pruneTimer(*this, &MemoryCache::prune)
    7066{
    7167    static_assert(sizeof(long long) > sizeof(unsigned), "Numerical overflow can happen when adjusting the size of the cached memory.");
     68
     69    static std::once_flag onceFlag;
     70    std::call_once(onceFlag, [] {
     71        PAL::registerNotifyCallback("com.apple.WebKit.showMemoryCache", [] {
     72            MemoryCache::singleton().dumpStats();
     73            MemoryCache::singleton().dumpLRULists(true);
     74        });
     75    });
    7276}
    7377
     
    330334            // Destroy our decoded data. This will remove us from m_liveDecodedResources, and possibly move us
    331335            // to a different LRU list in m_allResources.
     336            WTFLogAlways("pruneLiveResourcesToSize: trying to prune %p", current);
    332337            current->destroyDecodedData();
    333338
     
    734739}
    735740
    736 #ifndef NDEBUG
    737741void MemoryCache::dumpStats()
    738742{
    739743    Statistics s = getStatistics();
    740     printf("%-13s %-13s %-13s %-13s %-13s\n", "", "Count", "Size", "LiveSize", "DecodedSize");
    741     printf("%-13s %-13s %-13s %-13s %-13s\n", "-------------", "-------------", "-------------", "-------------", "-------------");
    742     printf("%-13s %13d %13d %13d %13d\n", "Images", s.images.count, s.images.size, s.images.liveSize, s.images.decodedSize);
    743     printf("%-13s %13d %13d %13d %13d\n", "CSS", s.cssStyleSheets.count, s.cssStyleSheets.size, s.cssStyleSheets.liveSize, s.cssStyleSheets.decodedSize);
     744    WTFLogAlways("\nMemory Cache");
     745    WTFLogAlways("%-13s %-13s %-13s %-13s %-13s\n", "", "Count", "Size", "LiveSize", "DecodedSize");
     746    WTFLogAlways("%-13s %-13s %-13s %-13s %-13s\n", "-------------", "-------------", "-------------", "-------------", "-------------");
     747    WTFLogAlways("%-13s %13d %13d %13d %13d\n", "Images", s.images.count, s.images.size, s.images.liveSize, s.images.decodedSize);
     748    WTFLogAlways("%-13s %13d %13d %13d %13d\n", "CSS", s.cssStyleSheets.count, s.cssStyleSheets.size, s.cssStyleSheets.liveSize, s.cssStyleSheets.decodedSize);
    744749#if ENABLE(XSLT)
    745     printf("%-13s %13d %13d %13d %13d\n", "XSL", s.xslStyleSheets.count, s.xslStyleSheets.size, s.xslStyleSheets.liveSize, s.xslStyleSheets.decodedSize);
     750    WTFLogAlways("%-13s %13d %13d %13d %13d\n", "XSL", s.xslStyleSheets.count, s.xslStyleSheets.size, s.xslStyleSheets.liveSize, s.xslStyleSheets.decodedSize);
    746751#endif
    747     printf("%-13s %13d %13d %13d %13d\n", "JavaScript", s.scripts.count, s.scripts.size, s.scripts.liveSize, s.scripts.decodedSize);
    748     printf("%-13s %13d %13d %13d %13d\n", "Fonts", s.fonts.count, s.fonts.size, s.fonts.liveSize, s.fonts.decodedSize);
    749     printf("%-13s %-13s %-13s %-13s %-13s\n\n", "-------------", "-------------", "-------------", "-------------", "-------------");
     752    WTFLogAlways("%-13s %13d %13d %13d %13d\n", "JavaScript", s.scripts.count, s.scripts.size, s.scripts.liveSize, s.scripts.decodedSize);
     753    WTFLogAlways("%-13s %13d %13d %13d %13d\n", "Fonts", s.fonts.count, s.fonts.size, s.fonts.liveSize, s.fonts.decodedSize);
     754    WTFLogAlways("%-13s %-13s %-13s %-13s %-13s\n\n", "-------------", "-------------", "-------------", "-------------", "-------------");
     755
     756    unsigned countTotal = s.images.count + s.cssStyleSheets.count + s.scripts.count + s.fonts.count;
     757    unsigned sizeTotal = s.images.size + s.cssStyleSheets.size + s.scripts.size + s.fonts.size;
     758    unsigned liveSizeTotal = s.images.liveSize + s.cssStyleSheets.liveSize + s.scripts.liveSize + s.fonts.liveSize;
     759    unsigned decodedSizeTotal = s.images.decodedSize + s.cssStyleSheets.decodedSize + s.scripts.decodedSize + s.fonts.decodedSize;
     760#if ENABLE(XSLT)
     761    countTotal += s.xslStyleSheets.count;
     762    sizeTotal += s.xslStyleSheets.size;
     763    liveSizeTotal += s.xslStyleSheets.liveSize;
     764    decodedSizeTotal += s.xslStyleSheets.decodedSize;
     765#endif
     766
     767    WTFLogAlways("%-13s %13d %11.2fKB %11.2fKB %11.2fKB\n", "Total", countTotal, sizeTotal / 1024., liveSizeTotal / 1024., decodedSizeTotal / 1024.);
    750768}
    751769
    752770void MemoryCache::dumpLRULists(bool includeLive) const
    753771{
    754     printf("LRU-SP lists in eviction order (Kilobytes decoded, Kilobytes encoded, Access count, Referenced):\n");
     772    WTFLogAlways("LRU-SP lists in eviction order (Kilobytes decoded, Kilobytes encoded, Access count, Referenced):\n");
    755773
    756774    int size = m_allResources.size();
    757775    for (int i = size - 1; i >= 0; i--) {
    758         printf("\n\nList %d: ", i);
     776        WTFLogAlways("\nList %d:\n", i);
    759777        for (auto* resource : *m_allResources[i]) {
    760778            if (includeLive || !resource->hasClients())
    761                 printf("(%.1fK, %.1fK, %uA, %dR); ", resource->decodedSize() / 1024.0f, (resource->encodedSize() + resource->overheadSize()) / 1024.0f, resource->accessCount(), resource->hasClients());
    762         }
    763     }
    764 }
    765 #endif
     779                WTFLogAlways("  %.100s %.1fK, %.1fK, accesses: %u, clients: %d\n", resource->url().string().utf8().data(), resource->decodedSize() / 1024.0f, (resource->encodedSize() + resource->overheadSize()) / 1024.0f, resource->accessCount(), resource->numberOfClients());
     780        }
     781    }
     782}
    766783
    767784} // namespace WebCore
  • trunk/Source/WebCore/loader/cache/MemoryCache.h

    r220887 r232098  
    177177
    178178    LRUList& lruListFor(CachedResource&);
    179 #ifndef NDEBUG
     179
    180180    void dumpStats();
    181181    void dumpLRULists(bool includeLive) const;
    182 #endif
    183182
    184183    unsigned liveCapacity() const;
     
    191190    CachedResourceMap* sessionResourceMap(PAL::SessionID) const;
    192191
    193     bool m_disabled;  // Whether or not the cache is enabled.
    194     bool m_inPruneResources;
     192    bool m_disabled { false };
     193    bool m_inPruneResources { false };
    195194
    196195    unsigned m_capacity;
    197     unsigned m_minDeadCapacity;
     196    unsigned m_minDeadCapacity { 0 };
    198197    unsigned m_maxDeadCapacity;
    199198    Seconds m_deadDecodedDataDeletionInterval;
    200199
    201     unsigned m_liveSize; // The number of bytes currently consumed by "live" resources in the cache.
    202     unsigned m_deadSize; // The number of bytes currently consumed by "dead" resources in the cache.
     200    unsigned m_liveSize { 0 }; // The number of bytes currently consumed by "live" resources in the cache.
     201    unsigned m_deadSize { 0 }; // The number of bytes currently consumed by "dead" resources in the cache.
    203202
    204203    // Size-adjusted and popularity-aware LRU list collection for cache objects.  This collection can hold
  • trunk/Source/WebCore/page/mac/PageMac.mm

    r231141 r232098  
    5353#endif
    5454
    55 #if ENABLE(TREE_DEBUGGING)
    5655    static std::once_flag onceFlag;
    5756    std::call_once(onceFlag, [] {
     57#if ENABLE(TREE_DEBUGGING)
    5858        PAL::registerNotifyCallback("com.apple.WebKit.showRenderTree", printRenderTreeForLiveDocuments);
    5959        PAL::registerNotifyCallback("com.apple.WebKit.showLayerTree", printLayerTreeForLiveDocuments);
     
    6161        PAL::registerNotifyCallback("com.apple.WebKit.showLayoutTree", Layout::printLayoutTreeForLiveDocuments);
    6262#endif
     63#endif // ENABLE(TREE_DEBUGGING)
     64
     65        PAL::registerNotifyCallback("com.apple.WebKit.showAllDocuments", [] {
     66            unsigned numPages = 0;
     67            Page::forEachPage([&numPages](Page&) {
     68                ++numPages;
     69            });
     70
     71            WTFLogAlways("%u live pages:", numPages);
     72
     73            Page::forEachPage([](Page& page) {
     74                const auto* mainFrameDocument = page.mainFrame().document();
     75                WTFLogAlways("Page %p with main document %p %s", &page, mainFrameDocument, mainFrameDocument ? mainFrameDocument->url().string().utf8().data() : "");
     76            });
     77
     78            WTFLogAlways("%u live documents:", Document::allDocuments().size());
     79            for (const auto* document : Document::allDocuments()) {
     80                WTFLogAlways("Document %p %s", document, document->url().string().utf8().data());
     81            }
     82        });
    6383    });
    64 #endif
    6584}
    6685
Note: See TracChangeset for help on using the changeset viewer.