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.reset(new HeapSnapshotProgress(&m_frontend)); |
220 | 220 |
221 GlobalObjectNameResolver resolver(m_session); | 221 GlobalObjectNameResolver resolver(m_session); |
222 const v8::HeapSnapshot* snapshot = | 222 const v8::HeapSnapshot* snapshot = |
223 profiler->TakeHeapSnapshot(progress.get(), &resolver); | 223 profiler->TakeHeapSnapshot(progress.get(), &resolver); |
224 if (!snapshot) return Response::Error("Failed to take heap snapshot"); | 224 if (!snapshot) return Response::Error("Failed to take heap snapshot"); |
225 HeapSnapshotOutputStream stream(&m_frontend); | 225 HeapSnapshotOutputStream stream(&m_frontend); |
226 snapshot->Serialize(&stream); | 226 snapshot->Serialize(&stream); |
227 const_cast<v8::HeapSnapshot*>(snapshot)->Delete(); | 227 const_cast<v8::HeapSnapshot*>(snapshot)->Delete(); |
228 return Response::OK(); | 228 return Response::OK(); |
229 } | 229 } |
(...skipping 23 matching lines...) Expand all Loading... |
253 bool ok; | 253 bool ok; |
254 int id = inspectedHeapObjectId.toInteger(&ok); | 254 int id = inspectedHeapObjectId.toInteger(&ok); |
255 if (!ok) return Response::Error("Invalid heap snapshot object id"); | 255 if (!ok) return Response::Error("Invalid heap snapshot object id"); |
256 | 256 |
257 v8::HandleScope handles(m_isolate); | 257 v8::HandleScope handles(m_isolate); |
258 v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); | 258 v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); |
259 if (heapObject.IsEmpty()) return Response::Error("Object is not available"); | 259 if (heapObject.IsEmpty()) return Response::Error("Object is not available"); |
260 | 260 |
261 if (!m_session->inspector()->client()->isInspectableHeapObject(heapObject)) | 261 if (!m_session->inspector()->client()->isInspectableHeapObject(heapObject)) |
262 return Response::Error("Object is not available"); | 262 return Response::Error("Object is not available"); |
263 m_session->addInspectedObject(wrapUnique(new InspectableHeapObject(id))); | 263 m_session->addInspectedObject( |
| 264 std::unique_ptr<InspectableHeapObject>(new InspectableHeapObject(id))); |
264 return Response::OK(); | 265 return Response::OK(); |
265 } | 266 } |
266 | 267 |
267 Response V8HeapProfilerAgentImpl::getHeapObjectId( | 268 Response V8HeapProfilerAgentImpl::getHeapObjectId( |
268 const String16& objectId, String16* heapSnapshotObjectId) { | 269 const String16& objectId, String16* heapSnapshotObjectId) { |
269 v8::HandleScope handles(m_isolate); | 270 v8::HandleScope handles(m_isolate); |
270 v8::Local<v8::Value> value; | 271 v8::Local<v8::Value> value; |
271 v8::Local<v8::Context> context; | 272 v8::Local<v8::Context> context; |
272 Response response = | 273 Response response = |
273 m_session->unwrapObject(objectId, &value, &context, nullptr); | 274 m_session->unwrapObject(objectId, &value, &context, nullptr); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 if (!v8Profile) | 374 if (!v8Profile) |
374 return Response::Error("Cannot access v8 sampled heap profile."); | 375 return Response::Error("Cannot access v8 sampled heap profile."); |
375 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); | 376 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); |
376 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() | 377 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() |
377 .setHead(buildSampingHeapProfileNode(root)) | 378 .setHead(buildSampingHeapProfileNode(root)) |
378 .build(); | 379 .build(); |
379 return Response::OK(); | 380 return Response::OK(); |
380 } | 381 } |
381 | 382 |
382 } // namespace v8_inspector | 383 } // namespace v8_inspector |
OLD | NEW |