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

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

Issue 2012753003: DevTools: consolidate protocol generators for front-end, backend and type builder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::HeapProfiler::Frontend* m_frontend; 147 protocol::HeapProfiler::Frontend* m_frontend;
148 }; 148 };
149 149
150 } // namespace 150 } // namespace
151 151
152 V8HeapProfilerAgentImpl::V8HeapProfilerAgentImpl(V8InspectorSessionImpl* session , protocol::HeapProfiler::Frontend* frontend, protocol::DictionaryValue* state) 152 V8HeapProfilerAgentImpl::V8HeapProfilerAgentImpl(V8InspectorSessionImpl* session , protocol::FrontendChannel* frontendChannel, 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(frontendChannel)
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 {
163 } 163 }
164 164
165 void V8HeapProfilerAgentImpl::restore() 165 void V8HeapProfilerAgentImpl::restore()
166 { 166 {
167 if (m_state->booleanProperty(HeapProfilerAgentState::heapProfilerEnabled, fa lse)) 167 if (m_state->booleanProperty(HeapProfilerAgentState::heapProfilerEnabled, fa lse))
168 m_frontend->resetProfiles(); 168 m_frontend.resetProfiles();
169 if (m_state->booleanProperty(HeapProfilerAgentState::heapObjectsTrackingEnab led, false)) 169 if (m_state->booleanProperty(HeapProfilerAgentState::heapObjectsTrackingEnab led, false))
170 startTrackingHeapObjectsInternal(m_state->booleanProperty(HeapProfilerAg entState::allocationTrackingEnabled, false)); 170 startTrackingHeapObjectsInternal(m_state->booleanProperty(HeapProfilerAg entState::allocationTrackingEnabled, false));
171 #if V8_MAJOR_VERSION >= 5 171 #if V8_MAJOR_VERSION >= 5
172 if (m_state->booleanProperty(HeapProfilerAgentState::samplingHeapProfilerEna bled, false)) { 172 if (m_state->booleanProperty(HeapProfilerAgentState::samplingHeapProfilerEna bled, false)) {
173 ErrorString error; 173 ErrorString error;
174 double samplingInterval = m_state->numberProperty(HeapProfilerAgentState ::samplingHeapProfilerInterval, -1); 174 double samplingInterval = m_state->numberProperty(HeapProfilerAgentState ::samplingHeapProfilerInterval, -1);
175 DCHECK_GE(samplingInterval, 0); 175 DCHECK_GE(samplingInterval, 0);
176 startSampling(&error, Maybe<double>(samplingInterval)); 176 startSampling(&error, Maybe<double>(samplingInterval));
177 } 177 }
178 #endif 178 #endif
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 219
220 void V8HeapProfilerAgentImpl::takeHeapSnapshot(ErrorString* errorString, const p rotocol::Maybe<bool>& reportProgress) 220 void V8HeapProfilerAgentImpl::takeHeapSnapshot(ErrorString* errorString, const p rotocol::Maybe<bool>& reportProgress)
221 { 221 {
222 v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler(); 222 v8::HeapProfiler* profiler = m_isolate->GetHeapProfiler();
223 if (!profiler) { 223 if (!profiler) {
224 *errorString = "Cannot access v8 heap profiler"; 224 *errorString = "Cannot access v8 heap profiler";
225 return; 225 return;
226 } 226 }
227 std::unique_ptr<HeapSnapshotProgress> progress; 227 std::unique_ptr<HeapSnapshotProgress> progress;
228 if (reportProgress.fromMaybe(false)) 228 if (reportProgress.fromMaybe(false))
229 progress = wrapUnique(new HeapSnapshotProgress(m_frontend)); 229 progress = wrapUnique(new HeapSnapshotProgress(&m_frontend));
230 230
231 GlobalObjectNameResolver resolver(m_session); 231 GlobalObjectNameResolver resolver(m_session);
232 const v8::HeapSnapshot* snapshot = profiler->TakeHeapSnapshot(progress.get() , &resolver); 232 const v8::HeapSnapshot* snapshot = profiler->TakeHeapSnapshot(progress.get() , &resolver);
233 if (!snapshot) { 233 if (!snapshot) {
234 *errorString = "Failed to take heap snapshot"; 234 *errorString = "Failed to take heap snapshot";
235 return; 235 return;
236 } 236 }
237 HeapSnapshotOutputStream stream(m_frontend); 237 HeapSnapshotOutputStream stream(&m_frontend);
238 snapshot->Serialize(&stream); 238 snapshot->Serialize(&stream);
239 const_cast<v8::HeapSnapshot*>(snapshot)->Delete(); 239 const_cast<v8::HeapSnapshot*>(snapshot)->Delete();
240 } 240 }
241 241
242 void V8HeapProfilerAgentImpl::getObjectByHeapObjectId(ErrorString* error, const String16& heapSnapshotObjectId, const protocol::Maybe<String16>& objectGroup, st d::unique_ptr<protocol::Runtime::RemoteObject>* result) 242 void V8HeapProfilerAgentImpl::getObjectByHeapObjectId(ErrorString* error, const String16& heapSnapshotObjectId, const protocol::Maybe<String16>& objectGroup, st d::unique_ptr<protocol::Runtime::RemoteObject>* result)
243 { 243 {
244 bool ok; 244 bool ok;
245 int id = heapSnapshotObjectId.toInt(&ok); 245 int id = heapSnapshotObjectId.toInt(&ok);
246 if (!ok) { 246 if (!ok) {
247 *error = "Invalid heap snapshot object id"; 247 *error = "Invalid heap snapshot object id";
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 v8::Local<v8::Value> value = m_session->findObject(errorString, objectId); 295 v8::Local<v8::Value> value = m_session->findObject(errorString, objectId);
296 if (value.IsEmpty() || value->IsUndefined()) 296 if (value.IsEmpty() || value->IsUndefined())
297 return; 297 return;
298 298
299 v8::SnapshotObjectId id = m_isolate->GetHeapProfiler()->GetObjectId(value); 299 v8::SnapshotObjectId id = m_isolate->GetHeapProfiler()->GetObjectId(value);
300 *heapSnapshotObjectId = String16::number(id); 300 *heapSnapshotObjectId = String16::number(id);
301 } 301 }
302 302
303 void V8HeapProfilerAgentImpl::requestHeapStatsUpdate() 303 void V8HeapProfilerAgentImpl::requestHeapStatsUpdate()
304 { 304 {
305 if (!m_frontend) 305 HeapStatsStream stream(&m_frontend);
306 return;
307 HeapStatsStream stream(m_frontend);
308 v8::SnapshotObjectId lastSeenObjectId = m_isolate->GetHeapProfiler()->GetHea pStats(&stream); 306 v8::SnapshotObjectId lastSeenObjectId = m_isolate->GetHeapProfiler()->GetHea pStats(&stream);
309 m_frontend->lastSeenObjectId(lastSeenObjectId, m_session->debugger()->client ()->currentTimeMS()); 307 m_frontend.lastSeenObjectId(lastSeenObjectId, m_session->debugger()->client( )->currentTimeMS());
310 } 308 }
311 309
312 // static 310 // static
313 void V8HeapProfilerAgentImpl::onTimer(void* data) 311 void V8HeapProfilerAgentImpl::onTimer(void* data)
314 { 312 {
315 reinterpret_cast<V8HeapProfilerAgentImpl*>(data)->requestHeapStatsUpdate(); 313 reinterpret_cast<V8HeapProfilerAgentImpl*>(data)->requestHeapStatsUpdate();
316 } 314 }
317 315
318 void V8HeapProfilerAgentImpl::startTrackingHeapObjectsInternal(bool trackAllocat ions) 316 void V8HeapProfilerAgentImpl::startTrackingHeapObjectsInternal(bool trackAllocat ions)
319 { 317 {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 *errorString = "Cannot access v8 sampled heap profile."; 392 *errorString = "Cannot access v8 sampled heap profile.";
395 return; 393 return;
396 } 394 }
397 v8::AllocationProfile::Node* root = v8Profile->GetRootNode(); 395 v8::AllocationProfile::Node* root = v8Profile->GetRootNode();
398 *profile = protocol::HeapProfiler::SamplingHeapProfile::create() 396 *profile = protocol::HeapProfiler::SamplingHeapProfile::create()
399 .setHead(buildSampingHeapProfileNode(root)).build(); 397 .setHead(buildSampingHeapProfileNode(root)).build();
400 #endif 398 #endif
401 } 399 }
402 400
403 } // namespace blink 401 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698