Title: [116058] trunk/Source
Revision
116058
Author
o...@chromium.org
Date
2012-05-03 18:35:36 -0700 (Thu, 03 May 2012)

Log Message

Histogram total allocated bytes in the arena in addition to the render tree size
https://bugs.webkit.org/show_bug.cgi?id=85537

Reviewed by Eric Seidel.

Source/WebCore:

We only free bytes allocated to a RenderArena when destroying the Document.
Histogram both the render tree size and the total bytes allocated. This
gives a better sense of the overhead of RenderArena as well as giving a more
accurate number for the amount of actual memory used by the render tree.

No new tests. This is not webfacing, so this can't be tested without adding
API to layout test controller, which doesn't seem worth it for this code.

* page/Page.cpp:
(WebCore::Page::renderTreeSize):
(WebCore::Page::setVisibilityState):
* page/Page.h:
(Page):
* platform/Arena.cpp:
(WebCore::ArenaAllocate):
* platform/Arena.h:
(WebCore):
* rendering/RenderArena.cpp:
(WebCore::RenderArena::allocate):
* rendering/RenderArena.h:
(WebCore::RenderArena::totalRenderArenaAllocatedBytes):
(RenderArena):

Source/WebKit2:

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::renderTreeSize):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (116057 => 116058)


--- trunk/Source/WebCore/ChangeLog	2012-05-04 01:28:11 UTC (rev 116057)
+++ trunk/Source/WebCore/ChangeLog	2012-05-04 01:35:36 UTC (rev 116058)
@@ -1,3 +1,33 @@
+2012-05-03  Ojan Vafai  <o...@chromium.org>
+
+        Histogram total allocated bytes in the arena in addition to the render tree size
+        https://bugs.webkit.org/show_bug.cgi?id=85537
+
+        Reviewed by Eric Seidel.
+
+        We only free bytes allocated to a RenderArena when destroying the Document.
+        Histogram both the render tree size and the total bytes allocated. This
+        gives a better sense of the overhead of RenderArena as well as giving a more
+        accurate number for the amount of actual memory used by the render tree.
+
+        No new tests. This is not webfacing, so this can't be tested without adding
+        API to layout test controller, which doesn't seem worth it for this code.
+
+        * page/Page.cpp:
+        (WebCore::Page::renderTreeSize):
+        (WebCore::Page::setVisibilityState):
+        * page/Page.h:
+        (Page):
+        * platform/Arena.cpp:
+        (WebCore::ArenaAllocate):
+        * platform/Arena.h:
+        (WebCore):
+        * rendering/RenderArena.cpp:
+        (WebCore::RenderArena::allocate):
+        * rendering/RenderArena.h:
+        (WebCore::RenderArena::totalRenderArenaAllocatedBytes):
+        (RenderArena):
+
 2012-05-03  Mary Wu  <mary...@torchmobile.com.cn>
 
         [BlackBerry] Add missed member in CrossThreadResourceRequestData

Modified: trunk/Source/WebCore/page/Page.cpp (116057 => 116058)


--- trunk/Source/WebCore/page/Page.cpp	2012-05-04 01:28:11 UTC (rev 116057)
+++ trunk/Source/WebCore/page/Page.cpp	2012-05-04 01:35:36 UTC (rev 116058)
@@ -210,14 +210,18 @@
 
 }
 
-size_t Page::renderTreeSize() const
+ArenaSize Page::renderTreeSize() const
 {
-    size_t size = 0;
+    ArenaSize total(0, 0);
     for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) {
-        if (frame->document() && frame->document()->renderArena())
-            size += frame->document()->renderArena()->totalRenderArenaSize();
+        if (!frame->document())
+            continue;
+        if (RenderArena* arena = frame->document()->renderArena()) {
+            total.treeSize += arena->totalRenderArenaSize();
+            total.allocated += arena->totalRenderArenaAllocatedBytes();
+        }
     }
-    return size;
+    return total;
 }
 
 ViewportArguments Page::viewportArguments() const
@@ -1029,8 +1033,11 @@
     m_visibilityState = visibilityState;
 
     if (!isInitialState && m_mainFrame) {
-        if (visibilityState == PageVisibilityStateHidden)
-            HistogramSupport::histogramCustomCounts("WebCore.Page.renderTreeSizeBytes", renderTreeSize(), 1000, 500000000, 50);
+        if (visibilityState == PageVisibilityStateHidden) {
+            ArenaSize size = renderTreeSize();
+            HistogramSupport::histogramCustomCounts("WebCore.Page.renderTreeSizeBytes", size.treeSize, 1000, 500000000, 50);
+            HistogramSupport::histogramCustomCounts("WebCore.Page.renderTreeAllocatedBytes", size.allocated, 1000, 500000000, 50);
+        }
         m_mainFrame->dispatchVisibilityStateChangeEvent();
     }
 }

Modified: trunk/Source/WebCore/page/Page.h (116057 => 116058)


--- trunk/Source/WebCore/page/Page.h	2012-05-04 01:28:11 UTC (rev 116057)
+++ trunk/Source/WebCore/page/Page.h	2012-05-04 01:35:36 UTC (rev 116058)
@@ -91,6 +91,16 @@
 
     float deviceScaleFactor(Frame*);
 
