Web Inspector: simplify Memory.getDOMNodeCount implementation
authoryurys@chromium.org <yurys@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Feb 2013 16:04:28 +0000 (16:04 +0000)
committeryurys@chromium.org <yurys@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Feb 2013 16:04:28 +0000 (16:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=108821

Reviewed by Alexander Pavlov.

Removed Memory.getDOMNodeCount command from the protocol. Memory.getDOMCounters
should be used instead.

* inspector/Inspector.json:
* inspector/InspectorMemoryAgent.cpp:
* inspector/InspectorMemoryAgent.h:
(InspectorMemoryAgent):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@142281 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/Inspector.json
Source/WebCore/inspector/InspectorMemoryAgent.cpp
Source/WebCore/inspector/InspectorMemoryAgent.h

index 433b197ea7cf99127d23d466a7007058b5b53940..44415c8fbfe471b6a9317beab687751e418f839e 100644 (file)
@@ -1,3 +1,18 @@
+2013-02-04  Yury Semikhatsky  <yurys@chromium.org>
+
+        Web Inspector: simplify Memory.getDOMNodeCount implementation
+        https://bugs.webkit.org/show_bug.cgi?id=108821
+
+        Reviewed by Alexander Pavlov.
+
+        Removed Memory.getDOMNodeCount command from the protocol. Memory.getDOMCounters
+        should be used instead.
+
+        * inspector/Inspector.json:
+        * inspector/InspectorMemoryAgent.cpp:
+        * inspector/InspectorMemoryAgent.h:
+        (InspectorMemoryAgent):
+
 2013-02-08  Yury Semikhatsky  <yurys@chromium.org>
 
         Web Inspector: refactor MemoryStatistics.js
index 8dfdc55c001eec17dddfa103f95c7c5d330b86df..1414f64c8226c96079e20e97f7547843e264353a 100644 (file)
         "domain": "Memory",
         "hidden": true,
         "types": [
-            {
-                "id": "NodeCount",
-                "type": "object",
-                "properties": [
-                    { "name": "nodeName", "type": "string" },
-                    { "name": "count", "type": "integer" }
-                ],
-                "description": "Number of nodes with given name."
-            },
-            {
-                "id": "ListenerCount",
-                "type": "object",
-                "properties": [
-                    { "name": "type", "type": "string" },
-                    { "name": "count", "type": "integer" }
-                ],
-                "description": "Number of JS event listeners by event type."
-            },
-            {
-                "id": "StringStatistics",
-                "type": "object",
-                "properties": [
-                    { "name": "dom", "type": "integer" },
-                    { "name": "js", "type": "integer" },
-                    { "name": "shared", "type": "integer" }
-                ],
-                "description": "Character data statistics for the page."
-            },
-            {
-                "id": "DOMGroup",
-                "type": "object",
-                "properties": [
-                    { "name": "size", "type": "integer" },
-                    { "name": "title", "type": "string" },
-                    { "name": "documentURI", "type": "string", "optional": true },
-                    { "name": "nodeCount", "type": "array", "items": { "$ref": "NodeCount" }},
-                    { "name": "listenerCount", "type": "array", "items": { "$ref": "ListenerCount" }}
-                ]
-            },
             {
                 "id": "MemoryBlock",
                 "type": "object",
             }
         ],
         "commands": [
-            {
-                "name": "getDOMNodeCount",
-                "returns": [
-                    { "name": "domGroups", "type": "array", "items": { "$ref": "DOMGroup" }},
-                    { "name": "strings", "$ref": "StringStatistics" }
-                ]
-            },
             {
                 "name": "getDOMCounters",
                 "returns": [
index 41ff16b7971739c3ada2092c62d5253a07f2e3ab..5f6a73d0d9aff3f565662e2a2f9c2e1d5a45d28c 100644 (file)
 #include <wtf/text/StringImpl.h>
 #include <wtf/text/WTFString.h>
 
-using WebCore::TypeBuilder::Memory::DOMGroup;
-using WebCore::TypeBuilder::Memory::ListenerCount;
-using WebCore::TypeBuilder::Memory::NodeCount;
-using WebCore::TypeBuilder::Memory::StringStatistics;
-
 // Use a type alias instead of 'using' here which would cause a conflict on Mac.
 typedef WebCore::TypeBuilder::Memory::MemoryBlock InspectorMemoryBlock;
 typedef WebCore::TypeBuilder::Array<InspectorMemoryBlock> InspectorMemoryBlocks;
@@ -149,219 +144,6 @@ private:
     TypeNameToSizeMap m_sizesMap;
 };
 
-String nodeName(Node* node)
-{
-    if (node->document()->isXHTMLDocument())
-         return node->nodeName();
-    return node->nodeName().lower();
-}
-
-typedef HashSet<StringImpl*, PtrHash<StringImpl*> > StringImplIdentitySet;
-
-class CharacterDataStatistics {
-    WTF_MAKE_NONCOPYABLE(CharacterDataStatistics);
-public:
-    CharacterDataStatistics() : m_characterDataSize(0) { }
-
-    void collectCharacterData(Node* node)
-    {
-        if (!node->isCharacterDataNode())
-            return;
-
-        CharacterData* characterData = static_cast<CharacterData*>(node);
-        StringImpl* dataImpl = characterData->dataImpl();
-        if (m_domStringImplSet.contains(dataImpl))
-            return;
-        m_domStringImplSet.add(dataImpl);
-
-        m_characterDataSize += dataImpl->sizeInBytes();
-    }
-
-    bool contains(StringImpl* s) { return m_domStringImplSet.contains(s); }
-
-    int characterDataSize() { return m_characterDataSize; }
-
-private:
-    StringImplIdentitySet m_domStringImplSet;
-    int m_characterDataSize;
-};
-
-class DOMTreeStatistics {
-    WTF_MAKE_NONCOPYABLE(DOMTreeStatistics);
-public:
-    DOMTreeStatistics(Node* rootNode, CharacterDataStatistics& characterDataStatistics)
-        : m_totalNodeCount(0)
-        , m_characterDataStatistics(characterDataStatistics)
-    {
-        collectTreeStatistics(rootNode);
-    }
-
-    int totalNodeCount() { return m_totalNodeCount; }
-
-    PassRefPtr<TypeBuilder::Array<TypeBuilder::Memory::NodeCount> > nodeCount()
-    {
-        RefPtr<TypeBuilder::Array<TypeBuilder::Memory::NodeCount> > childrenStats = TypeBuilder::Array<TypeBuilder::Memory::NodeCount>::create();
-        for (HashMap<String, int>::iterator it = m_nodeNameToCount.begin(); it != m_nodeNameToCount.end(); ++it) {
-            RefPtr<NodeCount> nodeCount = NodeCount::create().setNodeName(it->key)
-                                                             .setCount(it->value);
-            childrenStats->addItem(nodeCount);
-        }
-        return childrenStats.release();
-    }
-
-    PassRefPtr<TypeBuilder::Array<TypeBuilder::Memory::ListenerCount> > listenerCount()
-    {
-        RefPtr<TypeBuilder::Array<TypeBuilder::Memory::ListenerCount> > listenerStats = TypeBuilder::Array<TypeBuilder::Memory::ListenerCount>::create();
-        for (HashMap<AtomicString, int>::iterator it = m_eventTypeToCount.begin(); it != m_eventTypeToCount.end(); ++it) {
-            RefPtr<ListenerCount> listenerCount = ListenerCount::create().setType(it->key)
-                                                                         .setCount(it->value);
-            listenerStats->addItem(listenerCount);
-        }
-        return listenerStats.release();
-    }
-
-private:
-    void collectTreeStatistics(Node* rootNode)
-    {
-        Node* currentNode = rootNode;
-        collectListenersInfo(rootNode);
-        while ((currentNode = NodeTraversal::next(currentNode, rootNode))) {
-            ++m_totalNodeCount;
-            collectNodeStatistics(currentNode);
-        }
-    }
-    void collectNodeStatistics(Node* node)
-    {
-        m_characterDataStatistics.collectCharacterData(node);
-        collectNodeNameInfo(node);
-        collectListenersInfo(node);
-    }
-
-    void collectNodeNameInfo(Node* node)
-    {
-        String name = nodeName(node);
-        int currentCount = m_nodeNameToCount.get(name);
-        m_nodeNameToCount.set(name, currentCount + 1);
-    }
-
-    void collectListenersInfo(Node* node)
-    {
-        EventTargetData* d = node->eventTargetData();
-        if (!d)
-            return;
-        EventListenerMap& eventListenerMap = d->eventListenerMap;
-        if (eventListenerMap.isEmpty())
-            return;
-        Vector<AtomicString> eventNames = eventListenerMap.eventTypes();
-        for (Vector<AtomicString>::iterator it = eventNames.begin(); it != eventNames.end(); ++it) {
-            AtomicString name = *it;
-            EventListenerVector* listeners = eventListenerMap.find(name);
-            int count = 0;
-            for (EventListenerVector::iterator j = listeners->begin(); j != listeners->end(); ++j) {
-                if (j->listener->type() == EventListener::JSEventListenerType)
-                    ++count;
-            }
-            if (count)
-                m_eventTypeToCount.set(name, m_eventTypeToCount.get(name) + count);
-        }
-    }
-
-    int m_totalNodeCount;
-    HashMap<AtomicString, int> m_eventTypeToCount;
-    HashMap<String, int> m_nodeNameToCount;
-    CharacterDataStatistics& m_characterDataStatistics;
-};
-
-class CounterVisitor : public WrappedNodeVisitor, public ExternalStringVisitor {
-public:
-    CounterVisitor(Page* page)
-        : m_page(page)
-        , m_domGroups(TypeBuilder::Array<TypeBuilder::Memory::DOMGroup>::create())
-        , m_jsExternalStringSize(0)
-        , m_sharedStringSize(0) { }
-
-    TypeBuilder::Array<TypeBuilder::Memory::DOMGroup>* domGroups() { return m_domGroups.get(); }
-
-    PassRefPtr<StringStatistics> strings()
-    {
-        RefPtr<StringStatistics> stringStatistics = StringStatistics::create()
-            .setDom(m_characterDataStatistics.characterDataSize())
-            .setJs(m_jsExternalStringSize)
-            .setShared(m_sharedStringSize);
-        return stringStatistics.release();
-    }
-
-    virtual void visitNode(Node* node)
-    {
-        if (node->document()->frame() && m_page != node->document()->frame()->page())
-            return;
-
-        Node* rootNode = node;
-        while (rootNode->parentNode())
-            rootNode = rootNode->parentNode();
-
-        if (m_roots.contains(rootNode))
-            return;
-        m_roots.add(rootNode);
-
-        DOMTreeStatistics domTreeStats(rootNode, m_characterDataStatistics);
-
-        RefPtr<DOMGroup> domGroup = DOMGroup::create()
-            .setSize(domTreeStats.totalNodeCount())
-            .setTitle(rootNode->nodeType() == Node::ELEMENT_NODE ? elementTitle(static_cast<Element*>(rootNode)) : rootNode->nodeName())
-            .setNodeCount(domTreeStats.nodeCount())
-            .setListenerCount(domTreeStats.listenerCount());
-        if (rootNode->nodeType() == Node::DOCUMENT_NODE)
-            domGroup->setDocumentURI(static_cast<Document*>(rootNode)->documentURI());
-
-        m_domGroups->addItem(domGroup);
-    }
-
-    virtual void visitJSExternalString(StringImpl* string)
-    {
-        int size = string->sizeInBytes();
-        m_jsExternalStringSize += size;
-        if (m_characterDataStatistics.contains(string))
-            m_sharedStringSize += size;
-    }
-
-private:
-    String elementTitle(Element* element)
-    {
-        StringBuilder result;
-        result.append(nodeName(element));
-
-        const AtomicString& idValue = element->getIdAttribute();
-        String idString;
-        if (!idValue.isNull() && !idValue.isEmpty()) {
-            result.append("#");
-            result.append(idValue);
-        }
-
-        HashSet<AtomicString> usedClassNames;
-        if (element->hasClass() && element->isStyledElement()) {
-            const SpaceSplitString& classNamesString = static_cast<StyledElement*>(element)->classNames();
-            size_t classNameCount = classNamesString.size();
-            for (size_t i = 0; i < classNameCount; ++i) {
-                const AtomicString& className = classNamesString[i];
-                if (usedClassNames.contains(className))
-                    continue;
-                usedClassNames.add(className);
-                result.append(".");
-                result.append(className);
-            }
-        }
-        return result.toString();
-    }
-
-    HashSet<Node*> m_roots;
-    Page* m_page;
-    RefPtr<TypeBuilder::Array<TypeBuilder::Memory::DOMGroup> > m_domGroups;
-    CharacterDataStatistics m_characterDataStatistics;
-    int m_jsExternalStringSize;
-    int m_sharedStringSize;
-};
-
 class ExternalStringsRoot : public ExternalStringVisitor {
 public:
     ExternalStringsRoot() : m_memoryClassInfo(0) { }
@@ -412,23 +194,6 @@ InspectorMemoryAgent::~InspectorMemoryAgent()
 {
 }
 
-void InspectorMemoryAgent::getDOMNodeCount(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::Memory::DOMGroup> >& domGroups, RefPtr<TypeBuilder::Memory::StringStatistics>& strings)
-{
-    CounterVisitor counterVisitor(m_page);
-    ScriptProfiler::visitNodeWrappers(&counterVisitor);
-
-    // Make sure all documents reachable from the main frame are accounted.
-    for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
-        if (Document* doc = frame->document())
-            counterVisitor.visitNode(doc);
-    }
-
-    ScriptProfiler::visitExternalStrings(&counterVisitor);
-
-    domGroups = counterVisitor.domGroups();
-    strings = counterVisitor.strings();
-}
-
 void InspectorMemoryAgent::getDOMCounters(ErrorString*, int* documents, int* nodes, int* jsEventListeners)
 {
     *documents = InspectorCounters::counterValue(InspectorCounters::DocumentCounter);
index dda55a55327481c91851b7c252f05f5515658ff4..d5487d009c0db3f8ccdcab13dfd2e8a7e13f9ee0 100644 (file)
@@ -59,7 +59,6 @@ public:
     }
     virtual ~InspectorMemoryAgent();
 
-    virtual void getDOMNodeCount(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::Memory::DOMGroup> >& domGroups, RefPtr<TypeBuilder::Memory::StringStatistics>& strings);
     virtual void getDOMCounters(ErrorString*, int* documents, int* nodes, int* jsEventListeners);
     virtual void getProcessMemoryDistribution(ErrorString*, const bool* reportGraph, RefPtr<TypeBuilder::Memory::MemoryBlock>& processMemory);