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

Side by Side Diff: Source/core/inspector/InspectorHeapProfilerAgent.cpp

Issue 98273008: [DevTools] Send heap snapshot to the frontend immediatly when it is ready (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed test crash Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 } 249 }
250 } 250 }
251 251
252 void InspectorHeapProfilerAgent::removeProfile(ErrorString*, int rawUid) 252 void InspectorHeapProfilerAgent::removeProfile(ErrorString*, int rawUid)
253 { 253 {
254 unsigned uid = static_cast<unsigned>(rawUid); 254 unsigned uid = static_cast<unsigned>(rawUid);
255 if (m_snapshots.contains(uid)) 255 if (m_snapshots.contains(uid))
256 m_snapshots.remove(uid); 256 m_snapshots.remove(uid);
257 } 257 }
258 258
259 void InspectorHeapProfilerAgent::takeHeapSnapshot(ErrorString*, const bool* repo rtProgress) 259 void InspectorHeapProfilerAgent::takeHeapSnapshot(ErrorString* errorString, cons t bool* reportProgress)
260 { 260 {
261 class HeapSnapshotProgress FINAL : public ScriptProfiler::HeapSnapshotProgre ss { 261 class HeapSnapshotProgress FINAL : public ScriptProfiler::HeapSnapshotProgre ss {
262 public: 262 public:
263 explicit HeapSnapshotProgress(InspectorFrontend::HeapProfiler* frontend) 263 explicit HeapSnapshotProgress(InspectorFrontend::HeapProfiler* frontend)
264 : m_frontend(frontend) { } 264 : m_frontend(frontend) { }
265 virtual void Start(int totalWork) OVERRIDE 265 virtual void Start(int totalWork) OVERRIDE
266 { 266 {
267 m_totalWork = totalWork; 267 m_totalWork = totalWork;
268 } 268 }
269 virtual void Worked(int workDone) OVERRIDE 269 virtual void Worked(int workDone) OVERRIDE
270 { 270 {
271 if (m_frontend) 271 if (m_frontend)
272 m_frontend->reportHeapSnapshotProgress(workDone, m_totalWork); 272 m_frontend->reportHeapSnapshotProgress(workDone, m_totalWork, 0) ;
273 } 273 }
274 virtual void Done() OVERRIDE { } 274 virtual void Done() OVERRIDE
275 {
276 const bool finished = true;
277 if (m_frontend)
278 m_frontend->reportHeapSnapshotProgress(m_totalWork, m_totalWork, &finished);
279 }
275 virtual bool isCanceled() OVERRIDE { return false; } 280 virtual bool isCanceled() OVERRIDE { return false; }
276 private: 281 private:
277 InspectorFrontend::HeapProfiler* m_frontend; 282 InspectorFrontend::HeapProfiler* m_frontend;
278 int m_totalWork; 283 int m_totalWork;
279 }; 284 };
280 285
281 String title = "Snapshot " + String::number(m_nextUserInitiatedHeapSnapshotN umber++); 286 String title = "Snapshot " + String::number(m_nextUserInitiatedHeapSnapshotN umber++);
282 HeapSnapshotProgress progress(reportProgress && *reportProgress ? m_frontend : 0); 287 HeapSnapshotProgress progress(reportProgress && *reportProgress ? m_frontend : 0);
283 RefPtr<ScriptHeapSnapshot> snapshot = ScriptProfiler::takeHeapSnapshot(title , &progress); 288 RefPtr<ScriptHeapSnapshot> snapshot = ScriptProfiler::takeHeapSnapshot(title , &progress);
284 if (snapshot) { 289 if (!snapshot) {
285 m_snapshots.add(snapshot->uid(), snapshot); 290 *errorString = "Failed to take heap snapshot";
286 if (m_frontend) 291 return;
287 m_frontend->addProfileHeader(createSnapshotHeader(*snapshot)); 292 }
293
294 class OutputStream : public ScriptHeapSnapshot::OutputStream {
295 public:
296 OutputStream(InspectorFrontend::HeapProfiler* frontend, unsigned uid)
297 : m_frontend(frontend), m_uid(uid) { }
298 void Write(const String& chunk) { m_frontend->addHeapSnapshotChunk(m_uid , chunk); }
299 void Close() { }
300 private:
301 InspectorFrontend::HeapProfiler* m_frontend;
302 int m_uid;
303 };
304
305 if (m_frontend) {
306 unsigned uid = static_cast<unsigned>(snapshot->uid());
307 OutputStream stream(m_frontend, uid);
308 snapshot->writeJSON(&stream);
288 } 309 }
289 } 310 }
290 311
291 void InspectorHeapProfilerAgent::getObjectByHeapObjectId(ErrorString* error, con st String& heapSnapshotObjectId, const String* objectGroup, RefPtr<TypeBuilder:: Runtime::RemoteObject>& result) 312 void InspectorHeapProfilerAgent::getObjectByHeapObjectId(ErrorString* error, con st String& heapSnapshotObjectId, const String* objectGroup, RefPtr<TypeBuilder:: Runtime::RemoteObject>& result)
292 { 313 {
293 bool ok; 314 bool ok;
294 unsigned id = heapSnapshotObjectId.toUInt(&ok); 315 unsigned id = heapSnapshotObjectId.toUInt(&ok);
295 if (!ok) { 316 if (!ok) {
296 *error = "Invalid heap snapshot object id"; 317 *error = "Invalid heap snapshot object id";
297 return; 318 return;
(...skipping 25 matching lines...) Expand all
323 if (value.hasNoValue() || value.isUndefined()) { 344 if (value.hasNoValue() || value.isUndefined()) {
324 *errorString = "Object with given id not found"; 345 *errorString = "Object with given id not found";
325 return; 346 return;
326 } 347 }
327 unsigned id = ScriptProfiler::getHeapObjectId(value); 348 unsigned id = ScriptProfiler::getHeapObjectId(value);
328 *heapSnapshotObjectId = String::number(id); 349 *heapSnapshotObjectId = String::number(id);
329 } 350 }
330 351
331 } // namespace WebCore 352 } // namespace WebCore
332 353
OLDNEW
« no previous file with comments | « LayoutTests/inspector/profiler/heap-snapshot-test.js ('k') | Source/devtools/front_end/HeapSnapshotView.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698