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 24 matching lines...) Expand all Loading... |
35 } | 35 } |
36 m_frontend->flush(); | 36 m_frontend->flush(); |
37 return kContinue; | 37 return kContinue; |
38 } | 38 } |
39 private: | 39 private: |
40 protocol::Frontend::HeapProfiler* m_frontend; | 40 protocol::Frontend::HeapProfiler* m_frontend; |
41 }; | 41 }; |
42 | 42 |
43 class GlobalObjectNameResolver final : public v8::HeapProfiler::ObjectNameResolv
er { | 43 class GlobalObjectNameResolver final : public v8::HeapProfiler::ObjectNameResolv
er { |
44 public: | 44 public: |
45 explicit GlobalObjectNameResolver(V8RuntimeAgentImpl* runtimeAgent) : m_runt
imeAgent(runtimeAgent) { } | 45 explicit GlobalObjectNameResolver(V8RuntimeAgentImpl* runtimeAgent) : m_offs
et(0), m_runtimeAgent(runtimeAgent) |
| 46 { |
| 47 m_strings.resize(10000); |
| 48 } |
| 49 |
46 const char* GetName(v8::Local<v8::Object> object) override | 50 const char* GetName(v8::Local<v8::Object> object) override |
47 { | 51 { |
48 int contextId = V8Debugger::contextId(object->CreationContext()); | 52 int contextId = V8Debugger::contextId(object->CreationContext()); |
49 if (!contextId) | 53 if (!contextId) |
50 return ""; | 54 return ""; |
51 InjectedScript* injectedScript = m_runtimeAgent->getInjectedScriptManage
r()->findInjectedScript(contextId); | 55 InjectedScript* injectedScript = m_runtimeAgent->getInjectedScriptManage
r()->findInjectedScript(contextId); |
52 if (!injectedScript) | 56 if (!injectedScript) |
53 return ""; | 57 return ""; |
54 String16 name = injectedScript->origin().latin1Data(); | 58 String16 name = injectedScript->origin(); |
55 m_strings.append(name); | 59 size_t length = name.length(); |
56 return reinterpret_cast<const char *>(name.characters8()); | 60 if (m_offset + length + 1 >= m_strings.size()) |
| 61 return ""; |
| 62 for (size_t i = 0; i < length; ++i) { |
| 63 UChar ch = name[i]; |
| 64 m_strings[m_offset + i] = ch > 0xff ? '?' : static_cast<char>(ch); |
| 65 } |
| 66 m_strings[m_offset + length] = '\0'; |
| 67 char* result = &*m_strings.begin() + m_offset; |
| 68 m_offset += length + 1; |
| 69 return result; |
57 } | 70 } |
58 | 71 |
59 private: | 72 private: |
60 protocol::Vector<String16> m_strings; | 73 size_t m_offset; |
| 74 protocol::Vector<char> m_strings; |
61 V8RuntimeAgentImpl* m_runtimeAgent; | 75 V8RuntimeAgentImpl* m_runtimeAgent; |
62 }; | 76 }; |
63 | 77 |
64 class HeapSnapshotOutputStream final : public v8::OutputStream { | 78 class HeapSnapshotOutputStream final : public v8::OutputStream { |
65 public: | 79 public: |
66 HeapSnapshotOutputStream(protocol::Frontend::HeapProfiler* frontend) | 80 HeapSnapshotOutputStream(protocol::Frontend::HeapProfiler* frontend) |
67 : m_frontend(frontend) { } | 81 : m_frontend(frontend) { } |
68 void EndOfStream() override { } | 82 void EndOfStream() override { } |
69 int GetChunkSize() override { return 102400; } | 83 int GetChunkSize() override { return 102400; } |
70 WriteResult WriteAsciiChunk(char* data, int size) override | 84 WriteResult WriteAsciiChunk(char* data, int size) override |
71 { | 85 { |
72 m_frontend->addHeapSnapshotChunk(String16(data, size)); | 86 m_frontend->addHeapSnapshotChunk(String16(data, size)); |
73 m_frontend->flush(); | 87 m_frontend->flush(); |
74 return kContinue; | 88 return kContinue; |
75 } | 89 } |
76 private: | 90 private: |
77 protocol::Frontend::HeapProfiler* m_frontend; | 91 protocol::Frontend::HeapProfiler* m_frontend; |
78 }; | 92 }; |
79 | 93 |
80 v8::Local<v8::Object> objectByHeapObjectId(v8::Isolate* isolate, unsigned id) | 94 v8::Local<v8::Object> objectByHeapObjectId(v8::Isolate* isolate, int id) |
81 { | 95 { |
82 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); | 96 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); |
83 v8::Local<v8::Value> value = profiler->FindObjectById(id); | 97 v8::Local<v8::Value> value = profiler->FindObjectById(id); |
84 if (value.IsEmpty() || !value->IsObject()) | 98 if (value.IsEmpty() || !value->IsObject()) |
85 return v8::Local<v8::Object>(); | 99 return v8::Local<v8::Object>(); |
86 return value.As<v8::Object>(); | 100 return value.As<v8::Object>(); |
87 } | 101 } |
88 | 102 |
89 class InspectableHeapObject final : public V8RuntimeAgent::Inspectable { | 103 class InspectableHeapObject final : public V8RuntimeAgent::Inspectable { |
90 public: | 104 public: |
91 explicit InspectableHeapObject(unsigned heapObjectId) : m_heapObjectId(heapO
bjectId) { } | 105 explicit InspectableHeapObject(int heapObjectId) : m_heapObjectId(heapObject
Id) { } |
92 v8::Local<v8::Value> get(v8::Local<v8::Context> context) override | 106 v8::Local<v8::Value> get(v8::Local<v8::Context> context) override |
93 { | 107 { |
94 return objectByHeapObjectId(context->GetIsolate(), m_heapObjectId); | 108 return objectByHeapObjectId(context->GetIsolate(), m_heapObjectId); |
95 } | 109 } |
96 private: | 110 private: |
97 unsigned m_heapObjectId; | 111 int m_heapObjectId; |
98 }; | 112 }; |
99 | 113 |
100 class HeapStatsStream final : public v8::OutputStream { | 114 class HeapStatsStream final : public v8::OutputStream { |
101 public: | 115 public: |
102 HeapStatsStream(protocol::Frontend::HeapProfiler* frontend) | 116 HeapStatsStream(protocol::Frontend::HeapProfiler* frontend) |
103 : m_frontend(frontend) | 117 : m_frontend(frontend) |
104 { | 118 { |
105 } | 119 } |
106 | 120 |
107 void EndOfStream() override { } | 121 void EndOfStream() override { } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 return; | 235 return; |
222 } | 236 } |
223 HeapSnapshotOutputStream stream(m_frontend); | 237 HeapSnapshotOutputStream stream(m_frontend); |
224 snapshot->Serialize(&stream); | 238 snapshot->Serialize(&stream); |
225 const_cast<v8::HeapSnapshot*>(snapshot)->Delete(); | 239 const_cast<v8::HeapSnapshot*>(snapshot)->Delete(); |
226 } | 240 } |
227 | 241 |
228 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, Ow
nPtr<protocol::Runtime::RemoteObject>* result) |
229 { | 243 { |
230 bool ok; | 244 bool ok; |
231 unsigned id = heapSnapshotObjectId.toUInt(&ok); | 245 int id = heapSnapshotObjectId.toInt(&ok); |
232 if (!ok) { | 246 if (!ok) { |
233 *error = "Invalid heap snapshot object id"; | 247 *error = "Invalid heap snapshot object id"; |
234 return; | 248 return; |
235 } | 249 } |
236 | 250 |
237 v8::HandleScope handles(m_isolate); | 251 v8::HandleScope handles(m_isolate); |
238 v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); | 252 v8::Local<v8::Object> heapObject = objectByHeapObjectId(m_isolate, id); |
239 if (heapObject.IsEmpty()) { | 253 if (heapObject.IsEmpty()) { |
240 *error = "Object is not available"; | 254 *error = "Object is not available"; |
241 return; | 255 return; |
242 } | 256 } |
243 *result = m_runtimeAgent->wrapObject(heapObject->CreationContext(), heapObje
ct, objectGroup.fromMaybe("")); | 257 *result = m_runtimeAgent->wrapObject(heapObject->CreationContext(), heapObje
ct, objectGroup.fromMaybe("")); |
244 if (!result) | 258 if (!result) |
245 *error = "Object is not available"; | 259 *error = "Object is not available"; |
246 } | 260 } |
247 | 261 |
248 void V8HeapProfilerAgentImpl::addInspectedHeapObject(ErrorString* errorString, c
onst String16& inspectedHeapObjectId) | 262 void V8HeapProfilerAgentImpl::addInspectedHeapObject(ErrorString* errorString, c
onst String16& inspectedHeapObjectId) |
249 { | 263 { |
250 bool ok; | 264 bool ok; |
251 unsigned id = inspectedHeapObjectId.toUInt(&ok); | 265 int id = inspectedHeapObjectId.toInt(&ok); |
252 if (!ok) { | 266 if (!ok) { |
253 *errorString = "Invalid heap snapshot object id"; | 267 *errorString = "Invalid heap snapshot object id"; |
254 return; | 268 return; |
255 } | 269 } |
256 m_runtimeAgent->addInspectedObject(adoptPtr(new InspectableHeapObject(id))); | 270 m_runtimeAgent->addInspectedObject(adoptPtr(new InspectableHeapObject(id))); |
257 } | 271 } |
258 | 272 |
259 void V8HeapProfilerAgentImpl::getHeapObjectId(ErrorString* errorString, const St
ring16& objectId, String16* heapSnapshotObjectId) | 273 void V8HeapProfilerAgentImpl::getHeapObjectId(ErrorString* errorString, const St
ring16& objectId, String16* heapSnapshotObjectId) |
260 { | 274 { |
261 v8::HandleScope handles(m_isolate); | 275 v8::HandleScope handles(m_isolate); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 if (!v8Profile) { | 350 if (!v8Profile) { |
337 *errorString = "Cannot access v8 sampled heap profile."; | 351 *errorString = "Cannot access v8 sampled heap profile."; |
338 return; | 352 return; |
339 } | 353 } |
340 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); | 354 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); |
341 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() | 355 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() |
342 .setHead(buildSampingHeapProfileNode(root)).build(); | 356 .setHead(buildSampingHeapProfileNode(root)).build(); |
343 } | 357 } |
344 | 358 |
345 } // namespace blink | 359 } // namespace blink |
OLD | NEW |