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