summaryrefslogtreecommitdiff
path: root/Source/WebCore/inspector/MemoryInstrumentationImpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/inspector/MemoryInstrumentationImpl.cpp')
-rw-r--r--Source/WebCore/inspector/MemoryInstrumentationImpl.cpp73
1 files changed, 57 insertions, 16 deletions
diff --git a/Source/WebCore/inspector/MemoryInstrumentationImpl.cpp b/Source/WebCore/inspector/MemoryInstrumentationImpl.cpp
index 946888ce2..e93d66f4f 100644
--- a/Source/WebCore/inspector/MemoryInstrumentationImpl.cpp
+++ b/Source/WebCore/inspector/MemoryInstrumentationImpl.cpp
@@ -34,11 +34,63 @@
#include "MemoryInstrumentationImpl.h"
+#include "WebCoreMemoryInstrumentation.h"
+#include <wtf/Assertions.h>
+#include <wtf/MemoryInstrumentationHashMap.h>
+#include <wtf/MemoryInstrumentationHashSet.h>
+#include <wtf/MemoryInstrumentationVector.h>
+#include <wtf/text/StringHash.h>
+
namespace WebCore {
-MemoryInstrumentationImpl::MemoryInstrumentationImpl(VisitedObjects& visitedObjects)
- : m_visitedObjects(visitedObjects)
+TypeNameToSizeMap MemoryInstrumentationClientImpl::sizesMap() const
{
+ // TypeToSizeMap uses const char* as the key.
+ // Thus it could happen that we have two different keys with equal string.
+ TypeNameToSizeMap sizesMap;
+ for (TypeToSizeMap::const_iterator i = m_totalSizes.begin(); i != m_totalSizes.end(); ++i) {
+ String objectType(i->key);
+ TypeNameToSizeMap::AddResult result = sizesMap.add(objectType, i->value);
+ if (!result.isNewEntry)
+ result.iterator->value += i->value;
+ }
+
+ return sizesMap;
+}
+
+void MemoryInstrumentationClientImpl::countObjectSize(MemoryObjectType objectType, size_t size)
+{
+ ASSERT(objectType);
+ TypeToSizeMap::AddResult result = m_totalSizes.add(objectType, size);
+ if (!result.isNewEntry)
+ result.iterator->value += size;
+ ++m_totalCountedObjects;
+}
+
+bool MemoryInstrumentationClientImpl::visited(const void* object)
+{
+ return !m_visitedObjects.add(object).isNewEntry;
+}
+
+void MemoryInstrumentationClientImpl::checkCountedObject(const void* object)
+{
+ if (!checkInstrumentedObjects())
+ return;
+ if (!m_allocatedObjects.contains(object)) {
+ ++m_totalObjectsNotInAllocatedSet;
+#if 0
+ printf("Found unknown object referenced by pointer: %p\n", object);
+ WTFReportBacktrace();
+#endif
+ }
+}
+
+void MemoryInstrumentationClientImpl::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+{
+ MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::InspectorMemoryAgent);
+ info.addMember(m_totalSizes);
+ info.addMember(m_visitedObjects);
+ info.addMember(m_allocatedObjects);
}
void MemoryInstrumentationImpl::processDeferredInstrumentedPointers()
@@ -50,28 +102,17 @@ void MemoryInstrumentationImpl::processDeferredInstrumentedPointers()
}
}
-void MemoryInstrumentationImpl::countObjectSize(MemoryObjectType objectType, size_t size)
-{
- ASSERT(objectType);
- TypeToSizeMap::AddResult result = m_totalSizes.add(objectType, size);
- if (!result.isNewEntry)
- result.iterator->second += size;
-}
-
void MemoryInstrumentationImpl::deferInstrumentedPointer(PassOwnPtr<InstrumentedPointerBase> pointer)
{
m_deferredInstrumentedPointers.append(pointer);
}
-bool MemoryInstrumentationImpl::visited(const void* object)
+void MemoryInstrumentationImpl::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
{
- return !m_visitedObjects.add(object).isNewEntry;
+ MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::InspectorMemoryAgent);
+ info.addMember(m_deferredInstrumentedPointers);
}
-size_t MemoryInstrumentationImpl::selfSize() const
-{
- return calculateContainerSize(m_visitedObjects) + calculateContainerSize(m_deferredInstrumentedPointers);
-}
} // namespace WebCore