Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8HeapProfilerAgentImpl.cpp

Issue 2008183002: DevTools: generate frontend and backend interfaces under domains. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comment addressed Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 10 matching lines...) Expand all
21 static const char heapObjectsTrackingEnabled[] = "heapObjectsTrackingEnabled"; 21 static const char heapObjectsTrackingEnabled[] = "heapObjectsTrackingEnabled";
22 static const char allocationTrackingEnabled[] = "allocationTrackingEnabled"; 22 static const char allocationTrackingEnabled[] = "allocationTrackingEnabled";
23 #if V8_MAJOR_VERSION >= 5 23 #if V8_MAJOR_VERSION >= 5
24 static const char samplingHeapProfilerEnabled[] = "samplingHeapProfilerEnabled"; 24 static const char samplingHeapProfilerEnabled[] = "samplingHeapProfilerEnabled";
25 static const char samplingHeapProfilerInterval[] = "samplingHeapProfilerInterval "; 25 static const char samplingHeapProfilerInterval[] = "samplingHeapProfilerInterval ";
26 #endif 26 #endif
27 } 27 }
28 28
29 class HeapSnapshotProgress final : public v8::ActivityControl { 29 class HeapSnapshotProgress final : public v8::ActivityControl {
30 public: 30 public:
31 HeapSnapshotProgress(protocol::Frontend::HeapProfiler* frontend) 31 HeapSnapshotProgress(protocol::HeapProfiler::Frontend* frontend)
32 : m_frontend(frontend) { } 32 : m_frontend(frontend) { }
33 ControlOption ReportProgressValue(int done, int total) override 33 ControlOption ReportProgressValue(int done, int total) override
34 { 34 {
35 m_frontend->reportHeapSnapshotProgress(done, total, protocol::Maybe<bool >()); 35 m_frontend->reportHeapSnapshotProgress(done, total, protocol::Maybe<bool >());
36 if (done >= total) { 36 if (done >= total) {
37 m_frontend->reportHeapSnapshotProgress(total, total, true); 37 m_frontend->reportHeapSnapshotProgress(total, total, true);
38 } 38 }
39 m_frontend->flush(); 39 m_frontend->flush();
40 return kContinue; 40 return kContinue;
41 } 41 }
42 private: 42 private:
43 protocol::Frontend::HeapProfiler* 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) : m_offse t(0), m_session(session)
49 { 49 {
50 m_strings.resize(10000); 50 m_strings.resize(10000);
51 } 51 }
52 52
53 const char* GetName(v8::Local<v8::Object> object) override 53 const char* GetName(v8::Local<v8::Object> object) override
(...skipping 20 matching lines...) Expand all
74 } 74 }
75 75
76 private: 76 private:
77 size_t m_offset; 77 size_t m_offset;
78 protocol::Vector<char> m_strings; 78 protocol::Vector<char> m_strings;
79 V8InspectorSessionImpl* m_session; 79 V8InspectorSessionImpl* m_session;
80 }; 80 };
81 81
82 class HeapSnapshotOutputStream final : public v8::OutputStream { 82 class HeapSnapshotOutputStream final : public v8::OutputStream {
83 public: 83 public:
84 HeapSnapshotOutputStream(protocol::Frontend::HeapProfiler* frontend) 84 HeapSnapshotOutputStream(protocol::HeapProfiler::Frontend* frontend)
85 : m_frontend(frontend) { } 85 : m_frontend(frontend) { }
86 void EndOfStream() override { } 86 void EndOfStream() override { }
87 int GetChunkSize() override { return 102400; } 87 int GetChunkSize() override { return 102400; }
88 WriteResult WriteAsciiChunk(char* data, int size) override 88 WriteResult WriteAsciiChunk(char* data, int size) override
89 { 89 {
90 m_frontend->addHeapSnapshotChunk(String16(data, size)); 90 m_frontend->addHeapSnapshotChunk(String16(data, size));
91 m_frontend->flush(); 91 m_frontend->flush();
92 return kContinue; 92 return kContinue;
93 } 93 }
94 private: 94 private:
95 protocol::Frontend::HeapProfiler* m_frontend; 95 protocol::HeapProfiler::Frontend* m_frontend;
96 }; 96 };
97 97
98 v8::Local<v8::Object> objectByHeapObjectId(v8::Isolate* isolate, int id) 98 v8::Local<v8::Object> objectByHeapObjectId(v8::Isolate* isolate, int id)
99 { 99 {
100 v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); 100 v8::HeapProfiler* profiler = isolate->GetHeapProfiler();
101 v8::Local<v8::Value> value = profiler->FindObjectById(id); 101 v8::Local<v8::Value> value = profiler->FindObjectById(id);
102 if (value.IsEmpty() || !value->IsObject()) 102 if (value.IsEmpty() || !value->IsObject())
103 return v8::Local<v8::Object>(); 103 return v8::Local<v8::Object>();
104 return value.As<v8::Object>(); 104 return value.As<v8::Object>();
105 } 105 }
106 106
107 class InspectableHeapObject final : public V8InspectorSession::Inspectable { 107 class InspectableHeapObject final : public V8InspectorSession::Inspectable {
108 public: 108 public:
109 explicit InspectableHeapObject(int heapObjectId) : m_heapObjectId(heapObject Id) { } 109 explicit InspectableHeapObject(int heapObjectId) : m_heapObjectId(heapObject Id) { }
110 v8::Local<v8::Value> get(v8::Local<v8::Context> context) override 110 v8::Local<v8::Value> get(v8::Local<v8::Context> context) override
111 { 111 {
112 return objectByHeapObjectId(context->GetIsolate(), m_heapObjectId); 112 return objectByHeapObjectId(context->GetIsolate(), m_heapObjectId);
113 } 113 }
114 private: 114 private:
115 int m_heapObjectId; 115 int m_heapObjectId;
116 }; 116 };
117 117
118 class HeapStatsStream final : public v8::OutputStream { 118 class HeapStatsStream final : public v8::OutputStream {
119 public: 119 public:
120 HeapStatsStream(protocol::Frontend::HeapProfiler* frontend) 120 HeapStatsStream(protocol::HeapProfiler::Frontend* frontend)
121 : m_frontend(frontend) 121 : m_frontend(frontend)
122 { 122 {
123 } 123 }
124 124
125 void EndOfStream() override { } 125 void EndOfStream() override { }
126 126
127 WriteResult WriteAsciiChunk(char* data, int size) override 127 WriteResult WriteAsciiChunk(char* data, int size) override
128 { 128 {
129 DCHECK(false); 129 DCHECK(false);
130 return kAbort; 130 return kAbort;
131 } 131 }
132 132
133 WriteResult WriteHeapStatsChunk(v8::HeapStatsUpdate* updateData, int count) override 133 WriteResult WriteHeapStatsChunk(v8::HeapStatsUpdate* updateData, int count) override
134 { 134 {
135 DCHECK_GT(count, 0); 135 DCHECK_GT(count, 0);
136 std::unique_ptr<protocol::Array<int>> statsDiff = protocol::Array<int>:: create(); 136 std::unique_ptr<protocol::Array<int>> statsDiff = protocol::Array<int>:: create();
137 for (int i = 0; i < count; ++i) { 137 for (int i = 0; i < count; ++i) {
138 statsDiff->addItem(updateData[i].index); 138 statsDiff->addItem(updateData[i].index);
139 statsDiff->addItem(updateData[i].count); 139 statsDiff->addItem(updateData[i].count);
140 statsDiff->addItem(updateData[i].size); 140 statsDiff->addItem(updateData[i].size);
141 } 141 }
142 m_frontend->heapStatsUpdate(std::move(statsDiff)); 142 m_frontend->heapStatsUpdate(std::move(statsDiff));
143 return kContinue; 143 return kContinue;
144 } 144 }
145 145
146 private: 146 private:
147 protocol::Frontend::HeapProfiler* m_frontend; 147 protocol::HeapProfiler::Frontend* m_frontend;
148 }; 148 };
149 149
150 } // namespace 150 } // namespace
151 151
152 V8HeapProfilerAgentImpl::V8HeapProfilerAgentImpl(V8InspectorSessionImpl* session , protocol::Frontend::HeapProfiler* frontend, protocol::DictionaryValue* state) 152 V8HeapProfilerAgentImpl::V8HeapProfilerAgentImpl(V8InspectorSessionImpl* session , protocol::HeapProfiler::Frontend* frontend, protocol::DictionaryValue* state)
153 : m_session(session) 153 : m_session(session)
154 , m_isolate(session->debugger()->isolate()) 154 , m_isolate(session->debugger()->isolate())
155 , m_frontend(frontend) 155 , m_frontend(frontend)
156 , m_state(state) 156 , m_state(state)
157 , m_hasTimer(false) 157 , m_hasTimer(false)
158 { 158 {
159 } 159 }
160 160
161 V8HeapProfilerAgentImpl::~V8HeapProfilerAgentImpl() 161 V8HeapProfilerAgentImpl::~V8HeapProfilerAgentImpl()
162 { 162 {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 *errorString = "Cannot access v8 sampled heap profile."; 394 *errorString = "Cannot access v8 sampled heap profile.";
395 return; 395 return;
396 } 396 }
397 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); 397 v8::AllocationProfile::Node* root = v8Profile->GetRootNode();
398 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() 398 *profile = protocol::HeapProfiler::SamplingHeapProfile::create()
399 .setHead(buildSampingHeapProfileNode(root)).build(); 399 .setHead(buildSampingHeapProfileNode(root)).build();
400 #endif 400 #endif
401 } 401 }
402 402
403 } // namespace blink 403 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698