Bug 154407

Summary: Web Inspector: We should have a way to capture heap snapshots programatically.
Product: WebKit Reporter: Mark Lam <mark.lam>
Component: Web InspectorAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: bburg, commit-queue, dino, ggaren, graouts, joepeck, keith_miller, mark.lam, mattbaker, msaboff, nvasilyev, saam, timothy, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Local Build   
Hardware: All   
OS: All   
Bug Depends on:    
Bug Blocks: 10930    
Attachments:
Description Flags
[PATCH] Proposed Fix
none
[PATCH] Proposed Fix
timothy: review+
[PATCH] For Landing none

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>