diff options
author | 2024-12-04 13:40:33 -0800 | |
---|---|---|
committer | 2024-12-04 13:40:40 -0800 | |
commit | 512e4239dd3bbd55943bb786b1d41eb2fb0367a7 (patch) | |
tree | 911ca0f4a2dfc0ea1f6f000fef582b423efb0660 | |
parent | 2a76c44a1ae6020e51b9c61e17bae4033d1063f3 (diff) |
Add ability to dump bitmaps with `android.os.Debug.dumpHprofData()`
Bug: 382275220
Flag: NONE - hidden internal debugging APIs
Change-Id: I70a25a071821ab95d69d6fd9d52815ab7fe50200
-rw-r--r-- | core/java/android/app/ActivityThread.java | 8 | ||||
-rw-r--r-- | core/java/android/os/Debug.java | 42 |
2 files changed, 43 insertions, 7 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 60b8f80d8f2d..70da92ca8b27 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -7039,12 +7039,9 @@ public final class ActivityThread extends ClientTransactionHandler System.runFinalization(); System.gc(); } - if (dhd.dumpBitmaps != null) { - Bitmap.dumpAll(dhd.dumpBitmaps); - } try (ParcelFileDescriptor fd = dhd.fd) { if (dhd.managed) { - Debug.dumpHprofData(dhd.path, fd.getFileDescriptor()); + Debug.dumpHprofData(dhd.path, fd.getFileDescriptor(), dhd.dumpBitmaps); } else if (dhd.mallocInfo) { Debug.dumpNativeMallocInfo(fd.getFileDescriptor()); } else { @@ -7069,9 +7066,6 @@ public final class ActivityThread extends ClientTransactionHandler if (dhd.finishCallback != null) { dhd.finishCallback.sendResult(null); } - if (dhd.dumpBitmaps != null) { - Bitmap.dumpAll(null); // clear dump - } } final void handleDispatchPackageBroadcast(int cmd, String[] packages) { diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java index ef1e6c9405f3..2bc6ab5a18e9 100644 --- a/core/java/android/os/Debug.java +++ b/core/java/android/os/Debug.java @@ -22,6 +22,7 @@ import android.annotation.Nullable; import android.app.AppGlobals; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; +import android.graphics.Bitmap; import android.util.Log; import com.android.internal.util.FastPrintWriter; @@ -2139,6 +2140,47 @@ public final class Debug } /** + * Like dumpHprofData(String), but takes an argument of bitmapFormat, + * which can be png, jpg, webp, or null (no bitmaps in heapdump). + * + * @hide + */ + public static void dumpHprofData(String fileName, String bitmapFormat) + throws IOException { + try { + if (bitmapFormat != null) { + Bitmap.dumpAll(bitmapFormat); + } + VMDebug.dumpHprofData(fileName); + } finally { + if (bitmapFormat != null) { + Bitmap.dumpAll(null); // clear dump data + } + } + } + + /** + * Like dumpHprofData(String, FileDescriptor), but takes an argument + * of bitmapFormat, which can be png, jpg, webp, or null (no bitmaps + * in heapdump). + * + * @hide + */ + public static void dumpHprofData(String fileName, FileDescriptor fd, + String bitmapFormat) throws IOException { + try { + if (bitmapFormat != null) { + Bitmap.dumpAll(bitmapFormat); + } + VMDebug.dumpHprofData(fileName, fd); + } finally { + if (bitmapFormat != null) { + Bitmap.dumpAll(null); // clear dump data + } + } + } + + /** * Collect "hprof" and send it to DDMS. This may cause a GC. * * @throws UnsupportedOperationException if the VM was built without |