Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2dcf64fa authored by Kevin Jeon's avatar Kevin Jeon
Browse files

Save sizes when dumping bitmaps

This change adds bitmap allocation sizes to the dumped information when
calling am dumpheap -b.

Test: check that bitmap sizes can be extracted from heap dumps
Bug: 412425223
Flag: com.android.traceur.flags.bitmaps_in_traceur
Change-Id: I34fc82b03c1003dd840824e4e0a1c14031b7abec
parent c58f3cdc
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -1575,6 +1575,7 @@ public final class Bitmap implements Parcelable {
        private int format;
        private long[] natives;
        private byte[][] buffers;
        private int[] sizes;
        private int max;

        public DumpData(@NonNull CompressFormat format, int max) {
@@ -1582,12 +1583,14 @@ public final class Bitmap implements Parcelable {
            this.format = format.nativeInt;
            this.natives = new long[max];
            this.buffers = new byte[max][];
            this.sizes = new int[max];
            this.count = 0;
        }

        public void add(long nativePtr, byte[] buffer) {
        public void add(long nativePtr, byte[] buffer, int size) {
            natives[count] = nativePtr;
            buffers[count] = buffer;
            sizes[count] = size;
            count = (count >= max) ? max : count + 1;
        }

@@ -1639,7 +1642,8 @@ public final class Bitmap implements Parcelable {
        for (Bitmap bitmap : allBitmaps) {
            ByteArrayOutputStream bas = new ByteArrayOutputStream();
            if (bitmap.compress(fmt, 90, bas)) {
                dumpData.add(bitmap.getNativeInstance(), bas.toByteArray());
                dumpData.add(bitmap.getNativeInstance(), bas.toByteArray(),
                        bitmap.getAllocationByteCount());
            }
        }
        Log.i(TAG, dumpData.size() + "/" + allBitmaps.size() + " bitmaps dumped");