+    struct ArenaSize {
+        ArenaSize(size_t treeSize, size_t allocated)
+            : treeSize(treeSize)
+            , allocated(allocated)
+        {
+        }
+        size_t treeSize;
+        size_t allocated;
+    };
+
     class Page : public Supplementable<Page> {
         WTF_MAKE_NONCOPYABLE(Page);
         friend class Settings;
@@ -118,7 +128,7 @@
         Page(PageClients&);
         ~Page();
 
-        size_t renderTreeSize() const;
+        ArenaSize renderTreeSize() const;
 
         void setNeedsRecalcStyleInAllFrames();
 

Modified: trunk/Source/WebCore/platform/Arena.cpp (116057 => 116058)


--- trunk/Source/WebCore/platform/Arena.cpp	2012-05-04 01:28:11 UTC (rev 116057)
+++ trunk/Source/WebCore/platform/Arena.cpp	2012-05-04 01:35:36 UTC (rev 116058)
@@ -97,7 +97,7 @@
      pool->arenasize = size;                                  
 }
 
-void* ArenaAllocate(ArenaPool* pool, unsigned int numBytes)
+void* ArenaAllocate(ArenaPool* pool, unsigned int numBytes, unsigned int& bytesAllocated)
 {
     Arena* arena;
     char* returnPointer;
@@ -127,6 +127,7 @@
         i++;
         printf("Malloc: %d\n", i);
 #endif
+        bytesAllocated = size;
         arena = (Arena*)fastMalloc(size);
         // fastMalloc will abort() if it fails, so we are guaranteed that a is not 0.
         arena->limit = (uword)arena + size;

Modified: trunk/Source/WebCore/platform/Arena.h (116057 => 116058)


--- trunk/Source/WebCore/platform/Arena.h	2012-05-04 01:28:11 UTC (rev 116057)
+++ trunk/Source/WebCore/platform/Arena.h	2012-05-04 01:35:36 UTC (rev 116058)
@@ -69,17 +69,17 @@
 
 void InitArenaPool(ArenaPool*, const char* name, unsigned int size, unsigned int align);
 void FinishArenaPool(ArenaPool*);
-void* ArenaAllocate(ArenaPool*, unsigned int nb);
+void* ArenaAllocate(ArenaPool*, unsigned int numBytes, unsigned int& bytesAllocated);
 
 #define ARENA_ALIGN(n) (((uword)(n) + ARENA_ALIGN_MASK) & ~ARENA_ALIGN_MASK)
 #define INIT_ARENA_POOL(pool, name, size) InitArenaPool(pool, name, size, ARENA_ALIGN_MASK + 1)
-#define ARENA_ALLOCATE(p, pool, nb) \
+#define ARENA_ALLOCATE(p, pool, nb, bytesAllocated) \
     Arena* _a = (pool)->current; \
     unsigned int _nb = ARENA_ALIGN(nb); \
     uword _p = _a->avail; \
     uword _q = _p + _nb; \
     if (_q > _a->limit) \
-        _p = (uword)ArenaAllocate(pool, _nb); \
+        _p = (uword)ArenaAllocate(pool, _nb, *bytesAllocated); \
     else \
         _a->avail = _q; \
     p = (void*)_p;

Modified: trunk/Source/WebCore/rendering/RenderArena.cpp (116057 => 116058)


--- trunk/Source/WebCore/rendering/RenderArena.cpp	2012-05-04 01:28:11 UTC (rev 116057)
+++ trunk/Source/WebCore/rendering/RenderArena.cpp	2012-05-04 01:35:36 UTC (rev 116058)
@@ -110,7 +110,9 @@
 
     if (!result) {
         // Allocate a new chunk from the arena
-        ARENA_ALLOCATE(result, &m_pool, size);
+        unsigned bytesAllocated = 0;
+        ARENA_ALLOCATE(result, &m_pool, size, &bytesAllocated);
+        m_totalAllocated += bytesAllocated;
     }
 
     return result;

Modified: trunk/Source/WebCore/rendering/RenderArena.h (116057 => 116058)


--- trunk/Source/WebCore/rendering/RenderArena.h	2012-05-04 01:28:11 UTC (rev 116057)
+++ trunk/Source/WebCore/rendering/RenderArena.h	2012-05-04 01:35:36 UTC (rev 116058)
@@ -54,6 +54,7 @@
     void free(size_t, void*);
 
     size_t totalRenderArenaSize() const { return m_totalSize; }
+    size_t totalRenderArenaAllocatedBytes() const { return m_totalAllocated; }
 
 private:
     // Underlying arena pool
@@ -64,6 +65,7 @@
     void* m_recyclers[gMaxRecycledSize >> 2];
 
     size_t m_totalSize;
+    size_t m_totalAllocated;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebKit2/ChangeLog (116057 => 116058)


--- trunk/Source/WebKit2/ChangeLog	2012-05-04 01:28:11 UTC (rev 116057)
+++ trunk/Source/WebKit2/ChangeLog	2012-05-04 01:35:36 UTC (rev 116058)
@@ -1,3 +1,13 @@
+2012-05-03  Ojan Vafai  <o...@chromium.org>
+
+        Histogram total allocated bytes in the arena in addition to the render tree size
+        https://bugs.webkit.org/show_bug.cgi?id=85537
+
+        Reviewed by Eric Seidel.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::renderTreeSize):
+
 2012-05-03  Raphael Kubo da Costa  <rak...@webkit.org>
 
         [CMake] Rewrite FindCairo.cmake.

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (116057 => 116058)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2012-05-04 01:28:11 UTC (rev 116057)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2012-05-04 01:35:36 UTC (rev 116058)
@@ -501,7 +501,7 @@
 {
     if (!m_page)
         return 0;
-    return m_page->renderTreeSize();
+    return m_page->renderTreeSize().treeSize;
 }
 
 void WebPage::setPaintedObjectsCounterThreshold(uint64_t threshold)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to