| 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 162 |
| 163 void V8HeapProfilerAgentImpl::restore() | 163 void V8HeapProfilerAgentImpl::restore() |
| 164 { | 164 { |
| 165 if (m_state->booleanProperty(HeapProfilerAgentState::heapProfilerEnabled, fa
lse)) | 165 if (m_state->booleanProperty(HeapProfilerAgentState::heapProfilerEnabled, fa
lse)) |
| 166 m_frontend.resetProfiles(); | 166 m_frontend.resetProfiles(); |
| 167 if (m_state->booleanProperty(HeapProfilerAgentState::heapObjectsTrackingEnab
led, false)) | 167 if (m_state->booleanProperty(HeapProfilerAgentState::heapObjectsTrackingEnab
led, false)) |
| 168 startTrackingHeapObjectsInternal(m_state->booleanProperty(HeapProfilerAg
entState::allocationTrackingEnabled, false)); | 168 startTrackingHeapObjectsInternal(m_state->booleanProperty(HeapProfilerAg
entState::allocationTrackingEnabled, false)); |
| 169 #if V8_MAJOR_VERSION >= 5 | 169 #if V8_MAJOR_VERSION >= 5 |
| 170 if (m_state->booleanProperty(HeapProfilerAgentState::samplingHeapProfilerEna
bled, false)) { | 170 if (m_state->booleanProperty(HeapProfilerAgentState::samplingHeapProfilerEna
bled, false)) { |
| 171 ErrorString error; | 171 ErrorString error; |
| 172 double samplingInterval = m_state->numberProperty(HeapProfilerAgentState
::samplingHeapProfilerInterval, -1); | 172 double samplingInterval = m_state->doubleProperty(HeapProfilerAgentState
::samplingHeapProfilerInterval, -1); |
| 173 DCHECK_GE(samplingInterval, 0); | 173 DCHECK_GE(samplingInterval, 0); |
| 174 startSampling(&error, Maybe<double>(samplingInterval)); | 174 startSampling(&error, Maybe<double>(samplingInterval)); |
| 175 } | 175 } |
| 176 #endif | 176 #endif |
| 177 } | 177 } |
| 178 | 178 |
| 179 void V8HeapProfilerAgentImpl::collectGarbage(ErrorString*) | 179 void V8HeapProfilerAgentImpl::collectGarbage(ErrorString*) |
| 180 { | 180 { |
| 181 m_isolate->LowMemoryNotification(); | 181 m_isolate->LowMemoryNotification(); |
| 182 } | 182 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 } | 288 } |
| 289 | 289 |
| 290 void V8HeapProfilerAgentImpl::getHeapObjectId(ErrorString* errorString, const St
ring16& objectId, String16* heapSnapshotObjectId) | 290 void V8HeapProfilerAgentImpl::getHeapObjectId(ErrorString* errorString, const St
ring16& objectId, String16* heapSnapshotObjectId) |
| 291 { | 291 { |
| 292 v8::HandleScope handles(m_isolate); | 292 v8::HandleScope handles(m_isolate); |
| 293 v8::Local<v8::Value> value = m_session->findObject(errorString, objectId); | 293 v8::Local<v8::Value> value = m_session->findObject(errorString, objectId); |
| 294 if (value.IsEmpty() || value->IsUndefined()) | 294 if (value.IsEmpty() || value->IsUndefined()) |
| 295 return; | 295 return; |
| 296 | 296 |
| 297 v8::SnapshotObjectId id = m_isolate->GetHeapProfiler()->GetObjectId(value); | 297 v8::SnapshotObjectId id = m_isolate->GetHeapProfiler()->GetObjectId(value); |
| 298 *heapSnapshotObjectId = String16::number(id); | 298 *heapSnapshotObjectId = String16::fromInteger(id); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void V8HeapProfilerAgentImpl::requestHeapStatsUpdate() | 301 void V8HeapProfilerAgentImpl::requestHeapStatsUpdate() |
| 302 { | 302 { |
| 303 HeapStatsStream stream(&m_frontend); | 303 HeapStatsStream stream(&m_frontend); |
| 304 v8::SnapshotObjectId lastSeenObjectId = m_isolate->GetHeapProfiler()->GetHea
pStats(&stream); | 304 v8::SnapshotObjectId lastSeenObjectId = m_isolate->GetHeapProfiler()->GetHea
pStats(&stream); |
| 305 m_frontend.lastSeenObjectId(lastSeenObjectId, m_session->debugger()->client(
)->currentTimeMS()); | 305 m_frontend.lastSeenObjectId(lastSeenObjectId, m_session->debugger()->client(
)->currentTimeMS()); |
| 306 } | 306 } |
| 307 | 307 |
| 308 // static | 308 // static |
| (...skipping 25 matching lines...) Expand all Loading... |
| 334 void V8HeapProfilerAgentImpl::startSampling(ErrorString* errorString, const Mayb
e<double>& samplingInterval) | 334 void V8HeapProfilerAgentImpl::startSampling(ErrorString* errorString, const Mayb
e<double>& samplingInterval) |
| 335 { | 335 { |
| 336 #if V8_MAJOR_VERSION >= 5 | 336 #if V8_MAJOR_VERSION >= 5 |
| 337 v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); | 337 v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); |
| 338 if (!profiler) { | 338 if (!profiler) { |
| 339 *errorString = "Cannot access v8 heap profiler"; | 339 *errorString = "Cannot access v8 heap profiler"; |
| 340 return; | 340 return; |
| 341 } | 341 } |
| 342 const unsigned defaultSamplingInterval = 1 << 15; | 342 const unsigned defaultSamplingInterval = 1 << 15; |
| 343 double samplingIntervalValue = samplingInterval.fromMaybe(defaultSamplingInt
erval); | 343 double samplingIntervalValue = samplingInterval.fromMaybe(defaultSamplingInt
erval); |
| 344 m_state->setNumber(HeapProfilerAgentState::samplingHeapProfilerInterval, sam
plingIntervalValue); | 344 m_state->setDouble(HeapProfilerAgentState::samplingHeapProfilerInterval, sam
plingIntervalValue); |
| 345 m_state->setBoolean(HeapProfilerAgentState::samplingHeapProfilerEnabled, tru
e); | 345 m_state->setBoolean(HeapProfilerAgentState::samplingHeapProfilerEnabled, tru
e); |
| 346 #if V8_MAJOR_VERSION * 1000 + V8_MINOR_VERSION >= 5002 | 346 #if V8_MAJOR_VERSION * 1000 + V8_MINOR_VERSION >= 5002 |
| 347 profiler->StartSamplingHeapProfiler(static_cast<uint64_t>(samplingIntervalVa
lue), 128, v8::HeapProfiler::kSamplingForceGC); | 347 profiler->StartSamplingHeapProfiler(static_cast<uint64_t>(samplingIntervalVa
lue), 128, v8::HeapProfiler::kSamplingForceGC); |
| 348 #else | 348 #else |
| 349 profiler->StartSamplingHeapProfiler(static_cast<uint64_t>(samplingIntervalVa
lue), 128); | 349 profiler->StartSamplingHeapProfiler(static_cast<uint64_t>(samplingIntervalVa
lue), 128); |
| 350 #endif | 350 #endif |
| 351 #endif | 351 #endif |
| 352 } | 352 } |
| 353 | 353 |
| 354 #if V8_MAJOR_VERSION >= 5 | 354 #if V8_MAJOR_VERSION >= 5 |
| 355 namespace { | 355 namespace { |
| 356 std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfileNode> buildSampingHea
pProfileNode(const v8::AllocationProfile::Node* node) | 356 std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfileNode> buildSampingHea
pProfileNode(const v8::AllocationProfile::Node* node) |
| 357 { | 357 { |
| 358 auto children = protocol::Array<protocol::HeapProfiler::SamplingHeapProfileN
ode>::create(); | 358 auto children = protocol::Array<protocol::HeapProfiler::SamplingHeapProfileN
ode>::create(); |
| 359 for (const auto* child : node->children) | 359 for (const auto* child : node->children) |
| 360 children->addItem(buildSampingHeapProfileNode(child)); | 360 children->addItem(buildSampingHeapProfileNode(child)); |
| 361 size_t selfSize = 0; | 361 size_t selfSize = 0; |
| 362 for (const auto& allocation : node->allocations) | 362 for (const auto& allocation : node->allocations) |
| 363 selfSize += allocation.size * allocation.count; | 363 selfSize += allocation.size * allocation.count; |
| 364 std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfileNode> result = pr
otocol::HeapProfiler::SamplingHeapProfileNode::create() | 364 std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfileNode> result = pr
otocol::HeapProfiler::SamplingHeapProfileNode::create() |
| 365 .setFunctionName(toProtocolString(node->name)) | 365 .setFunctionName(toProtocolString(node->name)) |
| 366 .setScriptId(String16::number(node->script_id)) | 366 .setScriptId(String16::fromInteger(node->script_id)) |
| 367 .setUrl(toProtocolString(node->script_name)) | 367 .setUrl(toProtocolString(node->script_name)) |
| 368 .setLineNumber(node->line_number) | 368 .setLineNumber(node->line_number) |
| 369 .setColumnNumber(node->column_number) | 369 .setColumnNumber(node->column_number) |
| 370 .setSelfSize(selfSize) | 370 .setSelfSize(selfSize) |
| 371 .setChildren(std::move(children)).build(); | 371 .setChildren(std::move(children)).build(); |
| 372 return result; | 372 return result; |
| 373 } | 373 } |
| 374 } // namespace | 374 } // namespace |
| 375 #endif | 375 #endif |
| 376 | 376 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 390 *errorString = "Cannot access v8 sampled heap profile."; | 390 *errorString = "Cannot access v8 sampled heap profile."; |
| 391 return; | 391 return; |
| 392 } | 392 } |
| 393 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); | 393 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); |
| 394 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() | 394 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() |
| 395 .setHead(buildSampingHeapProfileNode(root)).build(); | 395 .setHead(buildSampingHeapProfileNode(root)).build(); |
| 396 #endif | 396 #endif |
| 397 } | 397 } |
| 398 | 398 |
| 399 } // namespace blink | 399 } // namespace blink |
| OLD | NEW |