frameworks/baseCopy HprofDumpDataSource.java to:
services/core/java/com/android/server/am/HprofDumpDataSource.java
In ActivityManagerService.java, add to the constructor or systemReady():
// In ActivityManagerService.java, after other Perfetto data sources are initialized: private HprofDumpDataSource mHprofDumpDataSource; // In systemReady() or start(): mHprofDumpDataSource = new HprofDumpDataSource(this);
This is the same pattern as WindowTracingDataSource which is created in WindowManagerService and registers itself with Perfetto in its constructor.
The data source writes to /data/local/tmp/perfetto_hprof/. This directory must be writable by system_server. On userdebug/eng builds this should work. For production, a dedicated directory with proper SELinux labels may be needed.
Add HprofDumpDataSource.java to the appropriate Android.bp or Android.mk for the services module.
adb shell perfetto -c - --txt <<EOF buffers { size_kb: 262144 } data_sources { config { name: "android.hprof_dump" } } duration_ms: 60000 EOF
AMS.dumpHeap() API -- no new system APIs needed