Commit 39020433 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[inspector] migrate HeapProfiler to new style

BUG=none
R=dgozman@chromium.org

Review-Url: https://codereview.chromium.org/2474483003
Cr-Commit-Position: refs/heads/master@{#40689}
parent 8c08d423
...@@ -164,39 +164,42 @@ void V8HeapProfilerAgentImpl::restore() { ...@@ -164,39 +164,42 @@ void V8HeapProfilerAgentImpl::restore() {
HeapProfilerAgentState::allocationTrackingEnabled, false)); HeapProfilerAgentState::allocationTrackingEnabled, false));
if (m_state->booleanProperty( if (m_state->booleanProperty(
HeapProfilerAgentState::samplingHeapProfilerEnabled, false)) { HeapProfilerAgentState::samplingHeapProfilerEnabled, false)) {
ErrorString error;
double samplingInterval = m_state->doubleProperty( double samplingInterval = m_state->doubleProperty(
HeapProfilerAgentState::samplingHeapProfilerInterval, -1); HeapProfilerAgentState::samplingHeapProfilerInterval, -1);
DCHECK_GE(samplingInterval, 0); DCHECK_GE(samplingInterval, 0);
startSampling(&error, Maybe<double>(samplingInterval)); startSampling(Maybe<double>(samplingInterval));
} }
} }
void V8HeapProfilerAgentImpl::collectGarbage(ErrorString*) { Response V8HeapProfilerAgentImpl::collectGarbage() {
m_isolate->LowMemoryNotification(); m_isolate->LowMemoryNotification();
return Response::OK();
} }
void V8HeapProfilerAgentImpl::startTrackingHeapObjects( Response V8HeapProfilerAgentImpl::startTrackingHeapObjects(
ErrorString*, const protocol::Maybe<bool>& trackAllocations) { Maybe<bool> trackAllocations) {
m_state->setBoolean(HeapProfilerAgentState::heapObjectsTrackingEnabled, true); m_state->setBoolean(HeapProfilerAgentState::heapObjectsTrackingEnabled, true);
bool allocationTrackingEnabled = trackAllocations.fromMaybe(false); bool allocationTrackingEnabled = trackAllocations.fromMaybe(false);
m_state->setBoolean(HeapProfilerAgentState::allocationTrackingEnabled, m_state->setBoolean(HeapProfilerAgentState::allocationTrackingEnabled,
allocationTrackingEnabled); allocationTrackingEnabled);
startTrackingHeapObjectsInternal(allocationTrackingEnabled); startTrackingHeapObjectsInternal(allocationTrackingEnabled);
return Response::OK();
} }
void V8HeapProfilerAgentImpl::stopTrackingHeapObjects( Response V8HeapProfilerAgentImpl::stopTrackingHeapObjects(
ErrorString* error, const protocol::Maybe<bool>& reportProgress) { Maybe<bool> reportProgress) {
requestHeapStatsUpdate(); requestHeapStatsUpdate();
takeHeapSnapshot(error, reportProgress); takeHeapSnapshot(std::move(reportProgress));
stopTrackingHeapObjectsInternal(); stopTrackingHeapObjectsInternal();
return Response::OK();
} }
void V8HeapProfilerAgentImpl::enable(ErrorString*) { Response V8HeapProfilerAgentImpl::enable() {
m_state->setBoolean(HeapProfilerAgentState::heapProfilerEnabled, true); m_state->setBoolean(HeapProfilerAgentState::heapProfilerEnabled, true);
return Response::OK();
} }
void V8HeapProfilerAgentImpl::disable(ErrorString* error) { Response V8HeapProfilerAgentImpl::disable() {
stopTrackingHeapObjectsInternal(); stopTrackingHeapObjectsInternal();
if (m_state->booleanProperty( if (m_state->booleanProperty(
HeapProfilerAgentState::samplingHeapProfilerEnabled, false)) { HeapProfilerAgentState::samplingHeapProfilerEnabled, false)) {
...@@ -205,15 +208,12 @@ void V8HeapProfilerAgentImpl::disable(ErrorString* error) { ...@@ -205,15 +208,12 @@ void V8HeapProfilerAgentImpl::disable(ErrorString* error) {
} }
m_isolate->GetHeapProfiler()->ClearObjectIds(); m_isolate->GetHeapProfiler()->ClearObjectIds();
m_state->setBoolean(HeapProfilerAgentState::heapProfilerEnabled, false); m_state->setBoolean(HeapProfilerAgentState::heapProfilerEnabled, false);
return Response::OK();
} }
void V8HeapProfilerAgentImpl::takeHeapSnapshot( Response V8HeapProfilerAgentImpl::takeHeapSnapshot(Maybe<bool> reportProgress) {
ErrorString* errorString, const protocol::Maybe<bool>& reportProgress) {
v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler();
if (!profiler) { if (!profiler) return Response::Error("Cannot access v8 heap profiler");
*errorString = "Cannot access v8 heap profiler";
return;
}
std::unique_ptr<HeapSnapshotProgress> progress; std::unique_ptr<HeapSnapshotProgress> progress;
if (reportProgress.fromMaybe(false)) if (reportProgress.fromMaybe(false))
progress = wrapUnique(new HeapSnapshotProgress(&m_frontend)); progress = wrapUnique(new HeapSnapshotProgress(&m_frontend));
...@@ -221,80 +221,63 @@ void V8HeapProfilerAgentImpl::takeHeapSnapshot( ...@@ -221,80 +221,63 @@ void V8HeapProfilerAgentImpl::takeHeapSnapshot(
GlobalObjectNameResolver resolver(m_session); GlobalObjectNameResolver resolver(m_session);
const v8::HeapSnapshot* snapshot = const v8::HeapSnapshot* snapshot =
profiler->TakeHeapSnapshot(progress.get(), &resolver); profiler->TakeHeapSnapshot(progress.get(), &resolver);
if (!snapshot) { if (!snapshot) return Response::Error("Failed to take heap snapshot");
*errorString = "Failed to take heap snapshot";
return;
}
HeapSnapshotOutputStream stream(&m_frontend); HeapSnapshotOutputStream stream(&m_frontend);
snapshot->Serialize(&stream); snapshot->Serialize(&stream);
const_cast<v8::HeapSnapshot*>(snapshot)->Delete(); const_cast<v8::HeapSnapshot*>(snapshot)->Delete();
return Response::OK();
} }
void V8HeapProfilerAgentImpl::getObjectByHeapObjectId( Response V8HeapProfilerAgentImpl::getObjectByHeapObjectId(
ErrorString* error, const String16& heapSnapshotObjectId, const String16& heapSnapshotObjectId, Maybe<String16> objectGroup,
const protocol::Maybe<String16>& objectGroup,
std::unique_ptr<protocol::Runtime::RemoteObject>* result) { std::unique_ptr<protocol::Runtime::RemoteObject>* result) {
bool ok; bool ok;
int id = heapSnapshotObjectId.toInteger(&ok); int id = heapSnapshotObjectId.toInteger(&ok);
if (!ok) { if (!ok) return Response::Error("Invalid heap snapshot object id");
*error = "Invalid heap snapshot object id";
return;
}
v8::HandleScope handles(m_isolate); v8::HandleScope handles(m_isolate);
v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id);
if (heapObject.IsEmpty()) { if (heapObject.IsEmpty()) return Response::Error("Object is not available");
*error = "Object is not available";
return;
}
if (!m_session->inspector()->client()->isInspectableHeapObject(heapObject)) { if (!m_session->inspector()->client()->isInspectableHeapObject(heapObject))
*error = "Object is not available"; return Response::Error("Object is not available");
return;
}
*result = m_session->wrapObject(heapObject->CreationContext(), heapObject, *result = m_session->wrapObject(heapObject->CreationContext(), heapObject,
objectGroup.fromMaybe(""), false); objectGroup.fromMaybe(""), false);
if (!result) *error = "Object is not available"; if (!result) return Response::Error("Object is not available");
return Response::OK();
} }
void V8HeapProfilerAgentImpl::addInspectedHeapObject( Response V8HeapProfilerAgentImpl::addInspectedHeapObject(
ErrorString* errorString, const String16& inspectedHeapObjectId) { const String16& inspectedHeapObjectId) {
bool ok; bool ok;
int id = inspectedHeapObjectId.toInteger(&ok); int id = inspectedHeapObjectId.toInteger(&ok);
if (!ok) { if (!ok) return Response::Error("Invalid heap snapshot object id");
*errorString = "Invalid heap snapshot object id";
return;
}
v8::HandleScope handles(m_isolate); v8::HandleScope handles(m_isolate);
v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id);
if (heapObject.IsEmpty()) { if (heapObject.IsEmpty()) return Response::Error("Object is not available");
*errorString = "Object is not available";
return;
}
if (!m_session->inspector()->client()->isInspectableHeapObject(heapObject)) {
*errorString = "Object is not available";
return;
}
if (!m_session->inspector()->client()->isInspectableHeapObject(heapObject))
return Response::Error("Object is not available");
m_session->addInspectedObject(wrapUnique(new InspectableHeapObject(id))); m_session->addInspectedObject(wrapUnique(new InspectableHeapObject(id)));
return Response::OK();
} }
void V8HeapProfilerAgentImpl::getHeapObjectId(ErrorString* errorString, Response V8HeapProfilerAgentImpl::getHeapObjectId(
const String16& objectId, const String16& objectId, String16* heapSnapshotObjectId) {
String16* heapSnapshotObjectId) {
v8::HandleScope handles(m_isolate); v8::HandleScope handles(m_isolate);
v8::Local<v8::Value> value; v8::Local<v8::Value> value;
v8::Local<v8::Context> context; v8::Local<v8::Context> context;
if (!m_session->unwrapObject(errorString, objectId, &value, &context, protocol::ErrorString errorString;
if (!m_session->unwrapObject(&errorString, objectId, &value, &context,
nullptr) || nullptr) ||
value->IsUndefined()) value->IsUndefined())
return; return Response::Error(errorString);
v8::SnapshotObjectId id = m_isolate->GetHeapProfiler()->GetObjectId(value); v8::SnapshotObjectId id = m_isolate->GetHeapProfiler()->GetObjectId(value);
*heapSnapshotObjectId = String16::fromInteger(static_cast<size_t>(id)); *heapSnapshotObjectId = String16::fromInteger(static_cast<size_t>(id));
return Response::OK();
} }
void V8HeapProfilerAgentImpl::requestHeapStatsUpdate() { void V8HeapProfilerAgentImpl::requestHeapStatsUpdate() {
...@@ -332,13 +315,10 @@ void V8HeapProfilerAgentImpl::stopTrackingHeapObjectsInternal() { ...@@ -332,13 +315,10 @@ void V8HeapProfilerAgentImpl::stopTrackingHeapObjectsInternal() {
m_state->setBoolean(HeapProfilerAgentState::allocationTrackingEnabled, false); m_state->setBoolean(HeapProfilerAgentState::allocationTrackingEnabled, false);
} }
void V8HeapProfilerAgentImpl::startSampling( Response V8HeapProfilerAgentImpl::startSampling(
ErrorString* errorString, const Maybe<double>& samplingInterval) { Maybe<double> samplingInterval) {
v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler();
if (!profiler) { if (!profiler) return Response::Error("Cannot access v8 heap profiler");
*errorString = "Cannot access v8 heap profiler";
return;
}
const unsigned defaultSamplingInterval = 1 << 15; const unsigned defaultSamplingInterval = 1 << 15;
double samplingIntervalValue = double samplingIntervalValue =
samplingInterval.fromMaybe(defaultSamplingInterval); samplingInterval.fromMaybe(defaultSamplingInterval);
...@@ -349,6 +329,7 @@ void V8HeapProfilerAgentImpl::startSampling( ...@@ -349,6 +329,7 @@ void V8HeapProfilerAgentImpl::startSampling(
profiler->StartSamplingHeapProfiler( profiler->StartSamplingHeapProfiler(
static_cast<uint64_t>(samplingIntervalValue), 128, static_cast<uint64_t>(samplingIntervalValue), 128,
v8::HeapProfiler::kSamplingForceGC); v8::HeapProfiler::kSamplingForceGC);
return Response::OK();
} }
namespace { namespace {
...@@ -379,14 +360,10 @@ buildSampingHeapProfileNode(const v8::AllocationProfile::Node* node) { ...@@ -379,14 +360,10 @@ buildSampingHeapProfileNode(const v8::AllocationProfile::Node* node) {
} }
} // namespace } // namespace
void V8HeapProfilerAgentImpl::stopSampling( Response V8HeapProfilerAgentImpl::stopSampling(
ErrorString* errorString,
std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfile>* profile) { std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfile>* profile) {
v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler();
if (!profiler) { if (!profiler) return Response::Error("Cannot access v8 heap profiler");
*errorString = "Cannot access v8 heap profiler";
return;
}
v8::HandleScope scope( v8::HandleScope scope(
m_isolate); // Allocation profile contains Local handles. m_isolate); // Allocation profile contains Local handles.
std::unique_ptr<v8::AllocationProfile> v8Profile( std::unique_ptr<v8::AllocationProfile> v8Profile(
...@@ -394,14 +371,13 @@ void V8HeapProfilerAgentImpl::stopSampling( ...@@ -394,14 +371,13 @@ void V8HeapProfilerAgentImpl::stopSampling(
profiler->StopSamplingHeapProfiler(); profiler->StopSamplingHeapProfiler();
m_state->setBoolean(HeapProfilerAgentState::samplingHeapProfilerEnabled, m_state->setBoolean(HeapProfilerAgentState::samplingHeapProfilerEnabled,
false); false);
if (!v8Profile) { if (!v8Profile)
*errorString = "Cannot access v8 sampled heap profile."; return Response::Error("Cannot access v8 sampled heap profile.");
return;
}
v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); v8::AllocationProfile::Node* root = v8Profile->GetRootNode();
*profile = protocol::HeapProfiler::SamplingHeapProfile::create() *profile = protocol::HeapProfiler::SamplingHeapProfile::create()
.setHead(buildSampingHeapProfileNode(root)) .setHead(buildSampingHeapProfileNode(root))
.build(); .build();
return Response::OK();
} }
} // namespace v8_inspector } // namespace v8_inspector
...@@ -15,8 +15,8 @@ namespace v8_inspector { ...@@ -15,8 +15,8 @@ namespace v8_inspector {
class V8InspectorSessionImpl; class V8InspectorSessionImpl;
using protocol::ErrorString;
using protocol::Maybe; using protocol::Maybe;
using protocol::Response;
class V8HeapProfilerAgentImpl : public protocol::HeapProfiler::Backend { class V8HeapProfilerAgentImpl : public protocol::HeapProfiler::Backend {
public: public:
...@@ -25,32 +25,26 @@ class V8HeapProfilerAgentImpl : public protocol::HeapProfiler::Backend { ...@@ -25,32 +25,26 @@ class V8HeapProfilerAgentImpl : public protocol::HeapProfiler::Backend {
~V8HeapProfilerAgentImpl() override; ~V8HeapProfilerAgentImpl() override;
void restore(); void restore();
void collectGarbage(ErrorString*) override; Response collectGarbage() override;
void enable(ErrorString*) override; Response enable() override;
void startTrackingHeapObjects(ErrorString*, Response startTrackingHeapObjects(Maybe<bool> trackAllocations) override;
const Maybe<bool>& trackAllocations) override; Response stopTrackingHeapObjects(Maybe<bool> reportProgress) override;
void stopTrackingHeapObjects(ErrorString*,
const Maybe<bool>& reportProgress) override;
void disable(ErrorString*) override; Response disable() override;
void takeHeapSnapshot(ErrorString*, Response takeHeapSnapshot(Maybe<bool> reportProgress) override;
const Maybe<bool>& reportProgress) override;
void getObjectByHeapObjectId( Response getObjectByHeapObjectId(
ErrorString*, const String16& heapSnapshotObjectId, const String16& heapSnapshotObjectId, Maybe<String16> objectGroup,
const Maybe<String16>& objectGroup,
std::unique_ptr<protocol::Runtime::RemoteObject>* result) override; std::unique_ptr<protocol::Runtime::RemoteObject>* result) override;
void addInspectedHeapObject(ErrorString*, Response addInspectedHeapObject(
const String16& inspectedHeapObjectId) override; const String16& inspectedHeapObjectId) override;
void getHeapObjectId(ErrorString*, const String16& objectId, Response getHeapObjectId(const String16& objectId,
String16* heapSnapshotObjectId) override; String16* heapSnapshotObjectId) override;
void startSampling(ErrorString*, Response startSampling(Maybe<double> samplingInterval) override;
const Maybe<double>& samplingInterval) override; Response stopSampling(
void stopSampling(
ErrorString*,
std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfile>*) override; std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfile>*) override;
private: private:
......
...@@ -107,7 +107,7 @@ V8InspectorSessionImpl::~V8InspectorSessionImpl() { ...@@ -107,7 +107,7 @@ V8InspectorSessionImpl::~V8InspectorSessionImpl() {
ErrorString errorString; ErrorString errorString;
m_consoleAgent->disable(); m_consoleAgent->disable();
m_profilerAgent->disable(); m_profilerAgent->disable();
m_heapProfilerAgent->disable(&errorString); m_heapProfilerAgent->disable();
m_debuggerAgent->disable(&errorString); m_debuggerAgent->disable(&errorString);
m_runtimeAgent->disable(&errorString); m_runtimeAgent->disable(&errorString);
......
...@@ -330,7 +330,7 @@ def resolve_type(protocol, prop): ...@@ -330,7 +330,7 @@ def resolve_type(protocol, prop):
def new_style(domain): def new_style(domain):
domains = [ "Schema", "Console", "Profiler" ] domains = [ "Schema", "Console", "Profiler", "HeapProfiler" ]
return domain["domain"] in domains return domain["domain"] in domains
......
...@@ -14,5 +14,5 @@ description. ...@@ -14,5 +14,5 @@ description.
Local modifications: Local modifications:
- This only includes the lib/ and templates/ directories, scripts, build - This only includes the lib/ and templates/ directories, scripts, build
and the LICENSE files. and the LICENSE files.
- New style domains [ "Schema", "Console", "Profiler" ] are added in - New style domains [ "Schema", "Console", "Profiler", "HeapProfiler" ] are
CodeGenerator.py. added in CodeGenerator.py.
\ No newline at end of file \ No newline at end of file
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