Add a debug overlay with information about web process resource usage.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Nov 2015 02:29:47 +0000 (02:29 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Nov 2015 02:29:47 +0000 (02:29 +0000)
commit04acd810b215a6c59511192991ce77200499e5b1
tree9912b0c1b4a3925fdec56656f125a22cd0b42e9b
parent1af522ecf4bee0d661e427e4a10b37470f5117b2
Add a debug overlay with information about web process resource usage.
<https://webkit.org/b/150599>

Reviewed by Darin Adler.

Source/JavaScriptCore:

Have Heap track the exact number of bytes allocated in CopiedBlock, MarkedBlock and
WeakBlock objects, keeping them in a single location that can be sampled by the
resource usage overlay thread.

The bulk of these changes is threading a Heap& through from sites where blocks are
allocated or freed.

* heap/CopiedBlock.cpp:
(JSC::CopiedBlock::createNoZeroFill):
(JSC::CopiedBlock::destroy):
(JSC::CopiedBlock::create):
* heap/CopiedBlock.h:
* heap/CopiedSpace.cpp:
(JSC::CopiedSpace::~CopiedSpace):
(JSC::CopiedSpace::tryAllocateOversize):
(JSC::CopiedSpace::tryReallocateOversize):
* heap/CopiedSpaceInlines.h:
(JSC::CopiedSpace::recycleEvacuatedBlock):
(JSC::CopiedSpace::recycleBorrowedBlock):
(JSC::CopiedSpace::allocateBlockForCopyingPhase):
(JSC::CopiedSpace::allocateBlock):
(JSC::CopiedSpace::startedCopying):
* heap/Heap.cpp:
(JSC::Heap::~Heap):
(JSC::Heap::sweepNextLogicallyEmptyWeakBlock):
* heap/Heap.h:
(JSC::Heap::blockBytesAllocated):
* heap/HeapInlines.h:
(JSC::Heap::didAllocateBlock):
(JSC::Heap::didFreeBlock):
* heap/MarkedAllocator.cpp:
(JSC::MarkedAllocator::allocateBlock):
* heap/MarkedBlock.cpp:
(JSC::MarkedBlock::create):
(JSC::MarkedBlock::destroy):
* heap/MarkedBlock.h:
* heap/MarkedSpace.cpp:
(JSC::MarkedSpace::freeBlock):
* heap/WeakBlock.cpp:
(JSC::WeakBlock::create):
(JSC::WeakBlock::destroy):
* heap/WeakBlock.h:
* heap/WeakSet.cpp:
(JSC::WeakSet::~WeakSet):
(JSC::WeakSet::addAllocator):
(JSC::WeakSet::removeAllocator):

Source/WebCore:

A new kind of PageOverlay is added behind the ENABLE(RESOURCE_USAGE_OVERLAY) flag.
It's owned by Page, but not instantiated unless the Settings::resourceUsageOverlayVisible flag is set.

All ResourceUsageOverlay objects share a single sampler thread. The thread currently runs every 500ms
and samples CPU usage, dirty memory regions, and GC heap size/capacity.

Most things in here are currently quite Mac-specific, but I will be iterating on this towards a more
cross-platform friendly solution.

There are two small changes to PageOverlay in order to support dragging the resource usage overlay:

    - A "should ignore mouse events outside bounds" state flag. This is on by default
      but turned off during a drag.
    - PageOverlay::bounds() will now return the override frame verbatim if one is set,
      instead of returning it relocated to 0,0.

Note that this is intended as a tool for WebKit engine developers to better understand memory usage.
It's not a goal to expose this information to end users.

* WebCore.xcodeproj/project.pbxproj:
* page/Page.cpp:
(WebCore::Page::setResourceUsageOverlayVisible):
* page/Page.h:
* page/PageOverlay.cpp:
(WebCore::PageOverlay::bounds):
(WebCore::PageOverlay::mouseEvent):
* page/PageOverlay.h:
* page/ResourceUsageOverlay.cpp: Added.
(WebCore::ResourceUsageOverlay::ResourceUsageOverlay):
(WebCore::ResourceUsageOverlay::~ResourceUsageOverlay):
(WebCore::ResourceUsageOverlay::mouseEvent):
* page/ResourceUsageOverlay.h: Added.
* page/Settings.cpp:
(WebCore::Settings::setResourceUsageOverlayVisible):
* page/Settings.h:
(WebCore::Settings::resourceUsageOverlayVisible):
* page/cocoa/ResourceUsageOverlayCocoa.mm: Added.
(-[WebOverlayLayer initWithResourceUsageOverlay:]):
(-[WebOverlayLayer drawInContext:]):
(WebCore::RingBuffer::RingBuffer):
(WebCore::RingBuffer::append):
(WebCore::RingBuffer::last):
(WebCore::RingBuffer::forEach):
(WebCore::RingBuffer::incrementIndex):
(WebCore::RingBuffer::decrementIndex):
(WebCore::sharedData):
(WebCore::ResourceUsageOverlay::platformInitialize):
(WebCore::ResourceUsageOverlay::platformDestroy):
(WebCore::drawCpuHistory):
(WebCore::drawGCHistory):
(WebCore::drawSlice):
(WebCore::drawPlate):
(WebCore::drawMemoryPie):
(WebCore::formatByteNumber):
(WebCore::showText):
(WebCore::ResourceUsageOverlay::draw):
(WebCore::dirtyPagesPerVMTag):
(WebCore::cpuUsage):
(WebCore::runSamplerThread):
* platform/spi/cocoa/MachVMSPI.h:

Source/WebKit2:

Add WK2 preferences SPI for showing/hiding the resource usage overlay.

* Shared/WebPreferencesDefinitions.h:
* UIProcess/API/C/WKPreferences.cpp:
(WKPreferencesSetResourceUsageOverlayVisible):
(WKPreferencesGetResourceUsageOverlayVisible):
* UIProcess/API/C/WKPreferencesRefPrivate.h:
* UIProcess/API/Cocoa/WKPreferences.mm:
(-[WKPreferences _resourceUsageOverlayVisible]):
(-[WKPreferences _setResourceUsageOverlayVisible:]):
* UIProcess/API/Cocoa/WKPreferencesPrivate.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences):

