Bug 154407 - Web Inspector: We should have a way to capture heap snapshots programatically.
Summary: Web Inspector: We should have a way to capture heap snapshots programatically.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Local Build
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks: 10930
  Show dependency treegraph
 
Reported: 2016-02-18 12:50 PST by Mark Lam
Modified: 2016-03-29 11:58 PDT (History)
14 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (33.14 KB, patch)
2016-03-17 20:42 PDT, Joseph Pecoraro
no flags Details | Formatted Diff | Diff
[PATCH] Proposed Fix (39.45 KB, patch)
2016-03-17 21:06 PDT, Joseph Pecoraro
timothy: review+
Details | Formatted Diff | Diff
[PATCH] For Landing (39.30 KB, patch)
2016-03-29 11:00 PDT, Joseph Pecoraro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Lam 2016-02-18 12:50:13 PST
This will come in handy for web devs who need to profile memory usage or detect leaks as a result of executing a certain section of script code.

We should also be able to provide a description string to label the snapshot being taken.
Comment 1 Radar WebKit Bug Importer 2016-02-18 12:50:50 PST
<rdar://problem/24726292>
Comment 2 Joseph Pecoraro 2016-02-18 13:04:03 PST
I'd suggest something like:

    console.heapSnapshot(name);

Which is similar to how we do programmatic JavaScript profiles:

    console.profile(name)
    console.profileEnd(name)
Comment 3 Joseph Pecoraro 2016-02-22 15:11:24 PST
Looks like Microsoft already has:
<https://msdn.microsoft.com/en-us/library/windows/apps/jj819176(v=vs.120).aspx#SnapshotDetails>

    console.takeHeapSnapshot

So we can use that to be consistent!
Comment 4 Joseph Pecoraro 2016-03-17 20:42:03 PDT
Created attachment 274364 [details]
[PATCH] Proposed Fix

This adds console.takeHeapSnapshot. It will only work if:

1. The inspector is open
2. The inspector's Timeline tab has the Heap Allocations timeline (currently this is always)
NOTE: You do not need to be recording.

We may want to provide an alternative, like a Console Message that you can click on to show the snapshot Content View.
Comment 5 Joseph Pecoraro 2016-03-17 21:00:35 PDT
Mozilla bug for this:
Implement console.takeHeapSnapshot
https://bugzilla.mozilla.org/show_bug.cgi?id=960662

Chrome bug for this:
No JavaScript call to trigger a heap snapshot
https://bugs.chromium.org/p/chromium/issues/detail?id=31516
Comment 6 Joseph Pecoraro 2016-03-17 21:06:01 PDT
Created attachment 274366 [details]
[PATCH] Proposed Fix
Comment 7 Joseph Pecoraro 2016-03-29 11:00:48 PDT
Created attachment 275109 [details]
[PATCH] For Landing
Comment 8 WebKit Commit Bot 2016-03-29 11:51:34 PDT
Comment on attachment 275109 [details]
[PATCH] For Landing

Clearing flags on attachment: 275109

Committed r198786: <http://trac.webkit.org/changeset/198786>