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/V8Debugger.h" | 8 #include "platform/v8_inspector/V8Debugger.h" |
9 #include "platform/v8_inspector/V8InspectorImpl.h" | 9 #include "platform/v8_inspector/V8InspectorImpl.h" |
10 #include "platform/v8_inspector/V8InspectorSessionImpl.h" | 10 #include "platform/v8_inspector/V8InspectorSessionImpl.h" |
(...skipping 219 matching lines...) Loading... |
230 return; | 230 return; |
231 } | 231 } |
232 HeapSnapshotOutputStream stream(&m_frontend); | 232 HeapSnapshotOutputStream stream(&m_frontend); |
233 snapshot->Serialize(&stream); | 233 snapshot->Serialize(&stream); |
234 const_cast<v8::HeapSnapshot*>(snapshot)->Delete(); | 234 const_cast<v8::HeapSnapshot*>(snapshot)->Delete(); |
235 } | 235 } |
236 | 236 |
237 void V8HeapProfilerAgentImpl::getObjectByHeapObjectId(ErrorString* error, const
String16& heapSnapshotObjectId, const protocol::Maybe<String16>& objectGroup, st
d::unique_ptr<protocol::Runtime::RemoteObject>* result) | 237 void V8HeapProfilerAgentImpl::getObjectByHeapObjectId(ErrorString* error, const
String16& heapSnapshotObjectId, const protocol::Maybe<String16>& objectGroup, st
d::unique_ptr<protocol::Runtime::RemoteObject>* result) |
238 { | 238 { |
239 bool ok; | 239 bool ok; |
240 int id = heapSnapshotObjectId.toInt(&ok); | 240 int id = protocol::string16CharactersToInt(heapSnapshotObjectId.characters16
(), heapSnapshotObjectId.length(), &ok); |
241 if (!ok) { | 241 if (!ok) { |
242 *error = "Invalid heap snapshot object id"; | 242 *error = "Invalid heap snapshot object id"; |
243 return; | 243 return; |
244 } | 244 } |
245 | 245 |
246 v8::HandleScope handles(m_isolate); | 246 v8::HandleScope handles(m_isolate); |
247 v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); | 247 v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); |
248 if (heapObject.IsEmpty()) { | 248 if (heapObject.IsEmpty()) { |
249 *error = "Object is not available"; | 249 *error = "Object is not available"; |
250 return; | 250 return; |
251 } | 251 } |
252 | 252 |
253 if (!m_session->inspector()->client()->isInspectableHeapObject(heapObject))
{ | 253 if (!m_session->inspector()->client()->isInspectableHeapObject(heapObject))
{ |
254 *error = "Object is not available"; | 254 *error = "Object is not available"; |
255 return; | 255 return; |
256 } | 256 } |
257 | 257 |
258 *result = m_session->wrapObject(heapObject->CreationContext(), heapObject, o
bjectGroup.fromMaybe(""), false); | 258 *result = m_session->wrapObject(heapObject->CreationContext(), heapObject, o
bjectGroup.fromMaybe(""), false); |
259 if (!result) | 259 if (!result) |
260 *error = "Object is not available"; | 260 *error = "Object is not available"; |
261 } | 261 } |
262 | 262 |
263 void V8HeapProfilerAgentImpl::addInspectedHeapObject(ErrorString* errorString, c
onst String16& inspectedHeapObjectId) | 263 void V8HeapProfilerAgentImpl::addInspectedHeapObject(ErrorString* errorString, c
onst String16& inspectedHeapObjectId) |
264 { | 264 { |
265 bool ok; | 265 bool ok; |
266 int id = inspectedHeapObjectId.toInt(&ok); | 266 int id = protocol::string16CharactersToInt(inspectedHeapObjectId.characters1
6(), inspectedHeapObjectId.length(), &ok); |
267 if (!ok) { | 267 if (!ok) { |
268 *errorString = "Invalid heap snapshot object id"; | 268 *errorString = "Invalid heap snapshot object id"; |
269 return; | 269 return; |
270 } | 270 } |
271 | 271 |
272 v8::HandleScope handles(m_isolate); | 272 v8::HandleScope handles(m_isolate); |
273 v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); | 273 v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); |
274 if (heapObject.IsEmpty()) { | 274 if (heapObject.IsEmpty()) { |
275 *errorString = "Object is not available"; | 275 *errorString = "Object is not available"; |
276 return; | 276 return; |
(...skipping 10 matching lines...) Loading... |
287 void V8HeapProfilerAgentImpl::getHeapObjectId(ErrorString* errorString, const St
ring16& objectId, String16* heapSnapshotObjectId) | 287 void V8HeapProfilerAgentImpl::getHeapObjectId(ErrorString* errorString, const St
ring16& objectId, String16* heapSnapshotObjectId) |
288 { | 288 { |
289 v8::HandleScope handles(m_isolate); | 289 v8::HandleScope handles(m_isolate); |
290 v8::Local<v8::Value> value; | 290 v8::Local<v8::Value> value; |
291 v8::Local<v8::Context> context; | 291 v8::Local<v8::Context> context; |
292 String16 objectGroup; | 292 String16 objectGroup; |
293 if (!m_session->unwrapObject(errorString, objectId, &value, &context, &objec
tGroup) || value->IsUndefined()) | 293 if (!m_session->unwrapObject(errorString, objectId, &value, &context, &objec
tGroup) || value->IsUndefined()) |
294 return; | 294 return; |
295 | 295 |
296 v8::SnapshotObjectId id = m_isolate->GetHeapProfiler()->GetObjectId(value); | 296 v8::SnapshotObjectId id = m_isolate->GetHeapProfiler()->GetObjectId(value); |
297 *heapSnapshotObjectId = String16::fromInteger(id); | 297 *heapSnapshotObjectId = protocol::string16FromInteger(id); |
298 } | 298 } |
299 | 299 |
300 void V8HeapProfilerAgentImpl::requestHeapStatsUpdate() | 300 void V8HeapProfilerAgentImpl::requestHeapStatsUpdate() |
301 { | 301 { |
302 HeapStatsStream stream(&m_frontend); | 302 HeapStatsStream stream(&m_frontend); |
303 v8::SnapshotObjectId lastSeenObjectId = m_isolate->GetHeapProfiler()->GetHea
pStats(&stream); | 303 v8::SnapshotObjectId lastSeenObjectId = m_isolate->GetHeapProfiler()->GetHea
pStats(&stream); |
304 m_frontend.lastSeenObjectId(lastSeenObjectId, m_session->inspector()->client
()->currentTimeMS()); | 304 m_frontend.lastSeenObjectId(lastSeenObjectId, m_session->inspector()->client
()->currentTimeMS()); |
305 } | 305 } |
306 | 306 |
307 // static | 307 // static |
(...skipping 47 matching lines...) Loading... |
355 std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfileNode> buildSampingHea
pProfileNode(const v8::AllocationProfile::Node* node) | 355 std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfileNode> buildSampingHea
pProfileNode(const v8::AllocationProfile::Node* node) |
356 { | 356 { |
357 auto children = protocol::Array<protocol::HeapProfiler::SamplingHeapProfileN
ode>::create(); | 357 auto children = protocol::Array<protocol::HeapProfiler::SamplingHeapProfileN
ode>::create(); |
358 for (const auto* child : node->children) | 358 for (const auto* child : node->children) |
359 children->addItem(buildSampingHeapProfileNode(child)); | 359 children->addItem(buildSampingHeapProfileNode(child)); |
360 size_t selfSize = 0; | 360 size_t selfSize = 0; |
361 for (const auto& allocation : node->allocations) | 361 for (const auto& allocation : node->allocations) |
362 selfSize += allocation.size * allocation.count; | 362 selfSize += allocation.size * allocation.count; |
363 std::unique_ptr<protocol::Runtime::CallFrame> callFrame = protocol::Runtime:
:CallFrame::create() | 363 std::unique_ptr<protocol::Runtime::CallFrame> callFrame = protocol::Runtime:
:CallFrame::create() |
364 .setFunctionName(toProtocolString(node->name)) | 364 .setFunctionName(toProtocolString(node->name)) |
365 .setScriptId(String16::fromInteger(node->script_id)) | 365 .setScriptId(protocol::string16FromInteger(node->script_id)) |
366 .setUrl(toProtocolString(node->script_name)) | 366 .setUrl(toProtocolString(node->script_name)) |
367 .setLineNumber(node->line_number - 1) | 367 .setLineNumber(node->line_number - 1) |
368 .setColumnNumber(node->column_number - 1) | 368 .setColumnNumber(node->column_number - 1) |
369 .build(); | 369 .build(); |
370 std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfileNode> result = pr
otocol::HeapProfiler::SamplingHeapProfileNode::create() | 370 std::unique_ptr<protocol::HeapProfiler::SamplingHeapProfileNode> result = pr
otocol::HeapProfiler::SamplingHeapProfileNode::create() |
371 .setCallFrame(std::move(callFrame)) | 371 .setCallFrame(std::move(callFrame)) |
372 .setSelfSize(selfSize) | 372 .setSelfSize(selfSize) |
373 .setChildren(std::move(children)).build(); | 373 .setChildren(std::move(children)).build(); |
374 return result; | 374 return result; |
375 } | 375 } |
(...skipping 16 matching lines...) Loading... |
392 *errorString = "Cannot access v8 sampled heap profile."; | 392 *errorString = "Cannot access v8 sampled heap profile."; |
393 return; | 393 return; |
394 } | 394 } |
395 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); | 395 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); |
396 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() | 396 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() |
397 .setHead(buildSampingHeapProfileNode(root)).build(); | 397 .setHead(buildSampingHeapProfileNode(root)).build(); |
398 #endif | 398 #endif |
399 } | 399 } |
400 | 400 |
401 } // namespace blink | 401 } // namespace blink |
OLD | NEW |