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/InjectedScriptManager.h" | 8 #include "platform/v8_inspector/InjectedScriptManager.h" |
9 #include "platform/v8_inspector/V8DebuggerImpl.h" | 9 #include "platform/v8_inspector/V8DebuggerImpl.h" |
10 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" | 10 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 public: | 44 public: |
45 explicit GlobalObjectNameResolver(V8RuntimeAgentImpl* runtimeAgent) : m_runt imeAgent(runtimeAgent) { } | 45 explicit GlobalObjectNameResolver(V8RuntimeAgentImpl* runtimeAgent) : m_runt imeAgent(runtimeAgent) { } |
46 const char* GetName(v8::Local<v8::Object> object) override | 46 const char* GetName(v8::Local<v8::Object> object) override |
47 { | 47 { |
48 int contextId = V8Debugger::contextId(object->CreationContext()); | 48 int contextId = V8Debugger::contextId(object->CreationContext()); |
49 if (!contextId) | 49 if (!contextId) |
50 return ""; | 50 return ""; |
51 InjectedScript* injectedScript = m_runtimeAgent->injectedScriptManager() ->findInjectedScript(contextId); | 51 InjectedScript* injectedScript = m_runtimeAgent->injectedScriptManager() ->findInjectedScript(contextId); |
52 if (!injectedScript) | 52 if (!injectedScript) |
53 return ""; | 53 return ""; |
54 CString name = injectedScript->origin().utf8(); | 54 String name = injectedScript->origin().latin1(); |
dgozman
2016/03/08 01:35:12
String16
| |
55 m_strings.append(name); | 55 m_strings.append(name); |
56 return name.data(); | 56 return reinterpret_cast<const char *>(name.characters8()); |
dgozman
2016/03/08 01:35:12
Is characters8 null-terminated?
pfeldman
2016/03/08 02:24:59
YES!
| |
57 } | 57 } |
58 | 58 |
59 private: | 59 private: |
60 protocol::Vector<CString> m_strings; | 60 protocol::Vector<String> m_strings; |
dgozman
2016/03/08 01:35:12
String16
| |
61 V8RuntimeAgentImpl* m_runtimeAgent; | 61 V8RuntimeAgentImpl* m_runtimeAgent; |
62 }; | 62 }; |
63 | 63 |
64 class HeapSnapshotOutputStream final : public v8::OutputStream { | 64 class HeapSnapshotOutputStream final : public v8::OutputStream { |
65 public: | 65 public: |
66 HeapSnapshotOutputStream(protocol::Frontend::HeapProfiler* frontend) | 66 HeapSnapshotOutputStream(protocol::Frontend::HeapProfiler* frontend) |
67 : m_frontend(frontend) { } | 67 : m_frontend(frontend) { } |
68 void EndOfStream() override { } | 68 void EndOfStream() override { } |
69 int GetChunkSize() override { return 102400; } | 69 int GetChunkSize() override { return 102400; } |
70 WriteResult WriteAsciiChunk(char* data, int size) override | 70 WriteResult WriteAsciiChunk(char* data, int size) override |
71 { | 71 { |
72 m_frontend->addHeapSnapshotChunk(String(data, size)); | 72 m_frontend->addHeapSnapshotChunk(String16(data, size)); |
73 m_frontend->flush(); | 73 m_frontend->flush(); |
74 return kContinue; | 74 return kContinue; |
75 } | 75 } |
76 private: | 76 private: |
77 protocol::Frontend::HeapProfiler* m_frontend; | 77 protocol::Frontend::HeapProfiler* m_frontend; |
78 }; | 78 }; |
79 | 79 |
80 v8::Local<v8::Object> objectByHeapObjectId(v8::Isolate* isolate, unsigned id) | 80 v8::Local<v8::Object> objectByHeapObjectId(v8::Isolate* isolate, unsigned id) |
81 { | 81 { |
82 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); | 82 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 const v8::HeapSnapshot* snapshot = profiler->TakeHeapSnapshot(progress.get() , &resolver); | 218 const v8::HeapSnapshot* snapshot = profiler->TakeHeapSnapshot(progress.get() , &resolver); |
219 if (!snapshot) { | 219 if (!snapshot) { |
220 *errorString = "Failed to take heap snapshot"; | 220 *errorString = "Failed to take heap snapshot"; |
221 return; | 221 return; |
222 } | 222 } |
223 HeapSnapshotOutputStream stream(m_frontend); | 223 HeapSnapshotOutputStream stream(m_frontend); |
224 snapshot->Serialize(&stream); | 224 snapshot->Serialize(&stream); |
225 const_cast<v8::HeapSnapshot*>(snapshot)->Delete(); | 225 const_cast<v8::HeapSnapshot*>(snapshot)->Delete(); |
226 } | 226 } |
227 | 227 |
228 void V8HeapProfilerAgentImpl::getObjectByHeapObjectId(ErrorString* error, const String& heapSnapshotObjectId, const protocol::Maybe<String>& objectGroup, OwnPtr <protocol::Runtime::RemoteObject>* result) | 228 void V8HeapProfilerAgentImpl::getObjectByHeapObjectId(ErrorString* error, const String16& heapSnapshotObjectId, const protocol::Maybe<String16>& objectGroup, Ow nPtr<protocol::Runtime::RemoteObject>* result) |
229 { | 229 { |
230 bool ok; | 230 bool ok; |
231 unsigned id = heapSnapshotObjectId.toUInt(&ok); | 231 unsigned id = heapSnapshotObjectId.toUInt(&ok); |
232 if (!ok) { | 232 if (!ok) { |
233 *error = "Invalid heap snapshot object id"; | 233 *error = "Invalid heap snapshot object id"; |
234 return; | 234 return; |
235 } | 235 } |
236 | 236 |
237 v8::HandleScope handles(m_isolate); | 237 v8::HandleScope handles(m_isolate); |
238 v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); | 238 v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); |
239 if (heapObject.IsEmpty()) { | 239 if (heapObject.IsEmpty()) { |
240 *error = "Object is not available"; | 240 *error = "Object is not available"; |
241 return; | 241 return; |
242 } | 242 } |
243 *result = m_runtimeAgent->wrapObject(heapObject->CreationContext(), heapObje ct, objectGroup.fromMaybe("")); | 243 *result = m_runtimeAgent->wrapObject(heapObject->CreationContext(), heapObje ct, objectGroup.fromMaybe("")); |
244 if (!result) | 244 if (!result) |
245 *error = "Object is not available"; | 245 *error = "Object is not available"; |
246 } | 246 } |
247 | 247 |
248 void V8HeapProfilerAgentImpl::addInspectedHeapObject(ErrorString* errorString, c onst String& inspectedHeapObjectId) | 248 void V8HeapProfilerAgentImpl::addInspectedHeapObject(ErrorString* errorString, c onst String16& inspectedHeapObjectId) |
249 { | 249 { |
250 bool ok; | 250 bool ok; |
251 unsigned id = inspectedHeapObjectId.toUInt(&ok); | 251 unsigned id = inspectedHeapObjectId.toUInt(&ok); |
252 if (!ok) { | 252 if (!ok) { |
253 *errorString = "Invalid heap snapshot object id"; | 253 *errorString = "Invalid heap snapshot object id"; |
254 return; | 254 return; |
255 } | 255 } |
256 m_runtimeAgent->addInspectedObject(adoptPtr(new InspectableHeapObject(id))); | 256 m_runtimeAgent->addInspectedObject(adoptPtr(new InspectableHeapObject(id))); |
257 } | 257 } |
258 | 258 |
259 void V8HeapProfilerAgentImpl::getHeapObjectId(ErrorString* errorString, const St ring& objectId, String* heapSnapshotObjectId) | 259 void V8HeapProfilerAgentImpl::getHeapObjectId(ErrorString* errorString, const St ring16& objectId, String16* heapSnapshotObjectId) |
260 { | 260 { |
261 v8::HandleScope handles(m_isolate); | 261 v8::HandleScope handles(m_isolate); |
262 v8::Local<v8::Value> value = m_runtimeAgent->findObject(objectId); | 262 v8::Local<v8::Value> value = m_runtimeAgent->findObject(objectId); |
263 if (value.IsEmpty() || value->IsUndefined()) { | 263 if (value.IsEmpty() || value->IsUndefined()) { |
264 *errorString = "Object with given id not found"; | 264 *errorString = "Object with given id not found"; |
265 return; | 265 return; |
266 } | 266 } |
267 | 267 |
268 v8::SnapshotObjectId id = m_isolate->GetHeapProfiler()->GetObjectId(value); | 268 v8::SnapshotObjectId id = m_isolate->GetHeapProfiler()->GetObjectId(value); |
269 *heapSnapshotObjectId = String::number(id); | 269 *heapSnapshotObjectId = String16::number(id); |
270 } | 270 } |
271 | 271 |
272 void V8HeapProfilerAgentImpl::requestHeapStatsUpdate() | 272 void V8HeapProfilerAgentImpl::requestHeapStatsUpdate() |
273 { | 273 { |
274 if (!m_frontend) | 274 if (!m_frontend) |
275 return; | 275 return; |
276 HeapStatsStream stream(m_frontend); | 276 HeapStatsStream stream(m_frontend); |
277 v8::SnapshotObjectId lastSeenObjectId = m_isolate->GetHeapProfiler()->GetHea pStats(&stream); | 277 v8::SnapshotObjectId lastSeenObjectId = m_isolate->GetHeapProfiler()->GetHea pStats(&stream); |
278 m_frontend->lastSeenObjectId(lastSeenObjectId, m_runtimeAgent->debugger()->c lient()->currentTimeMS()); | 278 m_frontend->lastSeenObjectId(lastSeenObjectId, m_runtimeAgent->debugger()->c lient()->currentTimeMS()); |
279 } | 279 } |
(...skipping 24 matching lines...) Expand all Loading... | |
304 namespace { | 304 namespace { |
305 PassOwnPtr<protocol::HeapProfiler::SamplingHeapProfileNode> buildSampingHeapProf ileNode(const v8::AllocationProfile::Node* node) | 305 PassOwnPtr<protocol::HeapProfiler::SamplingHeapProfileNode> buildSampingHeapProf ileNode(const v8::AllocationProfile::Node* node) |
306 { | 306 { |
307 auto children = protocol::Array<protocol::HeapProfiler::SamplingHeapProfileN ode>::create(); | 307 auto children = protocol::Array<protocol::HeapProfiler::SamplingHeapProfileN ode>::create(); |
308 for (const auto* child : node->children) | 308 for (const auto* child : node->children) |
309 children->addItem(buildSampingHeapProfileNode(child)); | 309 children->addItem(buildSampingHeapProfileNode(child)); |
310 size_t totalSize = 0; | 310 size_t totalSize = 0; |
311 for (const auto& allocation : node->allocations) | 311 for (const auto& allocation : node->allocations) |
312 totalSize += allocation.size * allocation.count; | 312 totalSize += allocation.size * allocation.count; |
313 OwnPtr<protocol::HeapProfiler::SamplingHeapProfileNode> result = protocol::H eapProfiler::SamplingHeapProfileNode::create() | 313 OwnPtr<protocol::HeapProfiler::SamplingHeapProfileNode> result = protocol::H eapProfiler::SamplingHeapProfileNode::create() |
314 .setFunctionName(toWTFString(node->name)) | 314 .setFunctionName(toProtocolString(node->name)) |
315 .setScriptId(String::number(node->script_id)) | 315 .setScriptId(String16::number(node->script_id)) |
316 .setUrl(toWTFString(node->script_name)) | 316 .setUrl(toProtocolString(node->script_name)) |
317 .setLineNumber(node->line_number) | 317 .setLineNumber(node->line_number) |
318 .setColumnNumber(node->column_number) | 318 .setColumnNumber(node->column_number) |
319 .setTotalSize(totalSize) | 319 .setTotalSize(totalSize) |
320 .setChildren(children).build(); | 320 .setChildren(children).build(); |
321 return result.release(); | 321 return result.release(); |
322 } | 322 } |
323 } // namespace | 323 } // namespace |
324 | 324 |
325 void V8HeapProfilerAgentImpl::stopSampling(ErrorString* errorString, OwnPtr<prot ocol::HeapProfiler::SamplingHeapProfile>* profile) | 325 void V8HeapProfilerAgentImpl::stopSampling(ErrorString* errorString, OwnPtr<prot ocol::HeapProfiler::SamplingHeapProfile>* profile) |
326 { | 326 { |
327 v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); | 327 v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); |
328 if (!profiler) { | 328 if (!profiler) { |
329 *errorString = "Cannot access v8 heap profiler"; | 329 *errorString = "Cannot access v8 heap profiler"; |
330 return; | 330 return; |
331 } | 331 } |
332 v8::HandleScope scope(m_isolate); // Allocation profile contains Local handl es. | 332 v8::HandleScope scope(m_isolate); // Allocation profile contains Local handl es. |
333 OwnPtr<v8::AllocationProfile> v8Profile = adoptPtr(profiler->GetAllocationPr ofile()); | 333 OwnPtr<v8::AllocationProfile> v8Profile = adoptPtr(profiler->GetAllocationPr ofile()); |
334 profiler->StopSamplingHeapProfiler(); | 334 profiler->StopSamplingHeapProfiler(); |
335 m_state->setBoolean(HeapProfilerAgentState::samplingHeapProfilerEnabled, fal se); | 335 m_state->setBoolean(HeapProfilerAgentState::samplingHeapProfilerEnabled, fal se); |
336 if (!v8Profile) { | 336 if (!v8Profile) { |
337 *errorString = "Cannot access v8 sampled heap profile."; | 337 *errorString = "Cannot access v8 sampled heap profile."; |
338 return; | 338 return; |
339 } | 339 } |
340 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); | 340 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); |
341 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() | 341 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() |
342 .setHead(buildSampingHeapProfileNode(root)).build(); | 342 .setHead(buildSampingHeapProfileNode(root)).build(); |
343 } | 343 } |
344 | 344 |
345 } // namespace blink | 345 } // namespace blink |
OLD | NEW |