Skip to content

Area for Improvement: Make it possible to programmatically trigger heap snapshots #54979

Open
@bkonyi

Description

@bkonyi

An interesting feature provided by Android is the ability to programmatically trigger the collection of a heap snapshot from within a running application. This gives developers the ability to collect the current state of the heap immediately before and after performing some operation, allowing for analysis of changes to the heap that occurred as a result of that operation.

While DevTools already provides the ability to inspect the diff between two heap snapshots, making this analysis workflow technically possible, it requires developers to manually trigger the heap snapshot from within DevTools. This manual interaction leaves time for the application to further manipulate the contents of the heap (e.g., perform garbage collection, allocate additional objects, etc.) before the snapshot can be collected, adding noise to the snapshot diff.

It should be relatively simple to add support for programmatically triggering heap snapshots from Dart code through a new ‘collectHeapSnapshot()’ API in dart:developer. This API would first check to see if any VM service clients were subscribed to the HeapSnapshot stream to avoid performing this expensive operation when no developer tooling is connected. Then, the heap snapshot would be collected and streamed to tooling.

With the support of the DevTools team, these streamed snapshots would be automatically added to the DevTools Diff Snapshot tool for viewing by the developer. An automatic snapshot event could also be added to the memory chart to give a visual indication as to when the snapshot was collected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.triagedIssue has been triaged by sub teamtype-enhancementA request for a change that isn't a bugvm-serviceThe VM Service Protocol, both the specification and its implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions