dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.19k stars 1.57k forks source link

Area for Improvement: Investigate adding support for heap allocation profiling to the standalone VM #50775

Open bkonyi opened 1 year ago

bkonyi commented 1 year ago

One of the main gaps between the memory tooling provided by DevTools and Android Studio, XCode, and Instruments is the lack of a general purpose allocation profiler. These profilers can either record all allocations made in the target process (known as a tracing profiler) or only record samples of allocations based on some sampling rate (known as a sampling profiler). Both types of allocation profilers give developers an idea of what types of objects currently exist on the heap while also informing them of call sites that are allocating the most memory.

The Dart VM already provides support for embedders to enable a sampling heap profiler, and this functionality is currently used by the Gallium team to debug memory issues in their production servers, but this functionality isn’t made available through the VM service. Adding allocation profiling support to the VM service would involve wiring up the sampling heap profiler in the VM so that it could write allocation samples to a sample buffer, similar to how the Dart VM’s CPU profiler works. DevTools would need to add a new tab to the memory screen capable of requesting the allocation profile from the VM service. This tool would be very similar to the CPU Profiler and would likely reuse much of the CPU profiler’s UI elements.

Although most of the functionality needed to provide allocation profiling in DevTools is available in some form, there’s likely still a good amount of work that needs to be done to ship this feature to users. Also, since other DevTools tooling provides lightweight options for inspecting high-level heap contents through the “Profile Memory” tool as well a way to trace allocations of specific types using the “Trace Instances” tool, it’s unclear that adding a dedicated allocation profiler will provide enough benefit to warrant the engineering effort. Further discussions with the DevTools and VM teams should happen to determine if this feature is worth investing in.

Original Issue

The Dart VM provides a mechanism to sample Dart heap allocations through a C API, but does not provide any support for sampling allocations out of the box. We should hook up the sampling profiler in the VM and provide support for accessing it through the VM service protocol.

a-siva commented 1 year ago

Can this be closed as done?

bkonyi commented 7 months ago

Can this be closed as done?

This is still an open issue since the standalone VM doesn't support heap allocation profiling. We'd have to configure it and make it available through the service protocol.