Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (195643 => 195644)
--- trunk/Source/_javascript_Core/ChangeLog 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-01-27 01:29:25 UTC (rev 195644)
@@ -1,3 +1,17 @@
+2016-01-26 Joseph Pecoraro <[email protected]>
+
+ Generalize ResourceUsageData gathering to be used outside of ResourceUsageOverlay
+ https://bugs.webkit.org/show_bug.cgi?id=153509
+ <rdar://problem/24354291>
+
+ Reviewed by Andreas Kling.
+
+ * heap/Heap.h:
+ * heap/HeapInlines.h:
+ (JSC::Heap::didAllocateBlock):
+ (JSC::Heap::didFreeBlock):
+ Rename the ENABLE flag.
+
2016-01-26 Csaba Osztrogonác <[email protected]>
[B3] Fix control reaches end of non-void function GCC warning after r195139
Modified: trunk/Source/_javascript_Core/heap/Heap.h (195643 => 195644)
--- trunk/Source/_javascript_Core/heap/Heap.h 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/_javascript_Core/heap/Heap.h 2016-01-27 01:29:25 UTC (rev 195644)
@@ -246,7 +246,7 @@
void addLogicallyEmptyWeakBlock(WeakBlock*);
-#if ENABLE(RESOURCE_USAGE_OVERLAY)
+#if ENABLE(RESOURCE_USAGE)
size_t blockBytesAllocated() const { return m_blockBytesAllocated; }
#endif
@@ -456,7 +456,7 @@
ParallelHelperClient m_helperClient;
-#if ENABLE(RESOURCE_USAGE_OVERLAY)
+#if ENABLE(RESOURCE_USAGE)
size_t m_blockBytesAllocated { 0 };
#endif
};
Modified: trunk/Source/_javascript_Core/heap/HeapInlines.h (195643 => 195644)
--- trunk/Source/_javascript_Core/heap/HeapInlines.h 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/_javascript_Core/heap/HeapInlines.h 2016-01-27 01:29:25 UTC (rev 195644)
@@ -310,7 +310,7 @@
inline void Heap::didAllocateBlock(size_t capacity)
{
-#if ENABLE(RESOURCE_USAGE_OVERLAY)
+#if ENABLE(RESOURCE_USAGE)
m_blockBytesAllocated += capacity;
#else
UNUSED_PARAM(capacity);
@@ -319,7 +319,7 @@
inline void Heap::didFreeBlock(size_t capacity)
{
-#if ENABLE(RESOURCE_USAGE_OVERLAY)
+#if ENABLE(RESOURCE_USAGE)
m_blockBytesAllocated -= capacity;
#else
UNUSED_PARAM(capacity);
Modified: trunk/Source/WTF/ChangeLog (195643 => 195644)
--- trunk/Source/WTF/ChangeLog 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/WTF/ChangeLog 2016-01-27 01:29:25 UTC (rev 195644)
@@ -1,3 +1,14 @@
+2016-01-26 Joseph Pecoraro <[email protected]>
+
+ Generalize ResourceUsageData gathering to be used outside of ResourceUsageOverlay
+ https://bugs.webkit.org/show_bug.cgi?id=153509
+ <rdar://problem/24354291>
+
+ Reviewed by Andreas Kling.
+
+ * wtf/Platform.h:
+ Rename the ENABLE flag.
+
2016-01-26 Yusuke Suzuki <[email protected]>
Make HashTable iterators STL iterators compatible
Modified: trunk/Source/WTF/wtf/Platform.h (195643 => 195644)
--- trunk/Source/WTF/wtf/Platform.h 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/WTF/wtf/Platform.h 2016-01-27 01:29:25 UTC (rev 195644)
@@ -1091,7 +1091,7 @@
#endif
#if PLATFORM(COCOA)
-#define ENABLE_RESOURCE_USAGE_OVERLAY 1
+#define ENABLE_RESOURCE_USAGE 1
#endif
#if PLATFORM(GTK) || PLATFORM(EFL)
Modified: trunk/Source/WebCore/CMakeLists.txt (195643 => 195644)
--- trunk/Source/WebCore/CMakeLists.txt 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/WebCore/CMakeLists.txt 2016-01-27 01:29:25 UTC (rev 195644)
@@ -2039,7 +2039,9 @@
page/PerformanceUserTiming.cpp
page/PointerLockController.cpp
page/PrintContext.cpp
+ page/ResourceUsageData.cpp
page/ResourceUsageOverlay.cpp
+ page/ResourceUsageThread.cpp
page/Screen.cpp
page/SecurityOrigin.cpp
page/SecurityOriginData.cpp
Modified: trunk/Source/WebCore/ChangeLog (195643 => 195644)
--- trunk/Source/WebCore/ChangeLog 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/WebCore/ChangeLog 2016-01-27 01:29:25 UTC (rev 195644)
@@ -1,3 +1,73 @@
+2016-01-26 Joseph Pecoraro <[email protected]>
+
+ Generalize ResourceUsageData gathering to be used outside of ResourceUsageOverlay
+ https://bugs.webkit.org/show_bug.cgi?id=153509
+ <rdar://problem/24354291>
+
+ Reviewed by Andreas Kling.
+
+ * CMakeLists.txt:
+ * PlatformMac.cmake:
+ * WebCore.xcodeproj/project.pbxproj:
+ * page/Page.cpp:
+ * page/Page.h:
+ * page/Settings.cpp:
+ * page/Settings.h:
+ * page/ResourceUsageOverlay.cpp:
+ * page/ResourceUsageOverlay.h:
+ Add new files to the build and updated ENABLE flag name.
+
+ * page/ResourceUsageData.cpp: Added.
+ (WebCore::ResourceUsageData::ResourceUsageData):
+ * page/ResourceUsageData.h: Added.
+ (WebCore::MemoryCategoryInfo::MemoryCategoryInfo):
+ Platform agnostic resource data that may be used by multiple clients,
+ such as the ResourceUsageOverlay and later the Inspector.
+
+ * page/ResourceUsageThread.h: Added.
+ * page/ResourceUsageThread.cpp: Added.
+ (WebCore::ResourceUsageThread::ResourceUsageThread):
+ (WebCore::ResourceUsageThread::singleton):
+ (WebCore::ResourceUsageThread::addObserver):
+ (WebCore::ResourceUsageThread::removeObserver):
+ (WebCore::ResourceUsageThread::waitUntilObservers):
+ (WebCore::ResourceUsageThread::notifyObservers):
+ (WebCore::ResourceUsageThread::createThreadIfNeeded):
+ (WebCore::ResourceUsageThread::threadCallback):
+ (WebCore::ResourceUsageThread::threadBody):
+ Platform agnostic resource usage thread that can be used to gather data
+ into a ResourceUsageData struct on a background thread and notify observers
+ on the main thread. Platforms need only implement ResourceUsageThread::platformThreadBody
+ to populate the ResourceUsageData struct with data.
+
+ * page/cocoa/ResourceUsageOverlayCocoa.mm:
+ (WebCore::HistoricMemoryCategoryInfo::HistoricMemoryCategoryInfo):
+ (WebCore::HistoricResourceUsageData::HistoricResourceUsageData):
+ (WebCore::historicUsageData):
+ (WebCore::appendDataToHistory):
+ (WebCore::ResourceUsageOverlay::platformInitialize):
+ (WebCore::ResourceUsageOverlay::platformDestroy):
+ (WebCore::drawMemHistory):
+ (WebCore::drawMemoryPie):
+ (WebCore::ResourceUsageOverlay::platformDraw):
+ Move CPU and memory resource usage calculations to ResourceUsageThread.
+ The overlay adds itself as an observer, and builds its RingBuffer list
+ of data from notifications from the ResourceUsageThread. Renamed
+ some of the fields.
+
+ * page/cocoa/ResourceUsageThreadCocoa.mm: Added.
+ (WebCore::vmPageSize):
+ (WebCore::TagInfo::TagInfo):
+ (WebCore::pagesPerVMTag):
+ (WebCore::cpuUsage):
+ (WebCore::categoryForVMTag):
+ (WebCore::ResourceUsageThread::platformThreadBody):
+ Extracted from ResourceUsageOverlayCocoa.
+
+ * page/scrolling/ScrollingThread.cpp:
+ (WebCore::ScrollingThread::dispatch):
+ Drive-by, don't call singleton again, we already have the result.
+
2016-01-26 Simon Fraser <[email protected]>
Use initializers in HTMLCanvasElement
Modified: trunk/Source/WebCore/PlatformMac.cmake (195643 => 195644)
--- trunk/Source/WebCore/PlatformMac.cmake 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/WebCore/PlatformMac.cmake 2016-01-27 01:29:25 UTC (rev 195644)
@@ -271,6 +271,7 @@
page/cocoa/UserAgent.mm
page/cocoa/ResourceUsageOverlayCocoa.mm
+ page/cocoa/ResourceUsageOverlayThread.mm
page/cocoa/SettingsCocoa.mm
page/mac/ChromeMac.mm
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (195643 => 195644)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-01-27 01:29:25 UTC (rev 195644)
@@ -4158,6 +4158,11 @@
A456FA2711AD4A830020B420 /* LabelsNodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = A456FA2511AD4A830020B420 /* LabelsNodeList.h */; };
A501920E132EBF2E008BFE55 /* Autocapitalize.h in Headers */ = {isa = PBXBuildFile; fileRef = A501920C132EBF2E008BFE55 /* Autocapitalize.h */; settings = {ATTRIBUTES = (Private, ); }; };
A502C5DF13049B3500FC7D53 /* WebSafeGCActivityCallbackIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = A502C5DD13049B3500FC7D53 /* WebSafeGCActivityCallbackIOS.h */; };
+ A5071E851C56D0DC009951BE /* ResourceUsageData.h in Headers */ = {isa = PBXBuildFile; fileRef = A5071E821C56D079009951BE /* ResourceUsageData.h */; };
+ A5071E861C56D0DF009951BE /* ResourceUsageThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5071E831C56D079009951BE /* ResourceUsageThread.cpp */; };
+ A5071E871C56D0E1009951BE /* ResourceUsageThread.h in Headers */ = {isa = PBXBuildFile; fileRef = A5071E841C56D079009951BE /* ResourceUsageThread.h */; };
+ A5071E891C56D4FE009951BE /* ResourceUsageThreadCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = A5071E881C56D4FA009951BE /* ResourceUsageThreadCocoa.mm */; };
+ A5071E8B1C56FB31009951BE /* ResourceUsageData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5071E8A1C56FAFA009951BE /* ResourceUsageData.cpp */; };
A513B3D7114B1666001C429B /* KeyEventCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = A5C974CF11485FF10066F2AB /* KeyEventCocoa.h */; };
A513B3D8114B166A001C429B /* KeyEventCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = A5C974D011485FF10066F2AB /* KeyEventCocoa.mm */; };
A516E8B7136E04DB0076C3C0 /* LocalizedDateCache.h in Headers */ = {isa = PBXBuildFile; fileRef = A516E8B4136E04DB0076C3C0 /* LocalizedDateCache.h */; };
@@ -11765,6 +11770,11 @@
A456FA2511AD4A830020B420 /* LabelsNodeList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LabelsNodeList.h; sourceTree = "<group>"; };
A501920C132EBF2E008BFE55 /* Autocapitalize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Autocapitalize.h; sourceTree = "<group>"; };
A502C5DD13049B3500FC7D53 /* WebSafeGCActivityCallbackIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSafeGCActivityCallbackIOS.h; sourceTree = "<group>"; };
+ A5071E821C56D079009951BE /* ResourceUsageData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceUsageData.h; sourceTree = "<group>"; };
+ A5071E831C56D079009951BE /* ResourceUsageThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceUsageThread.cpp; sourceTree = "<group>"; };
+ A5071E841C56D079009951BE /* ResourceUsageThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceUsageThread.h; sourceTree = "<group>"; };
+ A5071E881C56D4FA009951BE /* ResourceUsageThreadCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ResourceUsageThreadCocoa.mm; sourceTree = "<group>"; };
+ A5071E8A1C56FAFA009951BE /* ResourceUsageData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceUsageData.cpp; sourceTree = "<group>"; };
A516E8B4136E04DB0076C3C0 /* LocalizedDateCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalizedDateCache.h; sourceTree = "<group>"; };
A516E8B5136E04DB0076C3C0 /* LocalizedDateCache.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalizedDateCache.mm; sourceTree = "<group>"; };
A518225417E2A0D400A9BA1D /* InspectorOverlayPage.css */ = {isa = PBXFileReference; lastKnownFileType = text.css; path = InspectorOverlayPage.css; sourceTree = "<group>"; };
@@ -17300,6 +17310,7 @@
isa = PBXGroup;
children = (
ADFE2B541BD5F41200DAB457 /* ResourceUsageOverlayCocoa.mm */,
+ A5071E881C56D4FA009951BE /* ResourceUsageThreadCocoa.mm */,
A182D5B61BE722620087A7CC /* SettingsCocoa.mm */,
26255F0118878E110006E1FD /* UserAgent.h */,
5D5975B61963637B00D00878 /* UserAgent.mm */,
@@ -17876,8 +17887,12 @@
3772B09516535856000A49CA /* PopupOpeningObserver.h */,
B776D43C1104527500BEB0EC /* PrintContext.cpp */,
B776D43A1104525D00BEB0EC /* PrintContext.h */,
+ A5071E8A1C56FAFA009951BE /* ResourceUsageData.cpp */,
+ A5071E821C56D079009951BE /* ResourceUsageData.h */,
ADBAD6EC1BCDD95000381325 /* ResourceUsageOverlay.cpp */,
ADBAD6ED1BCDD95000381325 /* ResourceUsageOverlay.h */,
+ A5071E831C56D079009951BE /* ResourceUsageThread.cpp */,
+ A5071E841C56D079009951BE /* ResourceUsageThread.h */,
BCEC01BA0C274DAC009F4EC9 /* Screen.cpp */,
BCEC01BB0C274DAC009F4EC9 /* Screen.h */,
BCEC01BC0C274DAC009F4EC9 /* Screen.idl */,
@@ -25947,6 +25962,7 @@
1AB5EBD2194A50F30059AC70 /* HTTPHeaderNames.h in Headers */,
514C76730CE923A1007EF3CD /* HTTPParsers.h in Headers */,
375CD232119D43C800A2A859 /* Hyphenation.h in Headers */,
+ A5071E871C56D0E1009951BE /* ResourceUsageThread.h in Headers */,
862F12A018C1DD02005C54AF /* HysteresisActivity.h in Headers */,
B275356E0B053814002CE64F /* Icon.h in Headers */,
97E4029013A696ED00913D67 /* IconController.h in Headers */,
@@ -26618,6 +26634,7 @@
B2FA3E050AB75A6F000E5AC4 /* JSSVGTextElement.h in Headers */,
B22362290C3AF04A0008CA9B /* JSSVGTextPathElement.h in Headers */,
B2FA3E070AB75A6F000E5AC4 /* JSSVGTextPositioningElement.h in Headers */,
+ A5071E851C56D0DC009951BE /* ResourceUsageData.h in Headers */,
B2FA3E090AB75A6F000E5AC4 /* JSSVGTitleElement.h in Headers */,
B2FA3E0B0AB75A6F000E5AC4 /* JSSVGTransform.h in Headers */,
B2FA3E0D0AB75A6F000E5AC4 /* JSSVGTransformList.h in Headers */,
@@ -28717,6 +28734,7 @@
7C1E97271A9F9834007BF0FB /* AutoFillButtonElement.cpp in Sources */,
45830D4D1679B4F800ACF8C3 /* AutoscrollController.cpp in Sources */,
A8CFF0500A154F09000A4234 /* AutoTableLayout.cpp in Sources */,
+ A5071E891C56D4FE009951BE /* ResourceUsageThreadCocoa.mm in Sources */,
070363E1181A1CDC00C074A5 /* AVAudioCaptureSource.mm in Sources */,
070363E3181A1CDC00C074A5 /* AVCaptureDeviceManager.mm in Sources */,
070363E5181A1CDC00C074A5 /* AVMediaCaptureSource.mm in Sources */,
@@ -29041,6 +29059,7 @@
59A8F1D411A69508001AC34A /* DeviceOrientationController.cpp in Sources */,
59D1C10411EB5DCF00B638C8 /* DeviceOrientationData.cpp in Sources */,
59A85EA2119D68D900DEF1EF /* DeviceOrientationEvent.cpp in Sources */,
+ A5071E861C56D0DF009951BE /* ResourceUsageThread.cpp in Sources */,
267725FC1A5B3AD9003C24DD /* DFA.cpp in Sources */,
5C9A7A751AA0F6EA00958ACF /* DFABytecodeCompiler.cpp in Sources */,
5C9A7A761AA0F6ED00958ACF /* DFABytecodeInterpreter.cpp in Sources */,
@@ -31629,6 +31648,7 @@
49C7B9E51042D32F0009D447 /* WebGLTexture.cpp in Sources */,
6F995A231A7078B100A735F4 /* WebGLTransformFeedback.cpp in Sources */,
0C3F1F5A10C8871200D72CE1 /* WebGLUniformLocation.cpp in Sources */,
+ A5071E8B1C56FB31009951BE /* ResourceUsageData.cpp in Sources */,
6F995A251A7078B100A735F4 /* WebGLVertexArrayObject.cpp in Sources */,
6F222B761AB52D8A0094651A /* WebGLVertexArrayObjectBase.cpp in Sources */,
77A17A7712F28642004E02F6 /* WebGLVertexArrayObjectOES.cpp in Sources */,
Modified: trunk/Source/WebCore/page/Page.cpp (195643 => 195644)
--- trunk/Source/WebCore/page/Page.cpp 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/WebCore/page/Page.cpp 2016-01-27 01:29:25 UTC (rev 195644)
@@ -1848,7 +1848,7 @@
}
#endif
-#if ENABLE(RESOURCE_USAGE_OVERLAY)
+#if ENABLE(RESOURCE_USAGE)
void Page::setResourceUsageOverlayVisible(bool visible)
{
if (!visible) {
Modified: trunk/Source/WebCore/page/Page.h (195643 => 195644)
--- trunk/Source/WebCore/page/Page.h 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/WebCore/page/Page.h 2016-01-27 01:29:25 UTC (rev 195644)
@@ -341,7 +341,7 @@
void dnsPrefetchingStateChanged();
void storageBlockingStateChanged();
-#if ENABLE(RESOURCE_USAGE_OVERLAY)
+#if ENABLE(RESOURCE_USAGE)
void setResourceUsageOverlayVisible(bool);
#endif
@@ -656,7 +656,7 @@
HashSet<ViewStateChangeObserver*> m_viewStateChangeObservers;
-#if ENABLE(RESOURCE_USAGE_OVERLAY)
+#if ENABLE(RESOURCE_USAGE)
std::unique_ptr<ResourceUsageOverlay> m_resourceUsageOverlay;
#endif
Added: trunk/Source/WebCore/page/ResourceUsageData.cpp (0 => 195644)
--- trunk/Source/WebCore/page/ResourceUsageData.cpp (rev 0)
+++ trunk/Source/WebCore/page/ResourceUsageData.cpp 2016-01-27 01:29:25 UTC (rev 195644)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ResourceUsageData.h"
+
+#if ENABLE(RESOURCE_USAGE)
+
+namespace WebCore {
+
+ResourceUsageData::ResourceUsageData()
+{
+ // VM tag categories.
+ categories[MemoryCategory::JSJIT] = MemoryCategoryInfo(MemoryCategory::JSJIT);
+ categories[MemoryCategory::Images] = MemoryCategoryInfo(MemoryCategory::Images);
+ categories[MemoryCategory::Layers] = MemoryCategoryInfo(MemoryCategory::Layers);
+ categories[MemoryCategory::LibcMalloc] = MemoryCategoryInfo(MemoryCategory::LibcMalloc);
+ categories[MemoryCategory::bmalloc] = MemoryCategoryInfo(MemoryCategory::bmalloc);
+ categories[MemoryCategory::Other] = MemoryCategoryInfo(MemoryCategory::Other);
+
+ // Sub categories (e.g breakdown of bmalloc tag.)
+ categories[MemoryCategory::GCHeap] = MemoryCategoryInfo(MemoryCategory::GCHeap, true);
+ categories[MemoryCategory::GCOwned] = MemoryCategoryInfo(MemoryCategory::GCOwned, true);
+}
+
+ResourceUsageData::ResourceUsageData(const ResourceUsageData& other)
+ : cpu(other.cpu)
+ , totalDirtySize(other.totalDirtySize)
+ , timeOfNextEdenCollection(other.timeOfNextEdenCollection)
+ , timeOfNextFullCollection(other.timeOfNextFullCollection)
+{
+ std::copy(other.categories.begin(), other.categories.end(), categories.begin());
+}
+
+}
+
+#endif // ENABLE(RESOURCE_USAGE)
Added: trunk/Source/WebCore/page/ResourceUsageData.h (0 => 195644)
--- trunk/Source/WebCore/page/ResourceUsageData.h (rev 0)
+++ trunk/Source/WebCore/page/ResourceUsageData.h 2016-01-27 01:29:25 UTC (rev 195644)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ResourceUsageData_h
+#define ResourceUsageData_h
+
+#if ENABLE(RESOURCE_USAGE)
+
+#include <array>
+
+namespace WebCore {
+
+namespace MemoryCategory {
+static const unsigned bmalloc = 0;
+static const unsigned LibcMalloc = 1;
+static const unsigned JSJIT = 2;
+static const unsigned Images = 3;
+static const unsigned GCHeap = 4;
+static const unsigned GCOwned = 5;
+static const unsigned Other = 6;
+static const unsigned Layers = 7;
+static const unsigned NumberOfCategories = 8;
+}
+
+struct MemoryCategoryInfo {
+ MemoryCategoryInfo() { } // Needed for std::array.
+ MemoryCategoryInfo(unsigned category, bool subcategory = false)
+ : isSubcategory(subcategory)
+ , type(category)
+ {
+ }
+
+ size_t dirtySize { 0 };
+ size_t reclaimableSize { 0 };
+ bool isSubcategory { false };
+ unsigned type { MemoryCategory::NumberOfCategories };
+};
+
+struct ResourceUsageData {
+ ResourceUsageData();
+ ResourceUsageData(const ResourceUsageData& data);
+
+ float cpu { 0 };
+ size_t totalDirtySize { 0 };
+ std::array<MemoryCategoryInfo, MemoryCategory::NumberOfCategories> categories;
+ double timeOfNextEdenCollection { 0 };
+ double timeOfNextFullCollection { 0 };
+};
+
+} // namespace WebCore
+
+#endif // ResourceUsageData_h
+
+#endif // ENABLE(RESOURCE_USAGE)
Modified: trunk/Source/WebCore/page/ResourceUsageOverlay.cpp (195643 => 195644)
--- trunk/Source/WebCore/page/ResourceUsageOverlay.cpp 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/WebCore/page/ResourceUsageOverlay.cpp 2016-01-27 01:29:25 UTC (rev 195644)
@@ -25,7 +25,7 @@
#include "config.h"
-#if ENABLE(RESOURCE_USAGE_OVERLAY)
+#if ENABLE(RESOURCE_USAGE)
#include "ResourceUsageOverlay.h"
Modified: trunk/Source/WebCore/page/ResourceUsageOverlay.h (195643 => 195644)
--- trunk/Source/WebCore/page/ResourceUsageOverlay.h 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/WebCore/page/ResourceUsageOverlay.h 2016-01-27 01:29:25 UTC (rev 195644)
@@ -26,7 +26,7 @@
#ifndef ResourceUsageOverlay_h
#define ResourceUsageOverlay_h
-#if ENABLE(RESOURCE_USAGE_OVERLAY)
+#if ENABLE(RESOURCE_USAGE)
#include "FloatRect.h"
#include "IntRect.h"
Added: trunk/Source/WebCore/page/ResourceUsageThread.cpp (0 => 195644)
--- trunk/Source/WebCore/page/ResourceUsageThread.cpp (rev 0)
+++ trunk/Source/WebCore/page/ResourceUsageThread.cpp 2016-01-27 01:29:25 UTC (rev 195644)
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ResourceUsageThread.h"
+
+#if ENABLE(RESOURCE_USAGE)
+
+#include "JSDOMWindow.h"
+#include <thread>
+#include <wtf/MainThread.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+ResourceUsageThread::ResourceUsageThread()
+{
+}
+
+ResourceUsageThread& ResourceUsageThread::singleton()
+{
+ static NeverDestroyed<ResourceUsageThread> resourceUsageThread;
+ return resourceUsageThread;
+}
+
+void ResourceUsageThread::addObserver(void* key, std::function<void (const ResourceUsageData&)> function)
+{
+ auto& resourceUsageThread = ResourceUsageThread::singleton();
+ resourceUsageThread.createThreadIfNeeded();
+
+ {
+ LockHolder locker(resourceUsageThread.m_lock);
+ bool wasEmpty = resourceUsageThread.m_observers.isEmpty();
+ resourceUsageThread.m_observers.set(key, function);
+
+ if (wasEmpty)
+ resourceUsageThread.m_condition.notifyAll();
+ }
+}
+
+void ResourceUsageThread::removeObserver(void* key)
+{
+ auto& resourceUsageThread = ResourceUsageThread::singleton();
+
+ {
+ LockHolder locker(resourceUsageThread.m_lock);
+ resourceUsageThread.m_observers.remove(key);
+ }
+}
+
+void ResourceUsageThread::waitUntilObservers()
+{
+ LockHolder locker(m_lock);
+ while (m_observers.isEmpty())
+ m_condition.wait(m_lock);
+}
+
+void ResourceUsageThread::notifyObservers(ResourceUsageData& data)
+{
+ callOnMainThread([data]() mutable {
+ Vector<std::function<void (const ResourceUsageData&)>> functions;
+
+ {
+ auto& resourceUsageThread = ResourceUsageThread::singleton();
+ LockHolder locker(resourceUsageThread.m_lock);
+ copyValuesToVector(resourceUsageThread.m_observers, functions);
+ }
+
+ for (auto& function : functions)
+ function(data);
+ });
+}
+
+void ResourceUsageThread::createThreadIfNeeded()
+{
+ if (m_threadIdentifier)
+ return;
+
+ m_vm = &JSDOMWindow::commonVM();
+ m_threadIdentifier = createThread(threadCallback, this, "WebCore: ResourceUsage");
+}
+
+void ResourceUsageThread::threadCallback(void* resourceUsageThread)
+{
+ static_cast<ResourceUsageThread*>(resourceUsageThread)->threadBody();
+}
+
+NO_RETURN void ResourceUsageThread::threadBody()
+{
+ while (true) {
+ // Only do work if we have observers.
+ waitUntilObservers();
+
+ auto start = std::chrono::system_clock::now();
+
+ ResourceUsageData data;
+ platformThreadBody(m_vm, data);
+ notifyObservers(data);
+
+ auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - start);
+ auto difference = std::chrono::milliseconds(500) - duration;
+ std::this_thread::sleep_for(difference);
+ }
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(RESOURCE_USAGE)
Added: trunk/Source/WebCore/page/ResourceUsageThread.h (0 => 195644)
--- trunk/Source/WebCore/page/ResourceUsageThread.h (rev 0)
+++ trunk/Source/WebCore/page/ResourceUsageThread.h 2016-01-27 01:29:25 UTC (rev 195644)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ResourceUsageThread_h
+#define ResourceUsageThread_h
+
+#if ENABLE(RESOURCE_USAGE)
+
+#include "ResourceUsageData.h"
+#include <functional>
+#include <wtf/Condition.h>
+#include <wtf/HashMap.h>
+#include <wtf/Lock.h>
+#include <wtf/NeverDestroyed.h>
+#include <wtf/Noncopyable.h>
+
+namespace JSC {
+class VM;
+}
+
+namespace WebCore {
+
+class ResourceUsageThread {
+ WTF_MAKE_NONCOPYABLE(ResourceUsageThread);
+
+public:
+ static void addObserver(void* key, std::function<void (const ResourceUsageData&)>);
+ static void removeObserver(void* key);
+
+private:
+ friend NeverDestroyed<ResourceUsageThread>;
+ ResourceUsageThread();
+ static ResourceUsageThread& singleton();
+
+ void waitUntilObservers();
+ void notifyObservers(ResourceUsageData&);
+
+ void createThreadIfNeeded();
+ static void threadCallback(void* scrollingThread);
+ void threadBody();
+ void platformThreadBody(JSC::VM*, ResourceUsageData&);
+
+ ThreadIdentifier m_threadIdentifier { 0 };
+ Lock m_lock;
+ Condition m_condition;
+ HashMap<void*, std::function<void (const ResourceUsageData&)>> m_observers;
+
+ // Platforms may need to access some data from the common VM.
+ // They should ensure their use of the VM is thread safe.
+ JSC::VM* m_vm { nullptr };
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(RESOURCE_USAGE)
+
+#endif // ResourceUsageThread_h
Modified: trunk/Source/WebCore/page/Settings.cpp (195643 => 195644)
--- trunk/Source/WebCore/page/Settings.cpp 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/WebCore/page/Settings.cpp 2016-01-27 01:29:25 UTC (rev 195644)
@@ -540,7 +540,7 @@
m_showTiledScrollingIndicator = enabled;
}
-#if ENABLE(RESOURCE_USAGE_OVERLAY)
+#if ENABLE(RESOURCE_USAGE)
void Settings::setResourceUsageOverlayVisible(bool visible)
{
if (m_resourceUsageOverlayVisible == visible)
Modified: trunk/Source/WebCore/page/Settings.h (195643 => 195644)
--- trunk/Source/WebCore/page/Settings.h 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/WebCore/page/Settings.h 2016-01-27 01:29:25 UTC (rev 195644)
@@ -193,7 +193,7 @@
WEBCORE_EXPORT void setShowTiledScrollingIndicator(bool);
bool showTiledScrollingIndicator() const { return m_showTiledScrollingIndicator; }
-#if ENABLE(RESOURCE_USAGE_OVERLAY)
+#if ENABLE(RESOURCE_USAGE)
bool resourceUsageOverlayVisible() const { return m_resourceUsageOverlayVisible; }
WEBCORE_EXPORT void setResourceUsageOverlayVisible(bool);
#endif
@@ -352,7 +352,7 @@
bool m_forcePendingWebGLPolicy : 1;
-#if ENABLE(RESOURCE_USAGE_OVERLAY)
+#if ENABLE(RESOURCE_USAGE)
bool m_resourceUsageOverlayVisible { false };
#endif
Modified: trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm (195643 => 195644)
--- trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/WebCore/page/cocoa/ResourceUsageOverlayCocoa.mm 2016-01-27 01:29:25 UTC (rev 195644)
@@ -26,21 +26,14 @@
#include "config.h"
#include "ResourceUsageOverlay.h"
-#if ENABLE(RESOURCE_USAGE_OVERLAY)
+#if ENABLE(RESOURCE_USAGE)
#include "JSDOMWindow.h"
-#include "MachVMSPI.h"
#include "PlatformCALayer.h"
+#include "ResourceUsageThread.h"
#include <CoreGraphics/CGContext.h>
-#include <_javascript_Core/GCActivityCallback.h>
#include <QuartzCore/CALayer.h>
#include <QuartzCore/CATransaction.h>
-#include <array>
-#include <mach/mach.h>
-#include <mach/vm_statistics.h>
-#include <runtime/JSLock.h>
-#include <sys/sysctl.h>
-#include <thread>
#include <wtf/MathExtras.h>
#include <wtf/NeverDestroyed.h>
@@ -71,19 +64,6 @@
namespace WebCore {
-static size_t vmPageSize()
-{
- static size_t pageSize;
- static std::once_flag onceFlag;
- std::call_once(onceFlag, [&] {
- size_t outputSize = sizeof(pageSize);
- int status = sysctlbyname("vm.pagesize", &pageSize, &outputSize, nullptr, 0);
- ASSERT_UNUSED(status, status != -1);
- ASSERT(pageSize);
- });
- return pageSize;
-}
-
template<typename T, size_t size = 70>
class RingBuffer {
public:
@@ -133,18 +113,6 @@
unsigned m_current { 0 };
};
-namespace MemoryCategory {
-static const unsigned bmalloc = 0;
-static const unsigned LibcMalloc = 1;
-static const unsigned JSJIT = 2;
-static const unsigned Images = 3;
-static const unsigned GCHeap = 4;
-static const unsigned GCOwned = 5;
-static const unsigned Other = 6;
-static const unsigned Layers = 7;
-static const unsigned NumberOfCategories = 8;
-}
-
static CGColorRef createColor(float r, float g, float b, float a)
{
static CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
@@ -152,10 +120,10 @@
return CGColorCreate(colorSpace, components);
}
-struct MemoryCategoryInfo {
- MemoryCategoryInfo() { } // Needed for std::array.
+struct HistoricMemoryCategoryInfo {
+ HistoricMemoryCategoryInfo() { } // Needed for std::array.
- MemoryCategoryInfo(unsigned category, RGBA32 rgba, String name, bool subcategory = false)
+ HistoricMemoryCategoryInfo(unsigned category, RGBA32 rgba, String name, bool subcategory = false)
: name(WTFMove(name))
, isSubcategory(subcategory)
, type(category)
@@ -167,65 +135,76 @@
String name;
RetainPtr<CGColorRef> color;
- RingBuffer<size_t> history;
- RingBuffer<size_t> reclaimableHistory;
+ RingBuffer<size_t> dirtySize;
+ RingBuffer<size_t> reclaimableSize;
bool isSubcategory { false };
unsigned type { MemoryCategory::NumberOfCategories };
};
-struct ResourceUsageData {
- ResourceUsageData();
+struct HistoricResourceUsageData {
+ HistoricResourceUsageData();
- Lock lock;
-
- RingBuffer<size_t> totalDirty;
- std::array<MemoryCategoryInfo, MemoryCategory::NumberOfCategories> categories;
-
- RingBuffer<float> cpuHistory;
- RingBuffer<size_t> gcHeapSizeHistory;
-
- HashSet<CALayer *> overlayLayers;
- JSC::VM* vm { nullptr };
-
+ RingBuffer<float> cpu;
+ RingBuffer<size_t> totalDirtySize;
+ RingBuffer<size_t> gcHeapSize;
+ std::array<HistoricMemoryCategoryInfo, MemoryCategory::NumberOfCategories> categories;
double timeOfNextEdenCollection { 0 };
double timeOfNextFullCollection { 0 };
};
-ResourceUsageData::ResourceUsageData()
+HistoricResourceUsageData::HistoricResourceUsageData()
{
// VM tag categories.
- categories[MemoryCategory::JSJIT] = MemoryCategoryInfo(MemoryCategory::JSJIT, 0xFFFF60FF, "JS JIT");
- categories[MemoryCategory::Images] = MemoryCategoryInfo(MemoryCategory::Images, 0xFFFFFF00, "Images");
- categories[MemoryCategory::Layers] = MemoryCategoryInfo(MemoryCategory::Layers, 0xFF00FFFF, "Layers");
- categories[MemoryCategory::LibcMalloc] = MemoryCategoryInfo(MemoryCategory::LibcMalloc, 0xFF00FF00, "libc malloc");
- categories[MemoryCategory::bmalloc] = MemoryCategoryInfo(MemoryCategory::bmalloc, 0xFFFF6060, "bmalloc");
- categories[MemoryCategory::Other] = MemoryCategoryInfo(MemoryCategory::Other, 0xFFC0FF00, "Other");
+ categories[MemoryCategory::JSJIT] = HistoricMemoryCategoryInfo(MemoryCategory::JSJIT, 0xFFFF60FF, "JS JIT");
+ categories[MemoryCategory::Images] = HistoricMemoryCategoryInfo(MemoryCategory::Images, 0xFFFFFF00, "Images");
+ categories[MemoryCategory::Layers] = HistoricMemoryCategoryInfo(MemoryCategory::Layers, 0xFF00FFFF, "Layers");
+ categories[MemoryCategory::LibcMalloc] = HistoricMemoryCategoryInfo(MemoryCategory::LibcMalloc, 0xFF00FF00, "libc malloc");
+ categories[MemoryCategory::bmalloc] = HistoricMemoryCategoryInfo(MemoryCategory::bmalloc, 0xFFFF6060, "bmalloc");
+ categories[MemoryCategory::Other] = HistoricMemoryCategoryInfo(MemoryCategory::Other, 0xFFC0FF00, "Other");
// Sub categories (e.g breakdown of bmalloc tag.)
- categories[MemoryCategory::GCHeap] = MemoryCategoryInfo(MemoryCategory::GCHeap, 0xFFA0A0FF, "GC heap", true);
- categories[MemoryCategory::GCOwned] = MemoryCategoryInfo(MemoryCategory::GCOwned, 0xFFFFC060, "GC owned", true);
+ categories[MemoryCategory::GCHeap] = HistoricMemoryCategoryInfo(MemoryCategory::GCHeap, 0xFFA0A0FF, "GC heap", true);
+ categories[MemoryCategory::GCOwned] = HistoricMemoryCategoryInfo(MemoryCategory::GCOwned, 0xFFFFC060, "GC owned", true);
+
+#ifndef NDEBUG
+ // Ensure this aligns with ResourceUsageData's category order.
+ ResourceUsageData d;
+ ASSERT(categories.size() == d.categories.size());
+ for (size_t i = 0; i < categories.size(); ++i)
+ ASSERT(categories[i].type == d.categories[i].type);
+#endif
}
-static ResourceUsageData& sharedData()
+static HistoricResourceUsageData& historicUsageData()
{
- static NeverDestroyed<ResourceUsageData> data;
+ static NeverDestroyed<HistoricResourceUsageData> data;
return data;
}
-void runSamplerThread(void*);
-
-void ResourceUsageOverlay::platformInitialize()
+static void appendDataToHistory(const ResourceUsageData& data)
{
- auto& data = ""
- LockHolder locker(data.lock);
+ ASSERT(isMainThread());
- // FIXME: The sampler thread will never stop once started.
- static std::once_flag onceFlag;
- std::call_once(onceFlag, [&] {
- data.vm = &JSDOMWindow::commonVM();
- createThread(runSamplerThread, nullptr, "ResourceUsageOverlay Sampler");
- });
+ auto& historicData = historicUsageData();
+ historicData.cpu.append(data.cpu);
+ historicData.totalDirtySize.append(data.totalDirtySize);
+ for (auto& category : historicData.categories) {
+ category.dirtySize.append(data.categories[category.type].dirtySize);
+ category.reclaimableSize.append(data.categories[category.type].reclaimableSize);
+ }
+ historicData.timeOfNextEdenCollection = data.timeOfNextEdenCollection;
+ historicData.timeOfNextFullCollection = data.timeOfNextFullCollection;
+ // FIXME: Find a way to add this to ResourceUsageData and calculate it on the resource usage sampler thread.
+ {
+ JSC::VM* vm = &JSDOMWindow::commonVM();
+ JSC::JSLockHolder lock(vm);
+ historicData.gcHeapSize.append(vm->heap.size() - vm->heap.extraMemorySize());
+ }
+}
+
+void ResourceUsageOverlay::platformInitialize()
+{
m_layer = adoptNS([[WebOverlayLayer alloc] initWithResourceUsageOverlay:this]);
m_containerLayer = adoptNS([[CALayer alloc] init]);
@@ -241,14 +220,24 @@
overlay().layer().setContentsToPlatformLayer(m_layer.get(), GraphicsLayer::NoContentsLayer);
- data.overlayLayers.add(m_layer.get());
+ ResourceUsageThread::addObserver(this, [this] (const ResourceUsageData& data) {
+ appendDataToHistory(data);
+
+ // FIXME: It shouldn't be necessary to update the bounds on every single thread loop iteration,
+ // but something is causing them to become 0x0.
+ [CATransaction begin];
+ CALayer *containerLayer = [m_layer superlayer];
+ CGRect rect = CGRectMake(0, 0, ResourceUsageOverlay::normalWidth, ResourceUsageOverlay::normalHeight);
+ [m_layer setBounds:rect];
+ [containerLayer setBounds:rect];
+ [m_layer setNeedsDisplay];
+ [CATransaction commit];
+ });
}
void ResourceUsageOverlay::platformDestroy()
{
- auto& data = ""
- LockHolder locker(data.lock);
- data.overlayLayers.remove(m_layer.get());
+ ResourceUsageThread::removeObserver(this);
}
static void showText(CGContextRef context, float x, float y, CGColorRef color, const String& text)
@@ -351,12 +340,12 @@
drawGraphLabel(context, x1, y2, "GC");
}
-static void drawMemHistory(CGContextRef context, float x1, float y1, float y2, ResourceUsageData& data)
+static void drawMemHistory(CGContextRef context, float x1, float y1, float y2, HistoricResourceUsageData& data)
{
float yScale = y2 - y1;
size_t peak = 0;
- data.totalDirty.forEach([&](size_t m) {
+ data.totalDirtySize.forEach([&](size_t m) {
if (m > peak)
peak = m;
});
@@ -372,7 +361,7 @@
for (auto& category : data.categories) {
unsigned x = 0;
- category.history.forEach([&](size_t m) {
+ category.dirtySize.forEach([&](size_t m) {
columns[x][category.type] = { category.color.get(), m };
++x;
});
@@ -411,15 +400,15 @@
angle += part * fullCircleInRadians;
}
-static void drawMemoryPie(CGContextRef context, FloatRect& rect, ResourceUsageData& data)
+static void drawMemoryPie(CGContextRef context, FloatRect& rect, HistoricResourceUsageData& data)
{
float radius = rect.width() / 2;
FloatPoint center = rect.center();
- size_t totalDirty = data.totalDirty.last();
+ size_t totalDirty = data.totalDirtySize.last();
float angle = 0;
for (auto& category : data.categories)
- drawSlice(context, center, angle, radius, category.history.last(), totalDirty, category.color.get());
+ drawSlice(context, center, angle, radius, category.dirtySize.last(), totalDirty, category.color.get());
}
static String formatByteNumber(size_t number)
@@ -442,8 +431,7 @@
void ResourceUsageOverlay::platformDraw(CGContextRef context)
{
- auto& data = ""
- LockHolder locker(data.lock);
+ auto& data = ""
if (![m_layer.get() contentsAreFlipped]) {
CGContextScaleCTM(context, 1, -1);
@@ -457,13 +445,13 @@
CGContextClearRect(context, viewBounds);
static CGColorRef colorForLabels = createColor(0.9, 0.9, 0.9, 1);
- showText(context, 10, 20, colorForLabels, String::format(" CPU: %g", data.cpuHistory.last()));
- showText(context, 10, 30, colorForLabels, " Footprint: " + formatByteNumber(data.totalDirty.last()));
+ showText(context, 10, 20, colorForLabels, String::format(" CPU: %g", data.cpu.last()));
+ showText(context, 10, 30, colorForLabels, " Footprint: " + formatByteNumber(data.totalDirtySize.last()));
float y = 50;
for (auto& category : data.categories) {
- String label = String::format("% 11s: %s", category.name.ascii().data(), formatByteNumber(category.history.last()).ascii().data());
- size_t reclaimable = category.reclaimableHistory.last();
+ String label = String::format("% 11s: %s", category.name.ascii().data(), formatByteNumber(category.dirtySize.last()).ascii().data());
+ size_t reclaimable = category.reclaimableSize.last();
if (reclaimable)
label = label + String::format(" [%s]", formatByteNumber(reclaimable).ascii().data());
@@ -476,185 +464,14 @@
showText(context, 10, y + 10, colorForLabels, String::format(" Eden GC: %s", gcTimerString(data.timeOfNextEdenCollection, now).ascii().data()));
showText(context, 10, y + 20, colorForLabels, String::format(" Full GC: %s", gcTimerString(data.timeOfNextFullCollection, now).ascii().data()));
- drawCpuHistory(context, viewBounds.size.width - 70, 0, viewBounds.size.height, data.cpuHistory);
- drawGCHistory(context, viewBounds.size.width - 140, 0, viewBounds.size.height, data.gcHeapSizeHistory, data.categories[MemoryCategory::GCHeap].history);
+ drawCpuHistory(context, viewBounds.size.width - 70, 0, viewBounds.size.height, data.cpu);
+ drawGCHistory(context, viewBounds.size.width - 140, 0, viewBounds.size.height, data.gcHeapSize, data.categories[MemoryCategory::GCHeap].dirtySize);
drawMemHistory(context, viewBounds.size.width - 210, 0, viewBounds.size.height, data);
FloatRect pieRect(viewBounds.size.width - 330, 0, 100, viewBounds.size.height);
drawMemoryPie(context, pieRect, data);
}
-struct TagInfo {
- TagInfo() { }
- size_t dirty { 0 };
- size_t reclaimable { 0 };
-};
-
-static std::array<TagInfo, 256> pagesPerVMTag()
-{
- std::array<TagInfo, 256> tags;
- task_t task = mach_task_self();
- mach_vm_size_t size;
- uint32_t depth = 0;
- struct vm_region_submap_info_64 info = { };
- mach_msg_type_number_t count = VM_REGION_SUBMAP_INFO_COUNT_64;
- for (mach_vm_address_t addr = 0; ; addr += size) {
- int purgeableState;
- if (mach_vm_purgable_control(task, addr, VM_PURGABLE_GET_STATE, &purgeableState) != KERN_SUCCESS)
- purgeableState = VM_PURGABLE_DENY;
-
- kern_return_t kr = mach_vm_region_recurse(task, &addr, &size, &depth, (vm_region_info_t)&info, &count);
- if (kr != KERN_SUCCESS)
- break;
-
- if (purgeableState == VM_PURGABLE_VOLATILE) {
- tags[info.user_tag].reclaimable += info.pages_resident;
- continue;
- }
-
- if (purgeableState == VM_PURGABLE_EMPTY) {
- tags[info.user_tag].reclaimable += size / vmPageSize();
- continue;
- }
-
- bool anonymous = !info.external_pager;
- if (anonymous) {
- tags[info.user_tag].dirty += info.pages_resident - info.pages_reusable;
- tags[info.user_tag].reclaimable += info.pages_reusable;
- } else
- tags[info.user_tag].dirty += info.pages_dirtied;
- }
-
- return tags;
}
-static float cpuUsage()
-{
- thread_array_t threadList;
- mach_msg_type_number_t threadCount;
- kern_return_t kr = task_threads(mach_task_self(), &threadList, &threadCount);
- if (kr != KERN_SUCCESS)
- return -1;
-
- float usage = 0;
-
- for (mach_msg_type_number_t i = 0; i < threadCount; ++i) {
- thread_info_data_t threadInfo;
- thread_basic_info_t threadBasicInfo;
-
- mach_msg_type_number_t threadInfoCount = THREAD_INFO_MAX;
- kr = thread_info(threadList[i], THREAD_BASIC_INFO, static_cast<thread_info_t>(threadInfo), &threadInfoCount);
- if (kr != KERN_SUCCESS)
- return -1;
-
- threadBasicInfo = reinterpret_cast<thread_basic_info_t>(threadInfo);
-
- if (!(threadBasicInfo->flags & TH_FLAGS_IDLE))
- usage += threadBasicInfo->cpu_usage / static_cast<float>(TH_USAGE_SCALE) * 100.0;
- }
-
- kr = vm_deallocate(mach_task_self(), (vm_offset_t)threadList, threadCount * sizeof(thread_t));
- ASSERT(kr == KERN_SUCCESS);
-
- return usage;
-}
-
-static unsigned categoryForVMTag(unsigned tag)
-{
- switch (tag) {
- case VM_MEMORY_IOKIT:
- case VM_MEMORY_LAYERKIT:
- return MemoryCategory::Layers;
- case VM_MEMORY_IMAGEIO:
- case VM_MEMORY_CGIMAGE:
- return MemoryCategory::Images;
- case VM_MEMORY_JAVASCRIPT_JIT_EXECUTABLE_ALLOCATOR:
- return MemoryCategory::JSJIT;
- case VM_MEMORY_MALLOC:
- case VM_MEMORY_MALLOC_HUGE:
- case VM_MEMORY_MALLOC_LARGE:
- case VM_MEMORY_MALLOC_SMALL:
- case VM_MEMORY_MALLOC_TINY:
- case VM_MEMORY_MALLOC_NANO:
- return MemoryCategory::LibcMalloc;
- case VM_MEMORY_TCMALLOC:
- return MemoryCategory::bmalloc;
- default:
- return MemoryCategory::Other;
- }
-};
-
-NO_RETURN void runSamplerThread(void*)
-{
- auto& data = ""
- while (1) {
- float cpu = cpuUsage();
- auto tags = pagesPerVMTag();
- Vector<CALayer *, 8> layers;
-
- {
- LockHolder locker(data.lock);
- data.cpuHistory.append(cpu);
-
- std::array<TagInfo, MemoryCategory::NumberOfCategories> pagesPerCategory;
-
- size_t totalDirtyPages = 0;
- for (unsigned i = 0; i < 256; ++i) {
- pagesPerCategory[categoryForVMTag(i)].dirty += tags[i].dirty;
- pagesPerCategory[categoryForVMTag(i)].reclaimable += tags[i].reclaimable;
- totalDirtyPages += tags[i].dirty;
- }
-
- for (auto& category : data.categories) {
- if (category.isSubcategory) // Only do automatic tallying for top-level categories.
- continue;
- category.history.append(pagesPerCategory[category.type].dirty * vmPageSize());
- category.reclaimableHistory.append(pagesPerCategory[category.type].reclaimable * vmPageSize());
- }
- data.totalDirty.append(totalDirtyPages * vmPageSize());
-
- copyToVector(data.overlayLayers, layers);
-
- size_t currentGCHeapCapacity = data.vm->heap.blockBytesAllocated();
- size_t currentGCOwned = data.vm->heap.extraMemorySize();
-
- data.categories[MemoryCategory::GCHeap].history.append(currentGCHeapCapacity);
- data.categories[MemoryCategory::GCOwned].history.append(currentGCOwned);
-
- // Subtract known subchunks from the bmalloc bucket.
- // FIXME: Handle running with bmalloc disabled.
- data.categories[MemoryCategory::bmalloc].history.last() -= currentGCHeapCapacity + currentGCOwned;
-
- data.timeOfNextEdenCollection = data.vm->heap.edenActivityCallback()->nextFireTime();
- data.timeOfNextFullCollection = data.vm->heap.fullActivityCallback()->nextFireTime();
- }
-
- [CATransaction begin];
- for (CALayer *layer : layers) {
- // FIXME: It shouldn't be necessary to update the bounds on every single thread loop iteration,
- // but something is causing them to become 0x0.
- CALayer *containerLayer = [layer superlayer];
- CGRect rect = CGRectMake(0, 0, ResourceUsageOverlay::normalWidth, ResourceUsageOverlay::normalHeight);
- [layer setBounds:rect];
- [containerLayer setBounds:rect];
- [layer setNeedsDisplay];
- }
- [CATransaction commit];
-
- // FIXME: Find a way to get the size of the current GC heap size safely from the sampler thread.
- callOnMainThread([] {
- auto& data = ""
- JSC::JSLockHolder lock(data.vm);
- size_t gcHeapSize = data.vm->heap.size() - data.vm->heap.extraMemorySize();
-
- LockHolder locker(data.lock);
- data.gcHeapSizeHistory.append(gcHeapSize);
- });
-
- std::this_thread::sleep_for(std::chrono::milliseconds(500));
- }
-}
-
-}
-
-#endif
+#endif // ENABLE(RESOURCE_USAGE)
Added: trunk/Source/WebCore/page/cocoa/ResourceUsageThreadCocoa.mm (0 => 195644)
--- trunk/Source/WebCore/page/cocoa/ResourceUsageThreadCocoa.mm (rev 0)
+++ trunk/Source/WebCore/page/cocoa/ResourceUsageThreadCocoa.mm 2016-01-27 01:29:25 UTC (rev 195644)
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ResourceUsageThread.h"
+
+#if ENABLE(RESOURCE_USAGE)
+
+#include "MachVMSPI.h"
+#include <_javascript_Core/GCActivityCallback.h>
+#include <heap/Heap.h>
+#include <mach/mach.h>
+#include <mach/vm_statistics.h>
+#include <runtime/VM.h>
+#include <sys/sysctl.h>
+
+namespace WebCore {
+
+static size_t vmPageSize()
+{
+ static size_t pageSize;
+ static std::once_flag onceFlag;
+ std::call_once(onceFlag, [&] {
+ size_t outputSize = sizeof(pageSize);
+ int status = sysctlbyname("vm.pagesize", &pageSize, &outputSize, nullptr, 0);
+ ASSERT_UNUSED(status, status != -1);
+ ASSERT(pageSize);
+ });
+ return pageSize;
+}
+
+struct TagInfo {
+ TagInfo() { }
+ size_t dirty { 0 };
+ size_t reclaimable { 0 };
+};
+
+static std::array<TagInfo, 256> pagesPerVMTag()
+{
+ std::array<TagInfo, 256> tags;
+ task_t task = mach_task_self();
+ mach_vm_size_t size;
+ uint32_t depth = 0;
+ struct vm_region_submap_info_64 info = { };
+ mach_msg_type_number_t count = VM_REGION_SUBMAP_INFO_COUNT_64;
+ for (mach_vm_address_t addr = 0; ; addr += size) {
+ int purgeableState;
+ if (mach_vm_purgable_control(task, addr, VM_PURGABLE_GET_STATE, &purgeableState) != KERN_SUCCESS)
+ purgeableState = VM_PURGABLE_DENY;
+
+ kern_return_t kr = mach_vm_region_recurse(task, &addr, &size, &depth, (vm_region_info_t)&info, &count);
+ if (kr != KERN_SUCCESS)
+ break;
+
+ if (purgeableState == VM_PURGABLE_VOLATILE) {
+ tags[info.user_tag].reclaimable += info.pages_resident;
+ continue;
+ }
+
+ if (purgeableState == VM_PURGABLE_EMPTY) {
+ tags[info.user_tag].reclaimable += size / vmPageSize();
+ continue;
+ }
+
+ bool anonymous = !info.external_pager;
+ if (anonymous) {
+ tags[info.user_tag].dirty += info.pages_resident - info.pages_reusable;
+ tags[info.user_tag].reclaimable += info.pages_reusable;
+ } else
+ tags[info.user_tag].dirty += info.pages_dirtied;
+ }
+
+ return tags;
+}
+
+static float cpuUsage()
+{
+ thread_array_t threadList;
+ mach_msg_type_number_t threadCount;
+ kern_return_t kr = task_threads(mach_task_self(), &threadList, &threadCount);
+ if (kr != KERN_SUCCESS)
+ return -1;
+
+ float usage = 0;
+
+ for (mach_msg_type_number_t i = 0; i < threadCount; ++i) {
+ thread_info_data_t threadInfo;
+ thread_basic_info_t threadBasicInfo;
+
+ mach_msg_type_number_t threadInfoCount = THREAD_INFO_MAX;
+ kr = thread_info(threadList[i], THREAD_BASIC_INFO, static_cast<thread_info_t>(threadInfo), &threadInfoCount);
+ if (kr != KERN_SUCCESS)
+ return -1;
+
+ threadBasicInfo = reinterpret_cast<thread_basic_info_t>(threadInfo);
+
+ if (!(threadBasicInfo->flags & TH_FLAGS_IDLE))
+ usage += threadBasicInfo->cpu_usage / static_cast<float>(TH_USAGE_SCALE) * 100.0;
+ }
+
+ kr = vm_deallocate(mach_task_self(), (vm_offset_t)threadList, threadCount * sizeof(thread_t));
+ ASSERT(kr == KERN_SUCCESS);
+
+ return usage;
+}
+
+static unsigned categoryForVMTag(unsigned tag)
+{
+ switch (tag) {
+ case VM_MEMORY_IOKIT:
+ case VM_MEMORY_LAYERKIT:
+ return MemoryCategory::Layers;
+ case VM_MEMORY_IMAGEIO:
+ case VM_MEMORY_CGIMAGE:
+ return MemoryCategory::Images;
+ case VM_MEMORY_JAVASCRIPT_JIT_EXECUTABLE_ALLOCATOR:
+ return MemoryCategory::JSJIT;
+ case VM_MEMORY_MALLOC:
+ case VM_MEMORY_MALLOC_HUGE:
+ case VM_MEMORY_MALLOC_LARGE:
+ case VM_MEMORY_MALLOC_SMALL:
+ case VM_MEMORY_MALLOC_TINY:
+ case VM_MEMORY_MALLOC_NANO:
+ return MemoryCategory::LibcMalloc;
+ case VM_MEMORY_TCMALLOC:
+ return MemoryCategory::bmalloc;
+ default:
+ return MemoryCategory::Other;
+ }
+};
+
+void ResourceUsageThread::platformThreadBody(JSC::VM* vm, ResourceUsageData& data)
+{
+ data.cpu = cpuUsage();
+
+ auto tags = pagesPerVMTag();
+ std::array<TagInfo, MemoryCategory::NumberOfCategories> pagesPerCategory;
+ size_t totalDirtyPages = 0;
+ for (unsigned i = 0; i < 256; ++i) {
+ pagesPerCategory[categoryForVMTag(i)].dirty += tags[i].dirty;
+ pagesPerCategory[categoryForVMTag(i)].reclaimable += tags[i].reclaimable;
+ totalDirtyPages += tags[i].dirty;
+ }
+
+ for (auto& category : data.categories) {
+ if (category.isSubcategory) // Only do automatic tallying for top-level categories.
+ continue;
+ category.dirtySize = pagesPerCategory[category.type].dirty * vmPageSize();
+ category.reclaimableSize = pagesPerCategory[category.type].reclaimable * vmPageSize();
+ }
+ data.totalDirtySize = totalDirtyPages * vmPageSize();
+
+ size_t currentGCHeapCapacity = vm->heap.blockBytesAllocated();
+ size_t currentGCOwned = vm->heap.extraMemorySize();
+
+ data.categories[MemoryCategory::GCHeap].dirtySize = currentGCHeapCapacity;
+ data.categories[MemoryCategory::GCOwned].dirtySize = currentGCOwned;
+
+ // Subtract known subchunks from the bmalloc bucket.
+ // FIXME: Handle running with bmalloc disabled.
+ data.categories[MemoryCategory::bmalloc].dirtySize -= currentGCHeapCapacity + currentGCOwned;
+
+ data.timeOfNextEdenCollection = vm->heap.edenActivityCallback()->nextFireTime();
+ data.timeOfNextFullCollection = vm->heap.fullActivityCallback()->nextFireTime();
+}
+
+}
+
+#endif
Modified: trunk/Source/WebCore/page/scrolling/ScrollingThread.cpp (195643 => 195644)
--- trunk/Source/WebCore/page/scrolling/ScrollingThread.cpp 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/WebCore/page/scrolling/ScrollingThread.cpp 2016-01-27 01:29:25 UTC (rev 195644)
@@ -51,7 +51,7 @@
scrollingThread.createThreadIfNeeded();
{
- std::lock_guard<Lock> lock(singleton().m_functionsMutex);
+ std::lock_guard<Lock> lock(scrollingThread.m_functionsMutex);
scrollingThread.m_functions.append(function);
}
Modified: trunk/Source/WebKit2/ChangeLog (195643 => 195644)
--- trunk/Source/WebKit2/ChangeLog 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/WebKit2/ChangeLog 2016-01-27 01:29:25 UTC (rev 195644)
@@ -1,3 +1,15 @@
+2016-01-26 Joseph Pecoraro <[email protected]>
+
+ Generalize ResourceUsageData gathering to be used outside of ResourceUsageOverlay
+ https://bugs.webkit.org/show_bug.cgi?id=153509
+ <rdar://problem/24354291>
+
+ Reviewed by Andreas Kling.
+
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::updatePreferences):
+ Rename the ENABLE flag.
+
2016-01-26 Commit Queue <[email protected]>
Unreviewed, rolling out r195602.
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (195643 => 195644)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp 2016-01-27 01:22:44 UTC (rev 195643)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp 2016-01-27 01:29:25 UTC (rev 195644)
@@ -2849,7 +2849,7 @@
settings.setAllowsAirPlayForMediaPlayback(store.getBoolValueForKey(WebPreferencesKey::allowsAirPlayForMediaPlaybackKey()));
#endif
-#if ENABLE(RESOURCE_USAGE_OVERLAY)
+#if ENABLE(RESOURCE_USAGE)
settings.setResourceUsageOverlayVisible(store.getBoolValueForKey(WebPreferencesKey::resourceUsageOverlayVisibleKey()));
#endif