Changeset 127571 in webkit


Ignore:
Timestamp:
Sep 5, 2012 2:19:46 AM (12 years ago)
Author:
loislo@chromium.org
Message:

Web Inspector: NMI: replace ObjectType enum with static const char* string identifiers.
https://bugs.webkit.org/show_bug.cgi?id=95739

Reviewed by Yury Semikhatsky.

When we go deeper into different parts of browser like skia, chromium itself etc.
we can't use a single enum for all reported object types.
The current idea is to use plain simple strings as ObjectType identifiers.
In the future patches we will extract these identifiers into separate class or namespace
and and split it between components.

Source/WebCore:

  • dom/MemoryInstrumentation.cpp:

(WebCore):

  • dom/MemoryInstrumentation.h:

(MemoryInstrumentation):

  • inspector/InspectorMemoryAgent.cpp:

(WebCore::addMemoryBlockFor):
(WebCore):

  • inspector/MemoryInstrumentationImpl.cpp:

(WebCore::MemoryInstrumentationImpl::MemoryInstrumentationImpl):
(WebCore::MemoryInstrumentationImpl::countObjectSize):

  • inspector/MemoryInstrumentationImpl.h:

(WebCore::MemoryInstrumentationImpl::totalSize):
(WebCore::MemoryInstrumentationImpl::reportedSizeForAllTypes):
(MemoryInstrumentationImpl):

Source/WebKit/chromium:

  • tests/MemoryInstrumentationTest.cpp:

