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 27 matching lines...) Expand all Loading... |
38 } | 38 } |
39 m_frontend->flush(); | 39 m_frontend->flush(); |
40 return kContinue; | 40 return kContinue; |
41 } | 41 } |
42 private: | 42 private: |
43 protocol::HeapProfiler::Frontend* m_frontend; | 43 protocol::HeapProfiler::Frontend* m_frontend; |
44 }; | 44 }; |
45 | 45 |
46 class GlobalObjectNameResolver final : public v8::HeapProfiler::ObjectNameResolv
er { | 46 class GlobalObjectNameResolver final : public v8::HeapProfiler::ObjectNameResolv
er { |
47 public: | 47 public: |
48 explicit GlobalObjectNameResolver(V8InspectorSessionImpl* session) : m_offse
t(0), m_session(session) | 48 explicit GlobalObjectNameResolver(V8InspectorSessionImpl* session) |
49 { | 49 : m_offset(0), m_strings(10000), m_session(session) {} |
50 m_strings.resize(10000); | |
51 } | |
52 | 50 |
53 const char* GetName(v8::Local<v8::Object> object) override | 51 const char* GetName(v8::Local<v8::Object> object) override |
54 { | 52 { |
55 int contextId = V8Debugger::contextId(object->CreationContext()); | 53 int contextId = V8Debugger::contextId(object->CreationContext()); |
56 if (!contextId) | 54 if (!contextId) |
57 return ""; | 55 return ""; |
58 ErrorString errorString; | 56 ErrorString errorString; |
59 InjectedScript* injectedScript = m_session->findInjectedScript(&errorStr
ing, contextId); | 57 InjectedScript* injectedScript = m_session->findInjectedScript(&errorStr
ing, contextId); |
60 if (!injectedScript) | 58 if (!injectedScript) |
61 return ""; | 59 return ""; |
62 String16 name = injectedScript->context()->origin(); | 60 String16 name = injectedScript->context()->origin(); |
63 size_t length = name.length(); | 61 size_t length = name.length(); |
64 if (m_offset + length + 1 >= m_strings.size()) | 62 if (m_offset + length + 1 >= m_strings.size()) |
65 return ""; | 63 return ""; |
66 for (size_t i = 0; i < length; ++i) { | 64 for (size_t i = 0; i < length; ++i) { |
67 UChar ch = name[i]; | 65 UChar ch = name[i]; |
68 m_strings[m_offset + i] = ch > 0xff ? '?' : static_cast<char>(ch); | 66 m_strings[m_offset + i] = ch > 0xff ? '?' : static_cast<char>(ch); |
69 } | 67 } |
70 m_strings[m_offset + length] = '\0'; | 68 m_strings[m_offset + length] = '\0'; |
71 char* result = &*m_strings.begin() + m_offset; | 69 char* result = &*m_strings.begin() + m_offset; |
72 m_offset += length + 1; | 70 m_offset += length + 1; |
73 return result; | 71 return result; |
74 } | 72 } |
75 | 73 |
76 private: | 74 private: |
77 size_t m_offset; | 75 size_t m_offset; |
78 protocol::Vector<char> m_strings; | 76 std::vector<char> m_strings; |
79 V8InspectorSessionImpl* m_session; | 77 V8InspectorSessionImpl* m_session; |
80 }; | 78 }; |
81 | 79 |
82 class HeapSnapshotOutputStream final : public v8::OutputStream { | 80 class HeapSnapshotOutputStream final : public v8::OutputStream { |
83 public: | 81 public: |
84 HeapSnapshotOutputStream(protocol::HeapProfiler::Frontend* frontend) | 82 HeapSnapshotOutputStream(protocol::HeapProfiler::Frontend* frontend) |
85 : m_frontend(frontend) { } | 83 : m_frontend(frontend) { } |
86 void EndOfStream() override { } | 84 void EndOfStream() override { } |
87 int GetChunkSize() override { return 102400; } | 85 int GetChunkSize() override { return 102400; } |
88 WriteResult WriteAsciiChunk(char* data, int size) override | 86 WriteResult WriteAsciiChunk(char* data, int size) override |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 *errorString = "Cannot access v8 sampled heap profile."; | 390 *errorString = "Cannot access v8 sampled heap profile."; |
393 return; | 391 return; |
394 } | 392 } |
395 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); | 393 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); |
396 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() | 394 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() |
397 .setHead(buildSampingHeapProfileNode(root)).build(); | 395 .setHead(buildSampingHeapProfileNode(root)).build(); |
398 #endif | 396 #endif |
399 } | 397 } |
400 | 398 |
401 } // namespace blink | 399 } // namespace blink |
OLD | NEW |