Source/WTF:

Add ENABLE(RESOURCE_USAGE_OVERLAY) flag, enabled on Mac by default.

* wtf/Platform.h:

Tools:

Add a menu item to the MiniBrowser so we can toggle the resource usage overlay on/off.

* MiniBrowser/mac/SettingsController.h:
* MiniBrowser/mac/SettingsController.m:
(-[SettingsController _populateMenu]):
(-[SettingsController validateMenuItem:]):
(-[SettingsController toggleShowResourceUsageOverlay:]):
(-[SettingsController resourceUsageOverlayVisible]):
* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController didChangeSettings]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@191849 268f45cc-cd09-0410-ab3c-d52691b4dbfc
42 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/heap/CopiedBlock.cpp
Source/JavaScriptCore/heap/CopiedBlock.h
Source/JavaScriptCore/heap/CopiedSpace.cpp
Source/JavaScriptCore/heap/CopiedSpaceInlines.h
Source/JavaScriptCore/heap/Heap.cpp
Source/JavaScriptCore/heap/Heap.h
Source/JavaScriptCore/heap/HeapInlines.h
Source/JavaScriptCore/heap/MarkedAllocator.cpp
Source/JavaScriptCore/heap/MarkedBlock.cpp
Source/JavaScriptCore/heap/MarkedBlock.h
Source/JavaScriptCore/heap/MarkedSpace.cpp
Source/JavaScriptCore/heap/WeakBlock.cpp
Source/JavaScriptCore/heap/WeakBlock.h
Source/JavaScriptCore/heap/WeakSet.cpp
Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/PlatformMac.cmake
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h
Source/WebCore/page/PageOverlay.cpp
Source/WebCore/page/PageOverlay.h
Source/WebCore/page/ResourceUsageOverlay.cpp [new file with mode: 0644]
Source/WebCore/page/ResourceUsageOverlay.h [new file with mode: 0644]
Source/WebCore/page/Settings.cpp
Source/WebCore/page/Settings.h
Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm [new file with mode: 0644]
Source/WebCore/platform/spi/cocoa/MachVMSPI.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebPreferencesDefinitions.h
Source/WebKit2/UIProcess/API/C/WKPreferences.cpp
Source/WebKit2/UIProcess/API/C/WKPreferencesRefPrivate.h
Source/WebKit2/UIProcess/API/Cocoa/WKPreferences.mm
Source/WebKit2/UIProcess/API/Cocoa/WKPreferencesPrivate.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Tools/ChangeLog
Tools/MiniBrowser/mac/SettingsController.h
Tools/MiniBrowser/mac/SettingsController.m
Tools/MiniBrowser/mac/WK2BrowserWindowController.m