OLD | NEW |
---|---|
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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 } | 247 } |
248 } | 248 } |
249 | 249 |
250 void InspectorHeapProfilerAgent::removeProfile(ErrorString*, int rawUid) | 250 void InspectorHeapProfilerAgent::removeProfile(ErrorString*, int rawUid) |
251 { | 251 { |
252 unsigned uid = static_cast<unsigned>(rawUid); | 252 unsigned uid = static_cast<unsigned>(rawUid); |
253 if (m_snapshots.contains(uid)) | 253 if (m_snapshots.contains(uid)) |
254 m_snapshots.remove(uid); | 254 m_snapshots.remove(uid); |
255 } | 255 } |
256 | 256 |
257 void InspectorHeapProfilerAgent::takeHeapSnapshot(ErrorString*, const bool* repo rtProgress) | 257 void InspectorHeapProfilerAgent::takeHeapSnapshot(ErrorString* errorString, cons t bool* reportProgress) |
258 { | 258 { |
259 class HeapSnapshotProgress: public ScriptProfiler::HeapSnapshotProgress { | 259 class HeapSnapshotProgress: public ScriptProfiler::HeapSnapshotProgress { |
260 public: | 260 public: |
261 explicit HeapSnapshotProgress(InspectorFrontend::HeapProfiler* frontend) | 261 explicit HeapSnapshotProgress(InspectorFrontend::HeapProfiler* frontend) |
262 : m_frontend(frontend) { } | 262 : m_frontend(frontend) { } |
263 void Start(int totalWork) | 263 void Start(int totalWork) |
264 { | 264 { |
265 m_totalWork = totalWork; | 265 m_totalWork = totalWork; |
266 } | 266 } |
267 void Worked(int workDone) | 267 void Worked(int workDone) |
268 { | 268 { |
269 if (m_frontend) | 269 if (m_frontend) |
270 m_frontend->reportHeapSnapshotProgress(workDone, m_totalWork); | 270 m_frontend->reportHeapSnapshotProgress(workDone, m_totalWork, 0) ; |
271 } | 271 } |
272 void Done() { } | 272 void Done() |
273 { | |
274 const bool finished = true; | |
275 if (m_frontend) | |
276 m_frontend->reportHeapSnapshotProgress(m_totalWork, m_totalWork, &finished); | |
alph
2013/12/23 14:06:59
Do you really need to add this parameter?
Can't it
| |
277 } | |
273 bool isCanceled() { return false; } | 278 bool isCanceled() { return false; } |
274 private: | 279 private: |
275 InspectorFrontend::HeapProfiler* m_frontend; | 280 InspectorFrontend::HeapProfiler* m_frontend; |
276 int m_totalWork; | 281 int m_totalWork; |
277 }; | 282 }; |
278 | 283 |
279 String title = "Snapshot " + String::number(m_nextUserInitiatedHeapSnapshotN umber++); | 284 String title = "Snapshot " + String::number(m_nextUserInitiatedHeapSnapshotN umber++); |
280 HeapSnapshotProgress progress(reportProgress && *reportProgress ? m_frontend : 0); | 285 HeapSnapshotProgress progress(reportProgress && *reportProgress ? m_frontend : 0); |
281 RefPtr<ScriptHeapSnapshot> snapshot = ScriptProfiler::takeHeapSnapshot(title , &progress); | 286 RefPtr<ScriptHeapSnapshot> snapshot = ScriptProfiler::takeHeapSnapshot(title , &progress); |
282 if (snapshot) { | 287 if (!snapshot) { |
283 m_snapshots.add(snapshot->uid(), snapshot); | 288 *errorString = "Failed to take heap snapshot"; |
284 if (m_frontend) | 289 return; |
285 m_frontend->addProfileHeader(createSnapshotHeader(*snapshot)); | 290 } |
291 | |
292 class OutputStream : public ScriptHeapSnapshot::OutputStream { | |
293 public: | |
294 OutputStream(InspectorFrontend::HeapProfiler* frontend, unsigned uid) | |
295 : m_frontend(frontend), m_uid(uid) { } | |
296 void Write(const String& chunk) { m_frontend->addHeapSnapshotChunk(m_uid , chunk); } | |
297 void Close() { } | |
298 private: | |
299 InspectorFrontend::HeapProfiler* m_frontend; | |
300 int m_uid; | |
301 }; | |
302 | |
303 if (m_frontend) { | |
304 unsigned uid = static_cast<unsigned>(snapshot->uid()); | |
305 OutputStream stream(m_frontend, uid); | |
306 snapshot->writeJSON(&stream); | |
286 } | 307 } |
287 } | 308 } |
288 | 309 |
289 void InspectorHeapProfilerAgent::getObjectByHeapObjectId(ErrorString* error, con st String& heapSnapshotObjectId, const String* objectGroup, RefPtr<TypeBuilder:: Runtime::RemoteObject>& result) | 310 void InspectorHeapProfilerAgent::getObjectByHeapObjectId(ErrorString* error, con st String& heapSnapshotObjectId, const String* objectGroup, RefPtr<TypeBuilder:: Runtime::RemoteObject>& result) |
290 { | 311 { |
291 bool ok; | 312 bool ok; |
292 unsigned id = heapSnapshotObjectId.toUInt(&ok); | 313 unsigned id = heapSnapshotObjectId.toUInt(&ok); |
293 if (!ok) { | 314 if (!ok) { |
294 *error = "Invalid heap snapshot object id"; | 315 *error = "Invalid heap snapshot object id"; |
295 return; | 316 return; |
(...skipping 25 matching lines...) Expand all Loading... | |
321 if (value.hasNoValue() || value.isUndefined()) { | 342 if (value.hasNoValue() || value.isUndefined()) { |
322 *errorString = "Object with given id not found"; | 343 *errorString = "Object with given id not found"; |
323 return; | 344 return; |
324 } | 345 } |
325 unsigned id = ScriptProfiler::getHeapObjectId(value); | 346 unsigned id = ScriptProfiler::getHeapObjectId(value); |
326 *heapSnapshotObjectId = String::number(id); | 347 *heapSnapshotObjectId = String::number(id); |
327 } | 348 } |
328 | 349 |
329 } // namespace WebCore | 350 } // namespace WebCore |
330 | 351 |
OLD | NEW |