Diff
Modified: trunk/Source/WebCore/ChangeLog (102365 => 102366)
--- trunk/Source/WebCore/ChangeLog 2011-12-08 20:34:05 UTC (rev 102365)
+++ trunk/Source/WebCore/ChangeLog 2011-12-08 20:41:30 UTC (rev 102366)
@@ -1,3 +1,23 @@
+2011-12-08 Pavel Feldman <[email protected]>
+
+ Web Inspector: return node counts on the document / detached root basis
+ https://bugs.webkit.org/show_bug.cgi?id=74104
+
+ Reviewed by Yury Semikhatsky.
+
+ * bindings/js/ScriptProfiler.h:
+ * bindings/v8/ScriptProfiler.cpp:
+ (WebCore::ScriptProfiler::domNodeCount):
+ * bindings/v8/ScriptProfiler.h:
+ * inspector/Inspector.json:
+ * inspector/InspectorController.cpp:
+ (WebCore::InspectorController::InspectorController):
+ * inspector/InspectorMemoryAgent.cpp:
+ (WebCore::InspectorMemoryAgent::getDOMNodeCount):
+ (WebCore::InspectorMemoryAgent::InspectorMemoryAgent):
+ * inspector/InspectorMemoryAgent.h:
+ (WebCore::InspectorMemoryAgent::create):
+
2011-12-08 Andreas Kling <[email protected]>
RenderObject: Rename styleSlowCase() to styleInRegion().
Modified: trunk/Source/WebCore/bindings/js/ScriptProfiler.h (102365 => 102366)
--- trunk/Source/WebCore/bindings/js/ScriptProfiler.h 2011-12-08 20:34:05 UTC (rev 102365)
+++ trunk/Source/WebCore/bindings/js/ScriptProfiler.h 2011-12-08 20:41:30 UTC (rev 102366)
@@ -28,15 +28,17 @@
#define ScriptProfiler_h
#if ENABLE(_javascript__DEBUGGER)
+#include "InspectorValues.h"
#include "ScriptHeapSnapshot.h"
#include "ScriptProfile.h"
#include "ScriptState.h"
+#include <wtf/PassRefPtr.h>
namespace WebCore {
class InjectedScriptManager;
-class InspectorValue;
+class Page;
class ScriptProfiler {
WTF_MAKE_NONCOPYABLE(ScriptProfiler);
@@ -59,7 +61,7 @@
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; }
+ static PassRefPtr<InspectorArray> domNodeCount(Page*) { return 0; };
};
} // namespace WebCore
Modified: trunk/Source/WebCore/bindings/v8/ScriptProfiler.cpp (102365 => 102366)
--- trunk/Source/WebCore/bindings/v8/ScriptProfiler.cpp 2011-12-08 20:34:05 UTC (rev 102365)
+++ trunk/Source/WebCore/bindings/v8/ScriptProfiler.cpp 2011-12-08 20:41:30 UTC (rev 102366)
@@ -31,12 +31,14 @@
#include "config.h"
#include "ScriptProfiler.h"
+#include "DOMNodeHighlighter.h"
#include "InjectedScript.h"
#include "InspectorValues.h"
#include "RetainedDOMInfo.h"
#include "V8Binding.h"
#include "V8DOMMap.h"
#include "V8Node.h"
+#include <wtf/text/StringBuilder.h>
#include <v8-profiler.h>
@@ -150,10 +152,13 @@
class CounterVisitor : public DOMWrapperMap<Node>::Visitor {
public:
- CounterVisitor() : m_count(0) { }
+ CounterVisitor(Page* page, InspectorArray* counters) : m_page(page), m_counters(counters) { }
void visitDOMWrapper(DOMDataStore* store, Node* node, v8::Persistent<v8::Object> wrapper)
{
+ if (node->document()->frame() && m_page != node->document()->frame()->page())
+ return;
+
Node* rootNode = node;
while (rootNode->parentNode())
rootNode = rootNode->parentNode();
@@ -162,27 +167,63 @@
return;
m_roots.add(rootNode);
+ unsigned count = 0;
Node* currentNode = rootNode;
while ((currentNode = currentNode->traverseNextNode(rootNode)))
- ++m_count;
+ ++count;
+
+ RefPtr<InspectorObject> entry = InspectorObject::create();
+ entry->setNumber("size", count);
+
+ entry->setString("title", rootNode->nodeType() == Node::ELEMENT_NODE ? elementTitle(static_cast<Element*>(rootNode)) : rootNode->nodeName());
+ if (rootNode->nodeType() == Node::DOCUMENT_NODE)
+ entry->setString("documentURI", static_cast<Document*>(rootNode)->documentURI());
+ m_counters->pushObject(entry);
}
- unsigned nodeCount()
+private:
+ String elementTitle(Element* element)
{
- return m_count;
+ StringBuilder result;
+ bool isXHTML = element->document()->isXHTMLDocument();
+ result.append(isXHTML ? element->nodeName() : element->nodeName().lower());
+
+ 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();
}
-private:
+
HashSet<Node*> m_roots;
- unsigned m_count;
+ Page* m_page;
+ InspectorArray* m_counters;
};
} // namespace
-unsigned ScriptProfiler::domNodeCount()
+PassRefPtr<InspectorArray> ScriptProfiler::domNodeCount(Page* page)
{
- CounterVisitor counterVisitor;
+ RefPtr<InspectorArray> result = InspectorArray::create();
+ CounterVisitor counterVisitor(page, result.get());
visitDOMNodes(&counterVisitor);
- return counterVisitor.nodeCount();
+ return result;
}
Modified: trunk/Source/WebCore/bindings/v8/ScriptProfiler.h (102365 => 102366)
--- trunk/Source/WebCore/bindings/v8/ScriptProfiler.h 2011-12-08 20:34:05 UTC (rev 102365)
+++ trunk/Source/WebCore/bindings/v8/ScriptProfiler.h 2011-12-08 20:41:30 UTC (rev 102366)
@@ -31,16 +31,18 @@
#ifndef ScriptProfiler_h
#define ScriptProfiler_h
+#include "InspectorValues.h"
#include "PlatformString.h"
#include "ScriptHeapSnapshot.h"
#include "ScriptProfile.h"
#include "ScriptState.h"
+#include <wtf/PassRefPtr.h>
namespace WebCore {
class InjectedScriptManager;
-class InspectorValue;
+class Page;
class ScriptProfiler {
WTF_MAKE_NONCOPYABLE(ScriptProfiler);
@@ -63,7 +65,7 @@
static bool isSampling() { return true; }
static bool hasHeapProfiler() { return true; }
static void initialize();
- static unsigned domNodeCount();
+ static PassRefPtr<InspectorArray> domNodeCount(Page*);
};
} // namespace WebCore
Modified: trunk/Source/WebCore/inspector/Inspector.json (102365 => 102366)
--- trunk/Source/WebCore/inspector/Inspector.json 2011-12-08 20:34:05 UTC (rev 102365)
+++ trunk/Source/WebCore/inspector/Inspector.json 2011-12-08 20:41:30 UTC (rev 102366)
@@ -48,11 +48,21 @@
{
"domain": "Memory",
"hidden": true,
+ "types": [
+ {
+ "id": "DOMGroup",
+ "type": "object",
+ "properties": [
+ { "name": "size", "type": "integer" },
+ { "name": "title", "type": "string" }
+ ]
+ }
+ ],
"commands": [
{
"name": "getDOMNodeCount",
"returns": [
- { "name": "count", "type": "integer" }
+ { "name": "count", "type": "array", "items": { "$ref": "DOMGroup" }}
]
}
]
Modified: trunk/Source/WebCore/inspector/InspectorController.cpp (102365 => 102366)
--- trunk/Source/WebCore/inspector/InspectorController.cpp 2011-12-08 20:34:05 UTC (rev 102365)
+++ trunk/Source/WebCore/inspector/InspectorController.cpp 2011-12-08 20:41:30 UTC (rev 102366)
@@ -136,7 +136,7 @@
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));
+ m_agents.append(InspectorMemoryAgent::create(m_instrumentingAgents.get(), m_state.get(), m_page, m_domAgent));
ASSERT_ARG(inspectorClient, inspectorClient);
m_injectedScriptManager->injectedScriptHost()->init(m_inspectorAgent
Modified: trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp (102365 => 102366)
--- trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp 2011-12-08 20:34:05 UTC (rev 102365)
+++ trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp 2011-12-08 20:41:30 UTC (rev 102366)
@@ -47,14 +47,15 @@
{
}
-void InspectorMemoryAgent::getDOMNodeCount(ErrorString*, int* result)
+void InspectorMemoryAgent::getDOMNodeCount(ErrorString*, RefPtr<InspectorArray>* result)
{
- *result = ScriptProfiler::domNodeCount();
+ *result = ScriptProfiler::domNodeCount(m_page);
}
-InspectorMemoryAgent::InspectorMemoryAgent(InstrumentingAgents* instrumentingAgents, InspectorState* state, Page* page)
+InspectorMemoryAgent::InspectorMemoryAgent(InstrumentingAgents* instrumentingAgents, InspectorState* state, Page* page, InspectorDOMAgent* domAgent)
: InspectorBaseAgent<InspectorMemoryAgent>("Memory", instrumentingAgents, state)
, m_page(page)
+ , m_domAgent(domAgent)
{
}
Modified: trunk/Source/WebCore/inspector/InspectorMemoryAgent.h (102365 => 102366)
--- trunk/Source/WebCore/inspector/InspectorMemoryAgent.h 2011-12-08 20:34:05 UTC (rev 102365)
+++ trunk/Source/WebCore/inspector/InspectorMemoryAgent.h 2011-12-08 20:41:30 UTC (rev 102366)
@@ -38,6 +38,7 @@
#include <wtf/RefPtr.h>
namespace WebCore {
+class InspectorDOMAgent;
class InspectorFrontend;
class InspectorState;
class InspectorArray;
@@ -51,18 +52,19 @@
public:
typedef Vector<OwnPtr<InspectorBaseAgentInterface> > InspectorAgents;
- static PassOwnPtr<InspectorMemoryAgent> create(InstrumentingAgents* instrumentingAgents, InspectorState* state, Page* page)
+ static PassOwnPtr<InspectorMemoryAgent> create(InstrumentingAgents* instrumentingAgents, InspectorState* state, Page* page, InspectorDOMAgent* domAgent)
{
- return adoptPtr(new InspectorMemoryAgent(instrumentingAgents, state, page));
+ return adoptPtr(new InspectorMemoryAgent(instrumentingAgents, state, page, domAgent));
}
- void getDOMNodeCount(ErrorString*, int* result);
+ void getDOMNodeCount(ErrorString*, RefPtr<InspectorArray>* result);
~InspectorMemoryAgent();
private:
- InspectorMemoryAgent(InstrumentingAgents*, InspectorState*, Page*);
+ InspectorMemoryAgent(InstrumentingAgents*, InspectorState*, Page*, InspectorDOMAgent* domAgent);
Page* m_page;
+ InspectorDOMAgent* m_domAgent;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/inspector/front-end/ConsoleView.js (102365 => 102366)
--- trunk/Source/WebCore/inspector/front-end/ConsoleView.js 2011-12-08 20:34:05 UTC (rev 102365)
+++ trunk/Source/WebCore/inspector/front-end/ConsoleView.js 2011-12-08 20:41:30 UTC (rev 102366)
@@ -528,6 +528,9 @@
var shortcutL = shortcut.makeDescriptor("l", WebInspector.KeyboardShortcut.Modifiers.Ctrl);
this._shortcuts[shortcutL.key] = this._requestClearMessages.bind(this);
+ var shortcutM = shortcut.makeDescriptor("m", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta | WebInspector.KeyboardShortcut.Modifiers.Shift);
+ this._shortcuts[shortcutM.key] = this._dumpMemory.bind(this);
+
var section = WebInspector.shortcutsScreen.section(WebInspector.UIString("Console"));
var keys = WebInspector.isMac() ? [ shortcutK.name, shortcutL.name ] : [ shortcutL.name ];
section.addAlternateKeys(keys, WebInspector.UIString("Clear Console"));
@@ -656,6 +659,44 @@
elementsToRestoreScrollPositionsFor: function()
{
return [this.messagesElement];
+ },
+
+ _dumpMemory: function()
+ {
+ function comparator(a, b)
+ {
+ if (a.size < b.size)
+ return 1;
+ if (a.size > b.size)
+ return -1;
+ return a.title.localeCompare(b.title);
+ }
+
+ function callback(error, groups)
+ {
+ var titles = [];
+ groups.sort(comparator);
+ for (var i = 0; i < groups.length; ++i) {
+ var suffix = groups[i].size > 0 ? " [" + groups[i].size + "]" : "";
+ titles.push(groups[i].title + suffix + (groups[i].documentURI ? " (" + groups[i].documentURI + ")" : ""));
+ }
+
+ var counter = 1;
+ var previousTitle = null;
+ for (var i = 0; i < titles.length; ++i) {
+ var title = titles[i];
+ if (title === previousTitle) {
+ counter++;
+ continue;
+ }
+ if (previousTitle)
+ WebInspector.log(counter > 1 ? counter + " x " + previousTitle : previousTitle);
+ previousTitle = title;
+ counter = 1;
+ }
+ WebInspector.log(counter > 1 ? counter + " x " + previousTitle : previousTitle);
+ }
+ MemoryAgent.getDOMNodeCount(callback);
}
}