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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 WriteResult WriteHeapStatsChunk(v8::HeapStatsUpdate* updateData, int count)
override | 133 WriteResult WriteHeapStatsChunk(v8::HeapStatsUpdate* updateData, int count)
override |
134 { | 134 { |
135 ASSERT(count > 0); | 135 ASSERT(count > 0); |
136 OwnPtr<protocol::Array<int>> statsDiff = protocol::Array<int>::create(); | 136 OwnPtr<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(statsDiff.release()); | 142 m_frontend->heapStatsUpdate(std::move(statsDiff)); |
143 return kContinue; | 143 return kContinue; |
144 } | 144 } |
145 | 145 |
146 private: | 146 private: |
147 protocol::Frontend::HeapProfiler* m_frontend; | 147 protocol::Frontend::HeapProfiler* m_frontend; |
148 }; | 148 }; |
149 | 149 |
150 } // namespace | 150 } // namespace |
151 | 151 |
152 V8HeapProfilerAgentImpl::V8HeapProfilerAgentImpl(V8InspectorSessionImpl* session
) | 152 V8HeapProfilerAgentImpl::V8HeapProfilerAgentImpl(V8InspectorSessionImpl* session
) |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 for (const auto& allocation : node->allocations) | 372 for (const auto& allocation : node->allocations) |
373 selfSize += allocation.size * allocation.count; | 373 selfSize += allocation.size * allocation.count; |
374 OwnPtr<protocol::HeapProfiler::SamplingHeapProfileNode> result = protocol::H
eapProfiler::SamplingHeapProfileNode::create() | 374 OwnPtr<protocol::HeapProfiler::SamplingHeapProfileNode> result = protocol::H
eapProfiler::SamplingHeapProfileNode::create() |
375 .setFunctionName(toProtocolString(node->name)) | 375 .setFunctionName(toProtocolString(node->name)) |
376 .setScriptId(String16::number(node->script_id)) | 376 .setScriptId(String16::number(node->script_id)) |
377 .setUrl(toProtocolString(node->script_name)) | 377 .setUrl(toProtocolString(node->script_name)) |
378 .setLineNumber(node->line_number) | 378 .setLineNumber(node->line_number) |
379 .setColumnNumber(node->column_number) | 379 .setColumnNumber(node->column_number) |
380 .setSelfSize(selfSize) | 380 .setSelfSize(selfSize) |
381 .setChildren(std::move(children)).build(); | 381 .setChildren(std::move(children)).build(); |
382 return result.release(); | 382 return result; |
383 } | 383 } |
384 } // namespace | 384 } // namespace |
385 #endif | 385 #endif |
386 | 386 |
387 void V8HeapProfilerAgentImpl::stopSampling(ErrorString* errorString, OwnPtr<prot
ocol::HeapProfiler::SamplingHeapProfile>* profile) | 387 void V8HeapProfilerAgentImpl::stopSampling(ErrorString* errorString, OwnPtr<prot
ocol::HeapProfiler::SamplingHeapProfile>* profile) |
388 { | 388 { |
389 #if V8_MAJOR_VERSION >= 5 | 389 #if V8_MAJOR_VERSION >= 5 |
390 v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); | 390 v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); |
391 if (!profiler) { | 391 if (!profiler) { |
392 *errorString = "Cannot access v8 heap profiler"; | 392 *errorString = "Cannot access v8 heap profiler"; |
393 return; | 393 return; |
394 } | 394 } |
395 v8::HandleScope scope(m_isolate); // Allocation profile contains Local handl
es. | 395 v8::HandleScope scope(m_isolate); // Allocation profile contains Local handl
es. |
396 OwnPtr<v8::AllocationProfile> v8Profile = adoptPtr(profiler->GetAllocationPr
ofile()); | 396 OwnPtr<v8::AllocationProfile> v8Profile = adoptPtr(profiler->GetAllocationPr
ofile()); |
397 profiler->StopSamplingHeapProfiler(); | 397 profiler->StopSamplingHeapProfiler(); |
398 m_state->setBoolean(HeapProfilerAgentState::samplingHeapProfilerEnabled, fal
se); | 398 m_state->setBoolean(HeapProfilerAgentState::samplingHeapProfilerEnabled, fal
se); |
399 if (!v8Profile) { | 399 if (!v8Profile) { |
400 *errorString = "Cannot access v8 sampled heap profile."; | 400 *errorString = "Cannot access v8 sampled heap profile."; |
401 return; | 401 return; |
402 } | 402 } |
403 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); | 403 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); |
404 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() | 404 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() |
405 .setHead(buildSampingHeapProfileNode(root)).build(); | 405 .setHead(buildSampingHeapProfileNode(root)).build(); |
406 #endif | 406 #endif |
407 } | 407 } |
408 | 408 |
409 } // namespace blink | 409 } // namespace blink |
OLD | NEW |