heapprofd allows you to attribute memory usage to functions for Android services and apps.
For documentation, see https://perfetto.dev/docs/data-sources/native-heap-profiler.
For design doc, see https://perfetto.dev/docs/design-docs/heapprofd-design.