Commit 503c0f87 authored by yurys@chromium.org's avatar yurys@chromium.org

Web Inspector: add Profiler.getHeapObjectId command

https://bugs.webkit.org/show_bug.cgi?id=86211

Reviewed by Pavel Feldman.

Added Profiler.getHeapObjectId command to the protocol which allows to convert remote
object id to heap snapshot object id.

* bindings/js/ScriptProfiler.cpp:
(WebCore::ScriptProfiler::getHeapObjectId):
(WebCore):
* bindings/js/ScriptProfiler.h:
(WebCore):
(ScriptProfiler):
* bindings/v8/ScriptProfiler.cpp:
(WebCore::ScriptProfiler::getHeapObjectId):
(WebCore):
* bindings/v8/ScriptProfiler.h:
(WebCore):
(ScriptProfiler):
* inspector/InjectedScript.cpp:
(WebCore::InjectedScript::findObjectById):
(WebCore):
* inspector/InjectedScript.h:
(InjectedScript):
* inspector/InjectedScriptSource.js:
(.):
* inspector/Inspector.json:
* inspector/InspectorProfilerAgent.cpp:
(WebCore::InspectorProfilerAgent::getHeapObjectId):
(WebCore):
* inspector/InspectorProfilerAgent.h:
(InspectorProfilerAgent):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@116768 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 4767431b
2012-05-11 Yury Semikhatsky <yurys@chromium.org>
Web Inspector: add Profiler.getHeapObjectId command
https://bugs.webkit.org/show_bug.cgi?id=86211
Reviewed by Pavel Feldman.
Added Profiler.getHeapObjectId command to the protocol which allows to convert remote
object id to heap snapshot object id.
* bindings/js/ScriptProfiler.cpp:
(WebCore::ScriptProfiler::getHeapObjectId):
(WebCore):
* bindings/js/ScriptProfiler.h:
(WebCore):
(ScriptProfiler):
* bindings/v8/ScriptProfiler.cpp:
(WebCore::ScriptProfiler::getHeapObjectId):
(WebCore):
* bindings/v8/ScriptProfiler.h:
(WebCore):
(ScriptProfiler):
* inspector/InjectedScript.cpp:
(WebCore::InjectedScript::findObjectById):
(WebCore):
* inspector/InjectedScript.h:
(InjectedScript):
* inspector/InjectedScriptSource.js:
(.):
* inspector/Inspector.json:
* inspector/InspectorProfilerAgent.cpp:
(WebCore::InspectorProfilerAgent::getHeapObjectId):
(WebCore):
* inspector/InspectorProfilerAgent.h:
(InspectorProfilerAgent):
2012-05-11 Allan Sandfeld Jensen <allan.jensen@nokia.com>
Qt support for new layout types.
......@@ -51,6 +51,11 @@ ScriptObject ScriptProfiler::objectByHeapObjectId(unsigned)
return ScriptObject();
}
unsigned ScriptProfiler::getHeapObjectId(ScriptValue)
{
return 0;
}
void ScriptProfiler::start(ScriptState* state, const String& title)
{
JSC::Profiler::profiler()->startProfiling(state, stringToUString(title));
......
......@@ -39,6 +39,7 @@ namespace WebCore {
class DOMWrapperVisitor;
class Page;
class ScriptObject;
class ScriptValue;
class WorkerContext;
class ScriptProfiler {
......@@ -55,6 +56,7 @@ public:
static void collectGarbage();
static ScriptObject objectByHeapObjectId(unsigned id);
static unsigned getHeapObjectId(ScriptValue);
static void start(ScriptState* state, const String& title);
static void startForPage(Page*, const String& title);
#if ENABLE(WORKERS)
......
......@@ -121,6 +121,12 @@ ScriptObject ScriptProfiler::objectByHeapObjectId(unsigned id)
return ScriptObject(scriptState, object);
}
unsigned ScriptProfiler::getHeapObjectId(ScriptValue value)
{
v8::SnapshotObjectId id = v8::HeapProfiler::GetSnapshotObjectId(value.v8Value());
return id;
}
namespace {
class ActivityControlAdapter : public v8::ActivityControl {
......
......@@ -43,6 +43,7 @@ namespace WebCore {
class DOMWrapperVisitor;
class Page;
class ScriptObject;
class ScriptValue;
class WorkerContext;
class ScriptProfiler {
......@@ -59,6 +60,7 @@ public:
static void collectGarbage();
static ScriptObject objectByHeapObjectId(unsigned id);
static unsigned getHeapObjectId(ScriptValue);
static void start(ScriptState* state, const String& title);
static void startForPage(Page*, const String& title);
#if ENABLE(WORKERS)
......
......@@ -190,6 +190,18 @@ PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapSerializedObj
return scriptValue.hasNoValue() ? 0 : wrapObject(scriptValue, groupName);
}
ScriptValue InjectedScript::findObjectById(const String& objectId) const
{
ASSERT(!hasNoValue());
ScriptFunctionCall function(m_injectedScriptObject, "findObjectById");
function.appendArgument(objectId);
bool hadException = false;
ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException);
ASSERT(!hadException);
return resultValue;
}
void InjectedScript::inspectNode(Node* node)
{
ASSERT(!hasNoValue());
......
......@@ -93,6 +93,8 @@ public:
PassRefPtr<TypeBuilder::Runtime::RemoteObject> wrapObject(ScriptValue, const String& groupName) const;
PassRefPtr<TypeBuilder::Runtime::RemoteObject> wrapNode(Node*, const String& groupName);
PassRefPtr<TypeBuilder::Runtime::RemoteObject> wrapSerializedObject(SerializedScriptValue*, const String& groupName) const;
ScriptValue findObjectById(const String& objectId) const;
void inspectNode(Node*);
void releaseObjectGroup(const String&);
ScriptState* scriptState() const { return m_injectedScriptObject.scriptState(); }
......
......@@ -384,10 +384,15 @@ InjectedScript.prototype = {
return this._idToWrappedObject[objectId.id];
},
nodeForObjectId: function(objectId)
findObjectById: function(objectId)
{
var parsedObjectId = this._parseObjectId(objectId);
var object = this._objectForId(parsedObjectId);
return this._objectForId(parsedObjectId);
},
nodeForObjectId: function(objectId)
{
var object = this.findObjectById(objectId);
if (!object || this._subtype(object) !== "node")
return null;
return object;
......
......@@ -2596,6 +2596,11 @@
{ "name": "head", "type": "object", "optional": true },
{ "name": "bottomUpHead", "type": "object", "optional": true }
]
},
{
"id": "HeapSnapshotObjectId",
"type": "string",
"description": "Heap snashot object id."
}
],
"commands": [
......@@ -2664,12 +2669,21 @@
{
"name": "getObjectByHeapObjectId",
"parameters": [
{ "name": "objectId", "type": "integer" },
{ "name": "objectId", "$ref": "HeapSnapshotObjectId" },
{ "name": "objectGroup", "type": "string", "optional": true, "description": "Symbolic group name that can be used to release multiple objects." }
],
"returns": [
{ "name": "result", "$ref": "Runtime.RemoteObject", "description": "Evaluation result." }
]
},
{
"name": "getHeapObjectId",
"parameters": [
{ "name": "objectId", "$ref": "Runtime.RemoteObjectId", "description": "Identifier of the object to get heap object id for." }
],
"returns": [
{ "name": "heapSnapshotObjectId", "$ref": "HeapSnapshotObjectId", "description": "Id of the heap snapshot object corresponding to the passed remote object id." }
]
}
],
"events": [
......
......@@ -428,8 +428,14 @@ void InspectorProfilerAgent::toggleRecordButton(bool isProfiling)
m_frontend->setRecordingProfile(isProfiling);
}
void InspectorProfilerAgent::getObjectByHeapObjectId(ErrorString* error, int id, const String* objectGroup, RefPtr<TypeBuilder::Runtime::RemoteObject>& result)
void InspectorProfilerAgent::getObjectByHeapObjectId(ErrorString* error, const String& heapSnapshotObjectId, const String* objectGroup, RefPtr<TypeBuilder::Runtime::RemoteObject>& result)
{
bool ok;
unsigned id = heapSnapshotObjectId.toUInt(&ok);
if (!ok) {
*error = "Invalid heap snapshot object id";
return;
}
ScriptObject heapObject = ScriptProfiler::objectByHeapObjectId(id);
if (heapObject.hasNoValue()) {
*error = "Object is not available";
......@@ -445,6 +451,22 @@ void InspectorProfilerAgent::getObjectByHeapObjectId(ErrorString* error, int id,
*error = "Failed to wrap object";
}
void InspectorProfilerAgent::getHeapObjectId(ErrorString* errorString, const String& objectId, String* heapSnapshotObjectId)
{
InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForObjectId(objectId);
if (injectedScript.hasNoValue()) {
*errorString = "Inspected context has gone";
return;
}
ScriptValue value = injectedScript.findObjectById(objectId);
if (value.hasNoValue() || value.isUndefined()) {
*errorString = "Object with given id not found";
return;
}
unsigned id = ScriptProfiler::getHeapObjectId(value);
*heapSnapshotObjectId = String::number(id);
}
} // namespace WebCore
#endif // ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
......@@ -96,7 +96,8 @@ public:
virtual void takeHeapSnapshot(ErrorString*);
void toggleRecordButton(bool isProfiling);
virtual void getObjectByHeapObjectId(ErrorString*, int id, const String* objectGroup, RefPtr<TypeBuilder::Runtime::RemoteObject>& result);
virtual void getObjectByHeapObjectId(ErrorString*, const String& heapSnapshotObjectId, const String* objectGroup, RefPtr<TypeBuilder::Runtime::RemoteObject>& result);
virtual void getHeapObjectId(ErrorString*, const String& objectId, String* heapSnapshotObjectId);
protected:
InspectorProfilerAgent(InstrumentingAgents*, InspectorConsoleAgent*, InspectorState*, InjectedScriptManager*);
......
......@@ -339,7 +339,7 @@ WebInspector.HeapSnapshotGenericObjectNode.prototype = {
else
callback(WebInspector.RemoteObject.fromPrimitiveValue(WebInspector.UIString("Not available")));
}
ProfilerAgent.getObjectByHeapObjectId(this.snapshotNodeId, objectGroupName, formatResult);
ProfilerAgent.getObjectByHeapObjectId(String(this.snapshotNodeId), objectGroupName, formatResult);
}
},
......
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