(WebCore::TEST):
(WebCore):

Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r127568 r127571  
     12012-09-04  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Web Inspector: NMI: replace ObjectType enum with static const char* string identifiers.
     4        https://bugs.webkit.org/show_bug.cgi?id=95739
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        When we go deeper into different parts of browser like skia, chromium itself etc.
     9        we can't use a single enum for all reported object types.
     10        The current idea is to use plain simple strings as ObjectType identifiers.
     11        In the future patches we will extract these identifiers into separate class or namespace
     12        and and split it between components.
     13
     14        * dom/MemoryInstrumentation.cpp:
     15        (WebCore):
     16        * dom/MemoryInstrumentation.h:
     17        (MemoryInstrumentation):
     18        * inspector/InspectorMemoryAgent.cpp:
     19        (WebCore::addMemoryBlockFor):
     20        (WebCore):
     21        * inspector/MemoryInstrumentationImpl.cpp:
     22        (WebCore::MemoryInstrumentationImpl::MemoryInstrumentationImpl):
     23        (WebCore::MemoryInstrumentationImpl::countObjectSize):
     24        * inspector/MemoryInstrumentationImpl.h:
     25        (WebCore::MemoryInstrumentationImpl::totalSize):
     26        (WebCore::MemoryInstrumentationImpl::reportedSizeForAllTypes):
     27        (MemoryInstrumentationImpl):
     28
    1292012-09-05  Patrick Gansterer  <paroga@webkit.org>
    230
  • trunk/Source/WebCore/dom/MemoryInstrumentation.cpp

    r126154 r127571  
    3838namespace WebCore {
    3939
     40const char* MemoryInstrumentation::Other = "Other";
     41const char* MemoryInstrumentation::DOM = "DOM";
     42const char* MemoryInstrumentation::CSS = "CSS";
     43const char* MemoryInstrumentation::Binding = "Binding";
     44const char* MemoryInstrumentation::Loader = "Loader";
     45const char* MemoryInstrumentation::MemoryCacheStructures = "MemoryCacheStructures";
     46const char* MemoryInstrumentation::CachedResource = "CachedResource";
     47const char* MemoryInstrumentation::CachedResourceCSS = "CachedResourceCSS";
     48const char* MemoryInstrumentation::CachedResourceFont = "CachedResourceFont";
     49const char* MemoryInstrumentation::CachedResourceImage = "CachedResourceImage";
     50const char* MemoryInstrumentation::CachedResourceScript = "CachedResourceScript";
     51const char* MemoryInstrumentation::CachedResourceSVG = "CachedResourceSVG";
     52const char* MemoryInstrumentation::CachedResourceShader = "CachedResourceShader";
     53const char* MemoryInstrumentation::CachedResourceXSLT = "CachedResourceXSLT";
     54
    4055void MemoryInstrumentation::addInstrumentedObjectImpl(const String* const& string, ObjectType objectType, OwningType owningType)
    4156{
  • trunk/Source/WebCore/dom/MemoryInstrumentation.h

    r126926 r127571  
    4949    virtual ~MemoryInstrumentation() { }
    5050
    51     enum ObjectType {
    52         Other,
    53         DOM,
    54         CSS,
    55         Binding,
    56         Loader,
    57         MemoryCacheStructures,
    58         CachedResource,
    59         CachedResourceCSS,
    60         CachedResourceFont,
    61         CachedResourceImage,
    62         CachedResourceScript,
    63         CachedResourceSVG,
    64         CachedResourceShader,
    65         CachedResourceXSLT,
    66         LastTypeEntry
    67     };
     51    typedef const char* ObjectType;
     52
     53    static const char* Other;
     54    static const char* DOM;
     55    static const char* CSS;
     56    static const char* Binding;
     57    static const char* Loader;
     58    static const char* MemoryCacheStructures;
     59    static const char* CachedResource;
     60    static const char* CachedResourceCSS;
     61    static const char* CachedResourceFont;
     62    static const char* CachedResourceImage;
     63    static const char* CachedResourceScript;
     64    static const char* CachedResourceSVG;
     65    static const char* CachedResourceShader;
     66    static const char* CachedResourceXSLT;
    6867
    6968    template <typename T> void addRootObject(const T& t)
  • trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp

    r127443 r127571  
    441441}
    442442
    443 static void addMemoryBlockFor(TypeBuilder::Array<InspectorMemoryBlock>* array, size_t size, const char* name)
     443static size_t addMemoryBlockFor(TypeBuilder::Array<InspectorMemoryBlock>* array, size_t size, const char* name)
    444444{
    445445    RefPtr<InspectorMemoryBlock> result = InspectorMemoryBlock::create().setName(name);
    446446    result->setSize(size);
    447447    array->addItem(result);
     448    return size;
    448449}
    449450
     
    485486        size_t totalSize = 0;
    486487
    487         COMPILE_ASSERT(MemoryInstrumentation::LastTypeEntry == MemoryInstrumentation::CachedResourceXSLT + 1, object_type_enum_was_changed_please_fix_the_implementation);
    488         for (int i = MemoryInstrumentation::MemoryCacheStructures; i < MemoryInstrumentation::LastTypeEntry; ++i)
    489             totalSize += m_memoryInstrumentation.totalSize(static_cast<MemoryInstrumentation::ObjectType>(i));
    490 
    491488        RefPtr<TypeBuilder::Array<InspectorMemoryBlock> > children = TypeBuilder::Array<InspectorMemoryBlock>::create();
    492         addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::MemoryCacheStructures), MemoryBlockName::memoryCacheStructures);
    493         addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResource), MemoryBlockName::cachedResource);
    494         addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceCSS), MemoryBlockName::cachedResourceCSS);
    495         addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceFont), MemoryBlockName::cachedResourceFont);
    496         addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceImage), MemoryBlockName::cachedResourceImage);
    497         addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceScript), MemoryBlockName::cachedResourceScript);
    498         addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceSVG), MemoryBlockName::cachedResourceSVG);
    499         addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceShader), MemoryBlockName::cachedResourceShader);
    500         addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceXSLT), MemoryBlockName::cachedResourceXSLT);
     489        totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::MemoryCacheStructures), MemoryBlockName::memoryCacheStructures);
     490        totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResource), MemoryBlockName::cachedResource);
     491        totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceCSS), MemoryBlockName::cachedResourceCSS);
     492        totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceFont), MemoryBlockName::cachedResourceFont);
     493        totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceImage), MemoryBlockName::cachedResourceImage);
     494        totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceScript), MemoryBlockName::cachedResourceScript);
     495        totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceSVG), MemoryBlockName::cachedResourceSVG);
     496        totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceShader), MemoryBlockName::cachedResourceShader);
     497        totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceXSLT), MemoryBlockName::cachedResourceXSLT);
    501498
    502499        RefPtr<InspectorMemoryBlock> block = InspectorMemoryBlock::create().setName(MemoryBlockName::memoryCache);
     
    509506    {
    510507        size_t totalSize = 0;
    511         for (int i = MemoryInstrumentation::Other; i < MemoryInstrumentation::MemoryCacheStructures; ++i)
    512             totalSize += m_memoryInstrumentation.totalSize(static_cast<MemoryInstrumentation::ObjectType>(i));
    513508
    514509        RefPtr<TypeBuilder::Array<InspectorMemoryBlock> > domChildren = TypeBuilder::Array<InspectorMemoryBlock>::create();
    515         addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::Other), MemoryBlockName::domTreeOther);
    516         addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::DOM), MemoryBlockName::domTreeDOM);
    517         addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CSS), MemoryBlockName::domTreeCSS);
    518         addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::Binding), MemoryBlockName::domTreeBinding);
    519         addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::Loader), MemoryBlockName::domTreeLoader);
     510        totalSize += addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::Other), MemoryBlockName::domTreeOther);
     511        totalSize += addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::DOM), MemoryBlockName::domTreeDOM);
     512        totalSize += addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CSS), MemoryBlockName::domTreeCSS);
     513        totalSize += addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::Binding), MemoryBlockName::domTreeBinding);
     514        totalSize += addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::Loader), MemoryBlockName::domTreeLoader);
    520515
    521516        RefPtr<InspectorMemoryBlock> dom = InspectorMemoryBlock::create().setName(MemoryBlockName::dom);
  • trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.cpp

    r124306 r127571  
    4040    : m_visitedObjects(visitedObjects)
    4141{
    42     for (int i = 0; i < LastTypeEntry; ++i)
    43         m_totalSizes[i] = 0;
    4442}
    4543
     
    5553void MemoryInstrumentationImpl::countObjectSize(ObjectType objectType, size_t size)
    5654{
    57     ASSERT(objectType >= 0 && objectType < LastTypeEntry);
    58     m_totalSizes[objectType] += size;
     55    TypeToSizeMap::AddResult result = m_totalSizes.add(objectType, size);
     56    if (!result.isNewEntry)
     57        result.iterator->second += size;
    5958}
    6059
  • trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.h

    r124412 r127571  
    3434#include "MemoryInstrumentation.h"
    3535
     36#include <wtf/HashMap.h>
    3637#include <wtf/HashSet.h>
    3738#include <wtf/Vector.h>
     
    4849    size_t totalSize(ObjectType objectType) const
    4950    {
    50         ASSERT(objectType >= 0 && objectType < LastTypeEntry);
    51         return m_totalSizes[objectType];
     51        TypeToSizeMap::const_iterator i = m_totalSizes.find(objectType);
     52        return i == m_totalSizes.end() ? 0 : i->second;
    5253    }
    5354
     
    5556    {
    5657        size_t size = 0;
    57         for (int i = 0; i < LastTypeEntry; ++i)
    58             size += m_totalSizes[i];
     58        for (TypeToSizeMap::const_iterator i = m_totalSizes.begin(); i != m_totalSizes.end(); ++i)
     59            size += i->second;
    5960        return size;
    6061    }
     
    6667    virtual void processDeferredInstrumentedPointers() OVERRIDE;
    6768
    68     size_t m_totalSizes[LastTypeEntry];
     69    typedef HashMap<ObjectType, size_t> TypeToSizeMap;
     70    TypeToSizeMap m_totalSizes;
    6971    VisitedObjects& m_visitedObjects;
    7072    Vector<OwnPtr<InstrumentedPointerBase> > m_deferredInstrumentedPointers;
  • trunk/Source/WebKit/chromium/ChangeLog

    r127558 r127571  
     12012-09-04  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Web Inspector: NMI: replace ObjectType enum with static const char* string identifiers.
     4        https://bugs.webkit.org/show_bug.cgi?id=95739
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        When we go deeper into different parts of browser like skia, chromium itself etc.
     9        we can't use a single enum for all reported object types.
     10        The current idea is to use plain simple strings as ObjectType identifiers.
     11        In the future patches we will extract these identifiers into separate class or namespace
     12        and and split it between components.
     13
     14        * tests/MemoryInstrumentationTest.cpp:
     15        (WebCore::TEST):
     16        (WebCore):
     17
    1182012-09-04  Keishi Hattori  <keishi@webkit.org>
    219
  • trunk/Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp

    r126154 r127571  
    256256}
    257257
     258TEST(MemoryInstrumentationTest, speedTest)
     259{
     260    VisitedObjects visitedObjects;
     261    MemoryInstrumentationImpl impl(visitedObjects);
     262    NonVirtualInstrumented nonVirtualInstrumented;
     263    for (unsigned i = 0; i < 10000000; ++i) {
     264        impl.addRootObject(&nonVirtualInstrumented);
     265        visitedObjects.clear();
     266    }
     267}
     268
    258269} // namespace
    259270
Note: See TracChangeset for help on using the changeset viewer.