| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 126 |
| 127 WriteResult WriteAsciiChunk(char* data, int size) override | 127 WriteResult WriteAsciiChunk(char* data, int size) override |
| 128 { | 128 { |
| 129 DCHECK(false); | 129 DCHECK(false); |
| 130 return kAbort; | 130 return kAbort; |
| 131 } | 131 } |
| 132 | 132 |
| 133 WriteResult WriteHeapStatsChunk(v8::HeapStatsUpdate* updateData, int count)
override | 133 WriteResult WriteHeapStatsChunk(v8::HeapStatsUpdate* updateData, int count)
override |
| 134 { | 134 { |
| 135 DCHECK_GT(count, 0); | 135 DCHECK_GT(count, 0); |
| 136 OwnPtr<protocol::Array<int>> statsDiff = protocol::Array<int>::create(); | 136 std::unique_ptr<protocol::Array<int>> statsDiff = protocol::Array<int>::
create(); |
| 137 for (int i = 0; i < count; ++i) { | 137 for (int i = 0; i < count; ++i) { |
| 138 statsDiff->addItem(updateData[i].index); | 138 statsDiff->addItem(updateData[i].index); |
| 139 statsDiff->addItem(updateData[i].count); | 139 statsDiff->addItem(updateData[i].count); |
| 140 statsDiff->addItem(updateData[i].size); | 140 statsDiff->addItem(updateData[i].size); |
| 141 } | 141 } |
| 142 m_frontend->heapStatsUpdate(std::move(statsDiff)); | 142 m_frontend->heapStatsUpdate(std::move(statsDiff)); |
| 143 return kContinue; | 143 return kContinue; |
| 144 } | 144 } |
| 145 | 145 |
| 146 private: | 146 private: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 m_state->setBoolean(HeapProfilerAgentState::heapProfilerEnabled, false); | 217 m_state->setBoolean(HeapProfilerAgentState::heapProfilerEnabled, false); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void V8HeapProfilerAgentImpl::takeHeapSnapshot(ErrorString* errorString, const p
rotocol::Maybe<bool>& reportProgress) | 220 void V8HeapProfilerAgentImpl::takeHeapSnapshot(ErrorString* errorString, const p
rotocol::Maybe<bool>& reportProgress) |
| 221 { | 221 { |
| 222 v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); | 222 v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); |
| 223 if (!profiler) { | 223 if (!profiler) { |
| 224 *errorString = "Cannot access v8 heap profiler"; | 224 *errorString = "Cannot access v8 heap profiler"; |
| 225 return; | 225 return; |
| 226 } | 226 } |
| 227 OwnPtr<HeapSnapshotProgress> progress; | 227 std::unique_ptr<HeapSnapshotProgress> progress; |
| 228 if (reportProgress.fromMaybe(false)) | 228 if (reportProgress.fromMaybe(false)) |
| 229 progress = adoptPtr(new HeapSnapshotProgress(m_frontend)); | 229 progress = wrapUnique(new HeapSnapshotProgress(m_frontend)); |
| 230 | 230 |
| 231 GlobalObjectNameResolver resolver(m_session); | 231 GlobalObjectNameResolver resolver(m_session); |
| 232 const v8::HeapSnapshot* snapshot = profiler->TakeHeapSnapshot(progress.get()
, &resolver); | 232 const v8::HeapSnapshot* snapshot = profiler->TakeHeapSnapshot(progress.get()
, &resolver); |
| 233 if (!snapshot) { | 233 if (!snapshot) { |
| 234 *errorString = "Failed to take heap snapshot"; | 234 *errorString = "Failed to take heap snapshot"; |
| 235 return; | 235 return; |
| 236 } | 236 } |
| 237 HeapSnapshotOutputStream stream(m_frontend); | 237 HeapSnapshotOutputStream stream(m_frontend); |
| 238 snapshot->Serialize(&stream); | 238 snapshot->Serialize(&stream); |
| 239 const_cast<v8::HeapSnapshot*>(snapshot)->Delete(); | 239 const_cast<v8::HeapSnapshot*>(snapshot)->Delete(); |
| 240 } | 240 } |
| 241 | 241 |
| 242 void V8HeapProfilerAgentImpl::getObjectByHeapObjectId(ErrorString* error, const
String16& heapSnapshotObjectId, const protocol::Maybe<String16>& objectGroup, Ow
nPtr<protocol::Runtime::RemoteObject>* result) | 242 void V8HeapProfilerAgentImpl::getObjectByHeapObjectId(ErrorString* error, const
String16& heapSnapshotObjectId, const protocol::Maybe<String16>& objectGroup, st
d::unique_ptr<protocol::Runtime::RemoteObject>* result) |
| 243 { | 243 { |
| 244 bool ok; | 244 bool ok; |
| 245 int id = heapSnapshotObjectId.toInt(&ok); | 245 int id = heapSnapshotObjectId.toInt(&ok); |
| 246 if (!ok) { | 246 if (!ok) { |
| 247 *error = "Invalid heap snapshot object id"; | 247 *error = "Invalid heap snapshot object id"; |
| 248 return; | 248 return; |
| 249 } | 249 } |
| 250 | 250 |
| 251 v8::HandleScope handles(m_isolate); | 251 v8::HandleScope handles(m_isolate); |
| 252 v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); | 252 v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 279 if (heapObject.IsEmpty()) { | 279 if (heapObject.IsEmpty()) { |
| 280 *errorString = "Object is not available"; | 280 *errorString = "Object is not available"; |
| 281 return; | 281 return; |
| 282 } | 282 } |
| 283 | 283 |
| 284 if (!m_session->debugger()->client()->isInspectableHeapObject(heapObject)) { | 284 if (!m_session->debugger()->client()->isInspectableHeapObject(heapObject)) { |
| 285 *errorString = "Object is not available"; | 285 *errorString = "Object is not available"; |
| 286 return; | 286 return; |
| 287 } | 287 } |
| 288 | 288 |
| 289 m_session->addInspectedObject(adoptPtr(new InspectableHeapObject(id))); | 289 m_session->addInspectedObject(wrapUnique(new InspectableHeapObject(id))); |
| 290 } | 290 } |
| 291 | 291 |
| 292 void V8HeapProfilerAgentImpl::getHeapObjectId(ErrorString* errorString, const St
ring16& objectId, String16* heapSnapshotObjectId) | 292 void V8HeapProfilerAgentImpl::getHeapObjectId(ErrorString* errorString, const St
ring16& objectId, String16* heapSnapshotObjectId) |
| 293 { | 293 { |
| 294 v8::HandleScope handles(m_isolate); | 294 v8::HandleScope handles(m_isolate); |
| 295 v8::Local<v8::Value> value = m_session->findObject(errorString, objectId); | 295 v8::Local<v8::Value> value = m_session->findObject(errorString, objectId); |
| 296 if (value.IsEmpty() || value->IsUndefined()) | 296 if (value.IsEmpty() || value->IsUndefined()) |
| 297 return; | 297 return; |
| 298 | 298 |
| 299 v8::SnapshotObjectId id = m_isolate->GetHeapProfiler()->GetObjectId(value); | 299 v8::SnapshotObjectId id = m_isolate->GetHeapProfiler()->GetObjectId(value); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 #if V8_MAJOR_VERSION * 1000 + V8_MINOR_VERSION >= 5002 | 350 #if V8_MAJOR_VERSION * 1000 + V8_MINOR_VERSION >= 5002 |
| 351 profiler->StartSamplingHeapProfiler(static_cast<uint64_t>(samplingIntervalVa
lue), 128, v8::HeapProfiler::kSamplingForceGC); | 351 profiler->StartSamplingHeapProfiler(static_cast<uint64_t>(samplingIntervalVa
lue), 128, v8::HeapProfiler::kSamplingForceGC); |
| 352 #else | 352 #else |
| 353 profiler->StartSamplingHeapProfiler(static_cast<uint64_t>(samplingIntervalVa
lue), 128); | 353 profiler->StartSamplingHeapProfiler(static_cast<uint64_t>(samplingIntervalVa
lue), 128); |
| 354 #endif | 354 #endif |
| 355 #endif | 355 #endif |
| 356 } | 356 } |
| 357 | 357 |
| 358 #if V8_MAJOR_VERSION >= 5 | 358 #if V8_MAJOR_VERSION >= 5 |
| 359 namespace { | 359 namespace { |
| 360 PassOwnPtr<protocol::HeapProfiler::SamplingHeapProfileNode> buildSampingHeapProf
ileNode(const v8::AllocationProfile::Node* node) | 360 std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfileNode> buildSampingHea
pProfileNode(const v8::AllocationProfile::Node* node) |
| 361 { | 361 { |
| 362 auto children = protocol::Array<protocol::HeapProfiler::SamplingHeapProfileN
ode>::create(); | 362 auto children = protocol::Array<protocol::HeapProfiler::SamplingHeapProfileN
ode>::create(); |
| 363 for (const auto* child : node->children) | 363 for (const auto* child : node->children) |
| 364 children->addItem(buildSampingHeapProfileNode(child)); | 364 children->addItem(buildSampingHeapProfileNode(child)); |
| 365 size_t selfSize = 0; | 365 size_t selfSize = 0; |
| 366 for (const auto& allocation : node->allocations) | 366 for (const auto& allocation : node->allocations) |
| 367 selfSize += allocation.size * allocation.count; | 367 selfSize += allocation.size * allocation.count; |
| 368 OwnPtr<protocol::HeapProfiler::SamplingHeapProfileNode> result = protocol::H
eapProfiler::SamplingHeapProfileNode::create() | 368 std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfileNode> result = pr
otocol::HeapProfiler::SamplingHeapProfileNode::create() |
| 369 .setFunctionName(toProtocolString(node->name)) | 369 .setFunctionName(toProtocolString(node->name)) |
| 370 .setScriptId(String16::number(node->script_id)) | 370 .setScriptId(String16::number(node->script_id)) |
| 371 .setUrl(toProtocolString(node->script_name)) | 371 .setUrl(toProtocolString(node->script_name)) |
| 372 .setLineNumber(node->line_number) | 372 .setLineNumber(node->line_number) |
| 373 .setColumnNumber(node->column_number) | 373 .setColumnNumber(node->column_number) |
| 374 .setSelfSize(selfSize) | 374 .setSelfSize(selfSize) |
| 375 .setChildren(std::move(children)).build(); | 375 .setChildren(std::move(children)).build(); |
| 376 return result; | 376 return result; |
| 377 } | 377 } |
| 378 } // namespace | 378 } // namespace |
| 379 #endif | 379 #endif |
| 380 | 380 |
| 381 void V8HeapProfilerAgentImpl::stopSampling(ErrorString* errorString, OwnPtr<prot
ocol::HeapProfiler::SamplingHeapProfile>* profile) | 381 void V8HeapProfilerAgentImpl::stopSampling(ErrorString* errorString, std::unique
_ptr<protocol::HeapProfiler::SamplingHeapProfile>* profile) |
| 382 { | 382 { |
| 383 #if V8_MAJOR_VERSION >= 5 | 383 #if V8_MAJOR_VERSION >= 5 |
| 384 v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); | 384 v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); |
| 385 if (!profiler) { | 385 if (!profiler) { |
| 386 *errorString = "Cannot access v8 heap profiler"; | 386 *errorString = "Cannot access v8 heap profiler"; |
| 387 return; | 387 return; |
| 388 } | 388 } |
| 389 v8::HandleScope scope(m_isolate); // Allocation profile contains Local handl
es. | 389 v8::HandleScope scope(m_isolate); // Allocation profile contains Local handl
es. |
| 390 OwnPtr<v8::AllocationProfile> v8Profile = adoptPtr(profiler->GetAllocationPr
ofile()); | 390 std::unique_ptr<v8::AllocationProfile> v8Profile(profiler->GetAllocationProf
ile()); |
| 391 profiler->StopSamplingHeapProfiler(); | 391 profiler->StopSamplingHeapProfiler(); |
| 392 m_state->setBoolean(HeapProfilerAgentState::samplingHeapProfilerEnabled, fal
se); | 392 m_state->setBoolean(HeapProfilerAgentState::samplingHeapProfilerEnabled, fal
se); |
| 393 if (!v8Profile) { | 393 if (!v8Profile) { |
| 394 *errorString = "Cannot access v8 sampled heap profile."; | 394 *errorString = "Cannot access v8 sampled heap profile."; |
| 395 return; | 395 return; |
| 396 } | 396 } |
| 397 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); | 397 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); |
| 398 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() | 398 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() |
| 399 .setHead(buildSampingHeapProfileNode(root)).build(); | 399 .setHead(buildSampingHeapProfileNode(root)).build(); |
| 400 #endif | 400 #endif |
| 401 } | 401 } |
| 402 | 402 |
| 403 } // namespace blink | 403 } // namespace blink |
| OLD | NEW |