| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/v8_inspector/V8HeapProfilerAgentImpl.h" | 5 #include "platform/v8_inspector/V8HeapProfilerAgentImpl.h" |
| 6 | 6 |
| 7 #include "platform/v8_inspector/InjectedScript.h" | 7 #include "platform/v8_inspector/InjectedScript.h" |
| 8 #include "platform/v8_inspector/V8DebuggerImpl.h" | 8 #include "platform/v8_inspector/V8DebuggerImpl.h" |
| 9 #include "platform/v8_inspector/V8InspectorSessionImpl.h" | 9 #include "platform/v8_inspector/V8InspectorSessionImpl.h" |
| 10 #include "platform/v8_inspector/V8StringUtil.h" | 10 #include "platform/v8_inspector/V8StringUtil.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 97 |
| 98 v8::Local<v8::Object> objectByHeapObjectId(v8::Isolate* isolate, int id) | 98 v8::Local<v8::Object> objectByHeapObjectId(v8::Isolate* isolate, int id) |
| 99 { | 99 { |
| 100 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); | 100 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); |
| 101 v8::Local<v8::Value> value = profiler->FindObjectById(id); | 101 v8::Local<v8::Value> value = profiler->FindObjectById(id); |
| 102 if (value.IsEmpty() || !value->IsObject()) | 102 if (value.IsEmpty() || !value->IsObject()) |
| 103 return v8::Local<v8::Object>(); | 103 return v8::Local<v8::Object>(); |
| 104 return value.As<v8::Object>(); | 104 return value.As<v8::Object>(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 class InspectableHeapObject final : public V8RuntimeAgent::Inspectable { | 107 class InspectableHeapObject final : public V8InspectorSession::Inspectable { |
| 108 public: | 108 public: |
| 109 explicit InspectableHeapObject(int heapObjectId) : m_heapObjectId(heapObject
Id) { } | 109 explicit InspectableHeapObject(int heapObjectId) : m_heapObjectId(heapObject
Id) { } |
| 110 v8::Local<v8::Value> get(v8::Local<v8::Context> context) override | 110 v8::Local<v8::Value> get(v8::Local<v8::Context> context) override |
| 111 { | 111 { |
| 112 return objectByHeapObjectId(context->GetIsolate(), m_heapObjectId); | 112 return objectByHeapObjectId(context->GetIsolate(), m_heapObjectId); |
| 113 } | 113 } |
| 114 private: | 114 private: |
| 115 int m_heapObjectId; | 115 int m_heapObjectId; |
| 116 }; | 116 }; |
| 117 | 117 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 if (heapObject.IsEmpty()) { | 259 if (heapObject.IsEmpty()) { |
| 260 *error = "Object is not available"; | 260 *error = "Object is not available"; |
| 261 return; | 261 return; |
| 262 } | 262 } |
| 263 | 263 |
| 264 if (!m_session->debugger()->client()->isInspectableHeapObject(heapObject)) { | 264 if (!m_session->debugger()->client()->isInspectableHeapObject(heapObject)) { |
| 265 *error = "Object is not available"; | 265 *error = "Object is not available"; |
| 266 return; | 266 return; |
| 267 } | 267 } |
| 268 | 268 |
| 269 *result = m_session->runtimeAgent()->wrapObject(heapObject->CreationContext(
), heapObject, objectGroup.fromMaybe("")); | 269 *result = m_session->wrapObject(heapObject->CreationContext(), heapObject, o
bjectGroup.fromMaybe("")); |
| 270 if (!result) | 270 if (!result) |
| 271 *error = "Object is not available"; | 271 *error = "Object is not available"; |
| 272 } | 272 } |
| 273 | 273 |
| 274 void V8HeapProfilerAgentImpl::addInspectedHeapObject(ErrorString* errorString, c
onst String16& inspectedHeapObjectId) | 274 void V8HeapProfilerAgentImpl::addInspectedHeapObject(ErrorString* errorString, c
onst String16& inspectedHeapObjectId) |
| 275 { | 275 { |
| 276 bool ok; | 276 bool ok; |
| 277 int id = inspectedHeapObjectId.toInt(&ok); | 277 int id = inspectedHeapObjectId.toInt(&ok); |
| 278 if (!ok) { | 278 if (!ok) { |
| 279 *errorString = "Invalid heap snapshot object id"; | 279 *errorString = "Invalid heap snapshot object id"; |
| 280 return; | 280 return; |
| 281 } | 281 } |
| 282 | 282 |
| 283 v8::HandleScope handles(m_isolate); | 283 v8::HandleScope handles(m_isolate); |
| 284 v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); | 284 v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); |
| 285 if (heapObject.IsEmpty()) { | 285 if (heapObject.IsEmpty()) { |
| 286 *errorString = "Object is not available"; | 286 *errorString = "Object is not available"; |
| 287 return; | 287 return; |
| 288 } | 288 } |
| 289 | 289 |
| 290 if (!m_session->debugger()->client()->isInspectableHeapObject(heapObject)) { | 290 if (!m_session->debugger()->client()->isInspectableHeapObject(heapObject)) { |
| 291 *errorString = "Object is not available"; | 291 *errorString = "Object is not available"; |
| 292 return; | 292 return; |
| 293 } | 293 } |
| 294 | 294 |
| 295 m_session->runtimeAgent()->addInspectedObject(adoptPtr(new InspectableHeapOb
ject(id))); | 295 m_session->addInspectedObject(adoptPtr(new InspectableHeapObject(id))); |
| 296 } | 296 } |
| 297 | 297 |
| 298 void V8HeapProfilerAgentImpl::getHeapObjectId(ErrorString* errorString, const St
ring16& objectId, String16* heapSnapshotObjectId) | 298 void V8HeapProfilerAgentImpl::getHeapObjectId(ErrorString* errorString, const St
ring16& objectId, String16* heapSnapshotObjectId) |
| 299 { | 299 { |
| 300 v8::HandleScope handles(m_isolate); | 300 v8::HandleScope handles(m_isolate); |
| 301 v8::Local<v8::Value> value = m_session->runtimeAgent()->findObject(errorStri
ng, objectId); | 301 v8::Local<v8::Value> value = m_session->findObject(errorString, objectId); |
| 302 if (value.IsEmpty() || value->IsUndefined()) | 302 if (value.IsEmpty() || value->IsUndefined()) |
| 303 return; | 303 return; |
| 304 | 304 |
| 305 v8::SnapshotObjectId id = m_isolate->GetHeapProfiler()->GetObjectId(value); | 305 v8::SnapshotObjectId id = m_isolate->GetHeapProfiler()->GetObjectId(value); |
| 306 *heapSnapshotObjectId = String16::number(id); | 306 *heapSnapshotObjectId = String16::number(id); |
| 307 } | 307 } |
| 308 | 308 |
| 309 void V8HeapProfilerAgentImpl::requestHeapStatsUpdate() | 309 void V8HeapProfilerAgentImpl::requestHeapStatsUpdate() |
| 310 { | 310 { |
| 311 if (!m_frontend) | 311 if (!m_frontend) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 *errorString = "Cannot access v8 sampled heap profile."; | 388 *errorString = "Cannot access v8 sampled heap profile."; |
| 389 return; | 389 return; |
| 390 } | 390 } |
| 391 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); | 391 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); |
| 392 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() | 392 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() |
| 393 .setHead(buildSampingHeapProfileNode(root)).build(); | 393 .setHead(buildSampingHeapProfileNode(root)).build(); |
| 394 #endif | 394 #endif |
| 395 } | 395 } |
| 396 | 396 |
| 397 } // namespace blink | 397 } // namespace blink |
| OLD | NEW |