| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project 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 "src/inspector/v8-heap-profiler-agent-impl.h" | 5 #include "src/inspector/v8-heap-profiler-agent-impl.h" |
| 6 | 6 |
| 7 #include "src/inspector/injected-script.h" | 7 #include "src/inspector/injected-script.h" |
| 8 #include "src/inspector/protocol/Protocol.h" | 8 #include "src/inspector/protocol/Protocol.h" |
| 9 #include "src/inspector/string-util.h" | 9 #include "src/inspector/string-util.h" |
| 10 #include "src/inspector/v8-debugger.h" | 10 #include "src/inspector/v8-debugger.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 m_isolate->GetHeapProfiler()->ClearObjectIds(); | 209 m_isolate->GetHeapProfiler()->ClearObjectIds(); |
| 210 m_state->setBoolean(HeapProfilerAgentState::heapProfilerEnabled, false); | 210 m_state->setBoolean(HeapProfilerAgentState::heapProfilerEnabled, false); |
| 211 return Response::OK(); | 211 return Response::OK(); |
| 212 } | 212 } |
| 213 | 213 |
| 214 Response V8HeapProfilerAgentImpl::takeHeapSnapshot(Maybe<bool> reportProgress) { | 214 Response V8HeapProfilerAgentImpl::takeHeapSnapshot(Maybe<bool> reportProgress) { |
| 215 v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); | 215 v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); |
| 216 if (!profiler) return Response::Error("Cannot access v8 heap profiler"); | 216 if (!profiler) return Response::Error("Cannot access v8 heap profiler"); |
| 217 std::unique_ptr<HeapSnapshotProgress> progress; | 217 std::unique_ptr<HeapSnapshotProgress> progress; |
| 218 if (reportProgress.fromMaybe(false)) | 218 if (reportProgress.fromMaybe(false)) |
| 219 progress = wrapUnique(new HeapSnapshotProgress(&m_frontend)); | 219 progress = std::unique_ptr<HeapSnapshotProgress>( |
| 220 new HeapSnapshotProgress(&m_frontend)); |
| 220 | 221 |
| 221 GlobalObjectNameResolver resolver(m_session); | 222 GlobalObjectNameResolver resolver(m_session); |
| 222 const v8::HeapSnapshot* snapshot = | 223 const v8::HeapSnapshot* snapshot = |
| 223 profiler->TakeHeapSnapshot(progress.get(), &resolver); | 224 profiler->TakeHeapSnapshot(progress.get(), &resolver); |
| 224 if (!snapshot) return Response::Error("Failed to take heap snapshot"); | 225 if (!snapshot) return Response::Error("Failed to take heap snapshot"); |
| 225 HeapSnapshotOutputStream stream(&m_frontend); | 226 HeapSnapshotOutputStream stream(&m_frontend); |
| 226 snapshot->Serialize(&stream); | 227 snapshot->Serialize(&stream); |
| 227 const_cast<v8::HeapSnapshot*>(snapshot)->Delete(); | 228 const_cast<v8::HeapSnapshot*>(snapshot)->Delete(); |
| 228 return Response::OK(); | 229 return Response::OK(); |
| 229 } | 230 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 253 bool ok; | 254 bool ok; |
| 254 int id = inspectedHeapObjectId.toInteger(&ok); | 255 int id = inspectedHeapObjectId.toInteger(&ok); |
| 255 if (!ok) return Response::Error("Invalid heap snapshot object id"); | 256 if (!ok) return Response::Error("Invalid heap snapshot object id"); |
| 256 | 257 |
| 257 v8::HandleScope handles(m_isolate); | 258 v8::HandleScope handles(m_isolate); |
| 258 v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); | 259 v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); |
| 259 if (heapObject.IsEmpty()) return Response::Error("Object is not available"); | 260 if (heapObject.IsEmpty()) return Response::Error("Object is not available"); |
| 260 | 261 |
| 261 if (!m_session->inspector()->client()->isInspectableHeapObject(heapObject)) | 262 if (!m_session->inspector()->client()->isInspectableHeapObject(heapObject)) |
| 262 return Response::Error("Object is not available"); | 263 return Response::Error("Object is not available"); |
| 263 m_session->addInspectedObject(wrapUnique(new InspectableHeapObject(id))); | 264 m_session->addInspectedObject( |
| 265 std::unique_ptr<InspectableHeapObject>(new InspectableHeapObject(id))); |
| 264 return Response::OK(); | 266 return Response::OK(); |
| 265 } | 267 } |
| 266 | 268 |
| 267 Response V8HeapProfilerAgentImpl::getHeapObjectId( | 269 Response V8HeapProfilerAgentImpl::getHeapObjectId( |
| 268 const String16& objectId, String16* heapSnapshotObjectId) { | 270 const String16& objectId, String16* heapSnapshotObjectId) { |
| 269 v8::HandleScope handles(m_isolate); | 271 v8::HandleScope handles(m_isolate); |
| 270 v8::Local<v8::Value> value; | 272 v8::Local<v8::Value> value; |
| 271 v8::Local<v8::Context> context; | 273 v8::Local<v8::Context> context; |
| 272 Response response = | 274 Response response = |
| 273 m_session->unwrapObject(objectId, &value, &context, nullptr); | 275 m_session->unwrapObject(objectId, &value, &context, nullptr); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 if (!v8Profile) | 375 if (!v8Profile) |
| 374 return Response::Error("Cannot access v8 sampled heap profile."); | 376 return Response::Error("Cannot access v8 sampled heap profile."); |
| 375 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); | 377 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); |
| 376 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() | 378 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() |
| 377 .setHead(buildSampingHeapProfileNode(root)) | 379 .setHead(buildSampingHeapProfileNode(root)) |
| 378 .build(); | 380 .build(); |
| 379 return Response::OK(); | 381 return Response::OK(); |
| 380 } | 382 } |
| 381 | 383 |
| 382 } // namespace v8_inspector | 384 } // namespace v8_inspector |
| OLD | NEW |