Commit f0946f26 authored by loislo@chromium.org's avatar loislo@chromium.org

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):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@127571 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 92f2a29a
2012-09-04 Ilya Tikhonovsky <loislo@chromium.org>
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.
* 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):
2012-09-05 Patrick Gansterer <paroga@webkit.org>
Build fix for WinCE after r127525.
......@@ -37,6 +37,21 @@
namespace WebCore {
const char* MemoryInstrumentation::Other = "Other";
const char* MemoryInstrumentation::DOM = "DOM";
const char* MemoryInstrumentation::CSS = "CSS";
const char* MemoryInstrumentation::Binding = "Binding";
const char* MemoryInstrumentation::Loader = "Loader";
const char* MemoryInstrumentation::MemoryCacheStructures = "MemoryCacheStructures";
const char* MemoryInstrumentation::CachedResource = "CachedResource";
const char* MemoryInstrumentation::CachedResourceCSS = "CachedResourceCSS";
const char* MemoryInstrumentation::CachedResourceFont = "CachedResourceFont";
const char* MemoryInstrumentation::CachedResourceImage = "CachedResourceImage";
const char* MemoryInstrumentation::CachedResourceScript = "CachedResourceScript";
const char* MemoryInstrumentation::CachedResourceSVG = "CachedResourceSVG";
const char* MemoryInstrumentation::CachedResourceShader = "CachedResourceShader";
const char* MemoryInstrumentation::CachedResourceXSLT = "CachedResourceXSLT";
void MemoryInstrumentation::addInstrumentedObjectImpl(const String* const& string, ObjectType objectType, OwningType owningType)
{
if (!string || visited(string))
......
......@@ -48,23 +48,22 @@ class MemoryInstrumentation {
public:
virtual ~MemoryInstrumentation() { }
enum ObjectType {
Other,
DOM,
CSS,
Binding,
Loader,
MemoryCacheStructures,
CachedResource,
CachedResourceCSS,
CachedResourceFont,
CachedResourceImage,
CachedResourceScript,
CachedResourceSVG,
CachedResourceShader,
CachedResourceXSLT,
LastTypeEntry
};
typedef const char* ObjectType;
static const char* Other;
static const char* DOM;
static const char* CSS;
static const char* Binding;
static const char* Loader;
static const char* MemoryCacheStructures;
static const char* CachedResource;
static const char* CachedResourceCSS;
static const char* CachedResourceFont;
static const char* CachedResourceImage;
static const char* CachedResourceScript;
static const char* CachedResourceSVG;
static const char* CachedResourceShader;
static const char* CachedResourceXSLT;
template <typename T> void addRootObject(const T& t)
{
......
......@@ -440,11 +440,12 @@ static PassRefPtr<InspectorMemoryBlock> renderTreeInfo(Page* page)
return renderTreeAllocated.release();
}
static void addMemoryBlockFor(TypeBuilder::Array<InspectorMemoryBlock>* array, size_t size, const char* name)
static size_t addMemoryBlockFor(TypeBuilder::Array<InspectorMemoryBlock>* array, size_t size, const char* name)
{
RefPtr<InspectorMemoryBlock> result = InspectorMemoryBlock::create().setName(name);
result->setSize(size);
array->addItem(result);
return size;
}
namespace {
......@@ -484,20 +485,16 @@ public:
{
size_t totalSize = 0;
COMPILE_ASSERT(MemoryInstrumentation::LastTypeEntry == MemoryInstrumentation::CachedResourceXSLT + 1, object_type_enum_was_changed_please_fix_the_implementation);
for (int i = MemoryInstrumentation::MemoryCacheStructures; i < MemoryInstrumentation::LastTypeEntry; ++i)
totalSize += m_memoryInstrumentation.totalSize(static_cast<MemoryInstrumentation::ObjectType>(i));
RefPtr<TypeBuilder::Array<InspectorMemoryBlock> > children = TypeBuilder::Array<InspectorMemoryBlock>::create();
addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::MemoryCacheStructures), MemoryBlockName::memoryCacheStructures);
addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResource), MemoryBlockName::cachedResource);
addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceCSS), MemoryBlockName::cachedResourceCSS);
addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceFont), MemoryBlockName::cachedResourceFont);
addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceImage), MemoryBlockName::cachedResourceImage);
addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceScript), MemoryBlockName::cachedResourceScript);
addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceSVG), MemoryBlockName::cachedResourceSVG);
addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceShader), MemoryBlockName::cachedResourceShader);
addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceXSLT), MemoryBlockName::cachedResourceXSLT);
totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::MemoryCacheStructures), MemoryBlockName::memoryCacheStructures);
totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResource), MemoryBlockName::cachedResource);
totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceCSS), MemoryBlockName::cachedResourceCSS);
totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceFont), MemoryBlockName::cachedResourceFont);
totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceImage), MemoryBlockName::cachedResourceImage);
totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceScript), MemoryBlockName::cachedResourceScript);
totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceSVG), MemoryBlockName::cachedResourceSVG);
totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceShader), MemoryBlockName::cachedResourceShader);
totalSize += addMemoryBlockFor(children.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CachedResourceXSLT), MemoryBlockName::cachedResourceXSLT);
RefPtr<InspectorMemoryBlock> block = InspectorMemoryBlock::create().setName(MemoryBlockName::memoryCache);
block->setSize(totalSize);
......@@ -508,15 +505,13 @@ public:
PassRefPtr<InspectorMemoryBlock> buildObjectForDOM() const
{
size_t totalSize = 0;
for (int i = MemoryInstrumentation::Other; i < MemoryInstrumentation::MemoryCacheStructures; ++i)
totalSize += m_memoryInstrumentation.totalSize(static_cast<MemoryInstrumentation::ObjectType>(i));
RefPtr<TypeBuilder::Array<InspectorMemoryBlock> > domChildren = TypeBuilder::Array<InspectorMemoryBlock>::create();
addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::Other), MemoryBlockName::domTreeOther);
addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::DOM), MemoryBlockName::domTreeDOM);
addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CSS), MemoryBlockName::domTreeCSS);
addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::Binding), MemoryBlockName::domTreeBinding);
addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::Loader), MemoryBlockName::domTreeLoader);
totalSize += addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::Other), MemoryBlockName::domTreeOther);
totalSize += addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::DOM), MemoryBlockName::domTreeDOM);
totalSize += addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::CSS), MemoryBlockName::domTreeCSS);
totalSize += addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::Binding), MemoryBlockName::domTreeBinding);
totalSize += addMemoryBlockFor(domChildren.get(), m_memoryInstrumentation.totalSize(MemoryInstrumentation::Loader), MemoryBlockName::domTreeLoader);
RefPtr<InspectorMemoryBlock> dom = InspectorMemoryBlock::create().setName(MemoryBlockName::dom);
dom->setSize(totalSize);
......
......@@ -39,8 +39,6 @@ namespace WebCore {
MemoryInstrumentationImpl::MemoryInstrumentationImpl(VisitedObjects& visitedObjects)
: m_visitedObjects(visitedObjects)
{
for (int i = 0; i < LastTypeEntry; ++i)
m_totalSizes[i] = 0;
}
void MemoryInstrumentationImpl::processDeferredInstrumentedPointers()
......@@ -54,8 +52,9 @@ void MemoryInstrumentationImpl::processDeferredInstrumentedPointers()
void MemoryInstrumentationImpl::countObjectSize(ObjectType objectType, size_t size)
{
ASSERT(objectType >= 0 && objectType < LastTypeEntry);
m_totalSizes[objectType] += size;
TypeToSizeMap::AddResult result = m_totalSizes.add(objectType, size);
if (!result.isNewEntry)
result.iterator->second += size;
}
void MemoryInstrumentationImpl::deferInstrumentedPointer(PassOwnPtr<InstrumentedPointerBase> pointer)
......
......@@ -33,6 +33,7 @@
#include "MemoryInstrumentation.h"
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/Vector.h>
......@@ -47,15 +48,15 @@ public:
size_t selfSize() const;
size_t totalSize(ObjectType objectType) const
{
ASSERT(objectType >= 0 && objectType < LastTypeEntry);
return m_totalSizes[objectType];
TypeToSizeMap::const_iterator i = m_totalSizes.find(objectType);
return i == m_totalSizes.end() ? 0 : i->second;
}
size_t reportedSizeForAllTypes() const
{
size_t size = 0;
for (int i = 0; i < LastTypeEntry; ++i)
size += m_totalSizes[i];
for (TypeToSizeMap::const_iterator i = m_totalSizes.begin(); i != m_totalSizes.end(); ++i)
size += i->second;
return size;
}
......@@ -65,7 +66,8 @@ private:
virtual bool visited(const void*) OVERRIDE;
virtual void processDeferredInstrumentedPointers() OVERRIDE;
size_t m_totalSizes[LastTypeEntry];
typedef HashMap<ObjectType, size_t> TypeToSizeMap;
TypeToSizeMap m_totalSizes;
VisitedObjects& m_visitedObjects;
Vector<OwnPtr<InstrumentedPointerBase> > m_deferredInstrumentedPointers;
};
......
2012-09-04 Ilya Tikhonovsky <loislo@chromium.org>
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.
* tests/MemoryInstrumentationTest.cpp:
(WebCore::TEST):
(WebCore):
2012-09-04 Keishi Hattori <keishi@webkit.org>
Move PagePopupClient implementation for input[type=date] to Chromium WebKit layer
......
......@@ -255,5 +255,16 @@ TEST(MemoryInstrumentationTest, visitStrings)
}
}
TEST(MemoryInstrumentationTest, speedTest)
{
VisitedObjects visitedObjects;
MemoryInstrumentationImpl impl(visitedObjects);
NonVirtualInstrumented nonVirtualInstrumented;
for (unsigned i = 0; i < 10000000; ++i) {
impl.addRootObject(&nonVirtualInstrumented);
visitedObjects.clear();
}
}
} // namespace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment