Web Inspector: introduce a memory agent stub.
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2011 23:49:19 +0000 (23:49 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2011 23:49:19 +0000 (23:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=73930

Reviewed by Timothy Hatcher.

We'd like to experiment with the memory stats and hence need a
nice home for that. Adding this undocumented agent / domain for now.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/ScriptProfiler.h:
(WebCore::ScriptProfiler::nodeCount):
* bindings/v8/ScriptProfiler.cpp:
(WebCore::ScriptProfiler::nodeCount):
* bindings/v8/ScriptProfiler.h:
* inspector/Inspector.json:
* inspector/InspectorController.cpp:
(WebCore::InspectorController::InspectorController):
* inspector/InspectorMemoryAgent.cpp: Added.
(WebCore::InspectorMemoryAgent::~InspectorMemoryAgent):
(WebCore::InspectorMemoryAgent::getNodeCounter):
(WebCore::InspectorMemoryAgent::InspectorMemoryAgent):
* inspector/InspectorMemoryAgent.h: Added.
(WebCore::InspectorMemoryAgent::create):

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

14 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/ScriptProfiler.h
Source/WebCore/bindings/v8/ScriptProfiler.cpp
Source/WebCore/bindings/v8/ScriptProfiler.h
Source/WebCore/inspector/Inspector.json
Source/WebCore/inspector/InspectorController.cpp
Source/WebCore/inspector/InspectorMemoryAgent.cpp [new file with mode: 0644]
Source/WebCore/inspector/InspectorMemoryAgent.h [new file with mode: 0644]

index 3d16686..5855ad4 100644 (file)
@@ -886,6 +886,7 @@ SET(WebCore_SOURCES
     inspector/InspectorFrontendClientLocal.cpp
     inspector/InspectorFrontendHost.cpp
     inspector/InspectorInstrumentation.cpp
+    inspector/InspectorMemoryAgent.cpp
     inspector/InspectorProfilerAgent.cpp
     inspector/InspectorResourceAgent.cpp
     inspector/InspectorRuntimeAgent.cpp
index 63bf9d4..2c553bc 100644 (file)
@@ -1,3 +1,34 @@
+2011-12-06  Pavel Feldman  <pfeldman@google.com>
+
+        Web Inspector: introduce a memory agent stub.
+        https://bugs.webkit.org/show_bug.cgi?id=73930
+
+        Reviewed by Timothy Hatcher.
+
+        We'd like to experiment with the memory stats and hence need a
+        nice home for that. Adding this undocumented agent / domain for now.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/ScriptProfiler.h:
+        (WebCore::ScriptProfiler::nodeCount):
+        * bindings/v8/ScriptProfiler.cpp:
+        (WebCore::ScriptProfiler::nodeCount):
+        * bindings/v8/ScriptProfiler.h:
+        * inspector/Inspector.json:
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::InspectorController):
+        * inspector/InspectorMemoryAgent.cpp: Added.
+        (WebCore::InspectorMemoryAgent::~InspectorMemoryAgent):
+        (WebCore::InspectorMemoryAgent::getNodeCounter):
+        (WebCore::InspectorMemoryAgent::InspectorMemoryAgent):
+        * inspector/InspectorMemoryAgent.h: Added.
+        (WebCore::InspectorMemoryAgent::create):
+
 2011-12-06  Julien Chaffraix  <jchaffraix@webkit.org>
 
         Unreviewed build fix after 102183.
index e59dcb9..e175122 100644 (file)
@@ -2067,6 +2067,8 @@ webcore_sources += \
        Source/WebCore/inspector/InspectorFrontendHost.h \
        Source/WebCore/inspector/InspectorInstrumentation.cpp \
        Source/WebCore/inspector/InspectorInstrumentation.h \
+       Source/WebCore/inspector/InspectorMemoryAgent.cpp \
+       Source/WebCore/inspector/InspectorMemoryAgent.h \
        Source/WebCore/inspector/InspectorPageAgent.cpp \
        Source/WebCore/inspector/InspectorPageAgent.h \
        Source/WebCore/inspector/InspectorProfilerAgent.cpp \
index a2b94e2..7e42d24 100644 (file)
@@ -866,6 +866,7 @@ SOURCES += \
     inspector/InspectorFrontendClientLocal.cpp \
     inspector/InspectorFrontendHost.cpp \
     inspector/InspectorInstrumentation.cpp \
+    inspector/InspectorMemoryAgent.cpp \
     inspector/InspectorPageAgent.cpp \
     inspector/InspectorProfilerAgent.cpp \
     inspector/InspectorResourceAgent.cpp \
@@ -1910,6 +1911,7 @@ HEADERS += \
     inspector/InspectorFrontendClientLocal.h \
     inspector/InspectorFrontendHost.h \
     inspector/InspectorInstrumentation.h \
+    inspector/InspectorMemoryAgent.h \
     inspector/InspectorPageAgent.h \
     inspector/InspectorProfilerAgent.h \
     inspector/InspectorResourceAgent.h \
index ed398f8..b3fb18a 100644 (file)
             'inspector/InspectorFrontendHost.h',
             'inspector/InspectorInstrumentation.cpp',
             'inspector/InspectorInstrumentation.h',
+            'inspector/InspectorMemoryAgent.cpp',
+            'inspector/InspectorMemoryAgent.h',
             'inspector/InspectorPageAgent.cpp',
             'inspector/InspectorPageAgent.h',
             'inspector/InspectorProfilerAgent.cpp',
index cfd7221..2264fbb 100755 (executable)
                                >
                        </File>
                        <File
+                               RelativePath="..\inspector\InspectorMemoryAgent.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\inspector\InspectorMemoryAgent.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\inspector\InspectorPageAgent.cpp"
                                >
                        </File>
index dd5f7f9..73e9857 100644 (file)
                7AA365EE12E7265400DCA242 /* InspectorRuntimeAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AA365ED12E7265400DCA242 /* InspectorRuntimeAgent.cpp */; };
                7AA51B6E1483B61600AD2752 /* InspectorBaseAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AA51B6C1483B61600AD2752 /* InspectorBaseAgent.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7AA51B6F1483B61600AD2752 /* InspectorBaseAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AA51B6D1483B61600AD2752 /* InspectorBaseAgent.cpp */; };
+               7AA51DD5148506A900AD2752 /* InspectorMemoryAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AA51DD3148506A900AD2752 /* InspectorMemoryAgent.cpp */; };
+               7AA51DD6148506A900AD2752 /* InspectorMemoryAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AA51DD4148506A900AD2752 /* InspectorMemoryAgent.h */; };
                7AB0B1C01211A62200A76940 /* InspectorDatabaseAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AB0B1BE1211A62200A76940 /* InspectorDatabaseAgent.cpp */; };
                7AB0B1C11211A62200A76940 /* InspectorDatabaseAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AB0B1BF1211A62200A76940 /* InspectorDatabaseAgent.h */; };
                7ADE722610CBBB9B006B3B3A /* ContextMenuProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 7ADE722510CBBB9B006B3B3A /* ContextMenuProvider.h */; };
                7AA365ED12E7265400DCA242 /* InspectorRuntimeAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorRuntimeAgent.cpp; sourceTree = "<group>"; };
                7AA51B6C1483B61600AD2752 /* InspectorBaseAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorBaseAgent.h; sourceTree = "<group>"; };
                7AA51B6D1483B61600AD2752 /* InspectorBaseAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorBaseAgent.cpp; sourceTree = "<group>"; };
+               7AA51DD3148506A900AD2752 /* InspectorMemoryAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorMemoryAgent.cpp; sourceTree = "<group>"; };
+               7AA51DD4148506A900AD2752 /* InspectorMemoryAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorMemoryAgent.h; sourceTree = "<group>"; };
                7AB0B1BE1211A62200A76940 /* InspectorDatabaseAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorDatabaseAgent.cpp; sourceTree = "<group>"; };
                7AB0B1BF1211A62200A76940 /* InspectorDatabaseAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorDatabaseAgent.h; sourceTree = "<group>"; };
                7ADE722510CBBB9B006B3B3A /* ContextMenuProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContextMenuProvider.h; sourceTree = "<group>"; };
                                7A0E770D10C00A8800A0276E /* InspectorFrontendHost.idl */,
                                20D629241253690B00081543 /* InspectorInstrumentation.cpp */,
                                20D629251253690B00081543 /* InspectorInstrumentation.h */,
+                               7AA51DD3148506A900AD2752 /* InspectorMemoryAgent.cpp */,
+                               7AA51DD4148506A900AD2752 /* InspectorMemoryAgent.h */,
                                4F6FDD621341DEDD001F8EE3 /* InspectorPageAgent.cpp */,
                                4F6FDD631341DEDD001F8EE3 /* InspectorPageAgent.h */,
                                9F0D6B2C121BFEBA006C0288 /* InspectorProfilerAgent.cpp */,
                                A10DC76B14747BAB005E2471 /* StyleGridData.h in Headers */,
                                312C0C41146DC6CC0016C911 /* Notification.h in Headers */,
                                3128CA6B147331630074C72A /* NotificationController.h in Headers */,
+                               7AA51DD6148506A900AD2752 /* InspectorMemoryAgent.h in Headers */,
                                5038BF2814750F190095E0D1 /* CustomFilterOperation.h in Headers */,
                                5038BF2914750F190095E0D1 /* FilterOperation.h in Headers */,
                                5038BF2B14750F190095E0D1 /* FilterOperations.h in Headers */,
                                7AA51B6F1483B61600AD2752 /* InspectorBaseAgent.cpp in Sources */,
                                A10DC76A14747BAB005E2471 /* StyleGridData.cpp in Sources */,
                                3128CA68147331520074C72A /* NotificationController.cpp in Sources */,
+                               7AA51DD5148506A900AD2752 /* InspectorMemoryAgent.cpp in Sources */,
                                5038BF2A14750F190095E0D1 /* FilterOperations.cpp in Sources */,
                                6E3FAD3814733F4000E42306 /* JSWebGLCompressedTextures.cpp in Sources */,
                                6E3FAE8E14733FDB00E42306 /* WebGLCompressedTextures.cpp in Sources */,
index 8bb05c4..b28faa9 100644 (file)
@@ -58,6 +58,8 @@ public:
     static bool causesRecompilation() { return true; }
     static bool isSampling() { return false; }
     static bool hasHeapProfiler() { return false; }
+    // FIXME: Implement this counter for JSC. See bug 73936 for more details.
+    static unsigned domNodeCount() { return 0; }
 };
 
 } // namespace WebCore
index bfc6a87..ff34234 100644 (file)
@@ -35,6 +35,7 @@
 #include "InspectorValues.h"
 #include "RetainedDOMInfo.h"
 #include "V8Binding.h"
+#include "V8DOMMap.h"
 #include "V8Node.h"
 
 #include <v8-profiler.h>
@@ -145,5 +146,44 @@ void ScriptProfiler::initialize()
 #endif // ENABLE(INSPECTOR)
 }
 
+namespace {
+
+class CounterVisitor : public DOMWrapperMap<Node>::Visitor {
+public:
+    CounterVisitor() : m_count(0) { }
+
+    void visitDOMWrapper(DOMDataStore* store, Node* node, v8::Persistent<v8::Object> wrapper)
+    {
+        Node* rootNode = node;
+        while (rootNode->parentNode())
+            rootNode = rootNode->parentNode();
+
+        if (m_roots.contains(rootNode))
+            return;
+        m_roots.add(rootNode);
+
+        Node* currentNode = rootNode;
+        while ((currentNode = currentNode->traverseNextNode(rootNode)))
+            ++m_count;
+    }
+
+    unsigned nodeCount()
+    {
+        return m_count;
+    }
+private:
+    HashSet<Node*> m_roots;
+    unsigned m_count;
+};
+
+} // namespace
+
+unsigned ScriptProfiler::domNodeCount()
+{
+    CounterVisitor counterVisitor;
+    visitDOMNodes(&counterVisitor);
+    return counterVisitor.nodeCount();
+}
+
 
 } // namespace WebCore
index 7106d7c..5b3b617 100644 (file)
@@ -63,6 +63,7 @@ public:
     static bool isSampling() { return true; }
     static bool hasHeapProfiler() { return true; }
     static void initialize();
+    static unsigned domNodeCount();
 };
 
 } // namespace WebCore
index 64b78ba..591b2a5 100644 (file)
         ]
     },
     {
+        "domain": "Memory",
+        "hidden": true,
+        "commands": [
+            {
+                "name": "getDOMNodeCount",
+                "returns": [
+                    { "name": "count", "type": "integer" }
+                ]
+            }
+        ]
+    },
+    {
         "domain": "Page",
         "description": "Actions and events related to the inspected page belong to the page domain.",
         "types": [
index 3dcfdd3..2f8dfe0 100644 (file)
@@ -53,6 +53,7 @@
 #include "InspectorFrontend.h"
 #include "InspectorFrontendClient.h"
 #include "InspectorInstrumentation.h"
+#include "InspectorMemoryAgent.h"
 #include "InspectorPageAgent.h"
 #include "InspectorProfilerAgent.h"
 #include "InspectorResourceAgent.h"
@@ -135,6 +136,8 @@ InspectorController::InspectorController(Page* page, InspectorClient* inspectorC
     m_agents.append(InspectorWorkerAgent::create(m_instrumentingAgents.get(), m_state.get()));
 #endif
 
+    m_agents.append(InspectorMemoryAgent::create(m_instrumentingAgents.get(), m_state.get(), m_page));
+
     ASSERT_ARG(inspectorClient, inspectorClient);
     m_injectedScriptManager->injectedScriptHost()->init(m_inspectorAgent
         , consoleAgent
diff --git a/Source/WebCore/inspector/InspectorMemoryAgent.cpp b/Source/WebCore/inspector/InspectorMemoryAgent.cpp
new file mode 100644 (file)
index 0000000..017a635
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+* Copyright (C) 2011 Google Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+*     * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following disclaimer
+* in the documentation and/or other materials provided with the
+* distribution.
+*     * Neither the name of Google Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from
+* this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "config.h"
+#include "InspectorMemoryAgent.h"
+
+#if ENABLE(INSPECTOR)
+
+#include "InspectorState.h"
+#include "InspectorValues.h"
+#include "InstrumentingAgents.h"
+#include "Node.h"
+#include "Page.h"
+#include "ScriptProfiler.h"
+#include <wtf/HashSet.h>
+
+namespace WebCore {
+
+InspectorMemoryAgent::~InspectorMemoryAgent()
+{
+}
+
+void InspectorMemoryAgent::getDOMNodeCount(ErrorString*, int* result)
+{
+    *result = ScriptProfiler::domNodeCount();
+}
+
+InspectorMemoryAgent::InspectorMemoryAgent(InstrumentingAgents* instrumentingAgents, InspectorState* state, Page* page)
+    : InspectorBaseAgent<InspectorMemoryAgent>("Memory", instrumentingAgents, state)
+    , m_page(page)
+{
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INSPECTOR)
diff --git a/Source/WebCore/inspector/InspectorMemoryAgent.h b/Source/WebCore/inspector/InspectorMemoryAgent.h
new file mode 100644 (file)
index 0000000..d7451f6
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+* Copyright (C) 2011 Google Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+*     * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following disclaimer
+* in the documentation and/or other materials provided with the
+* distribution.
+*     * Neither the name of Google Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from
+* this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef InspectorMemoryAgent_h
+#define InspectorMemoryAgent_h
+
+#if ENABLE(INSPECTOR)
+
+#include "InspectorBaseAgent.h"
+#include <wtf/PassOwnPtr.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+class InspectorFrontend;
+class InspectorState;
+class InspectorArray;
+class InstrumentingAgents;
+class Page;
+
+typedef String ErrorString;
+
+class InspectorMemoryAgent : public InspectorBaseAgent<InspectorMemoryAgent> {
+    WTF_MAKE_NONCOPYABLE(InspectorMemoryAgent);
+public:
+    typedef Vector<OwnPtr<InspectorBaseAgentInterface> > InspectorAgents;
+
+    static PassOwnPtr<InspectorMemoryAgent> create(InstrumentingAgents* instrumentingAgents, InspectorState* state, Page* page)
+    {
+        return adoptPtr(new InspectorMemoryAgent(instrumentingAgents, state, page));
+    }
+
+    void getDOMNodeCount(ErrorString*, int* result);
+
+    ~InspectorMemoryAgent();
+
+private:
+    InspectorMemoryAgent(InstrumentingAgents*, InspectorState*, Page*);
+    Page* m_page;
+};
+
+} // namespace WebCore
+
+#endif // !ENABLE(INSPECTOR)
+#endif // !defined(InspectorMemoryAgent_h)