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

Commit 89e68fbe authored by Max Zhang's avatar Max Zhang
Browse files

replace VMDebug

VMDebug methods are @hide and can't be used in AppMemoryTest


Test: getting tests to pass locally, still not working on ABTD
Flag: EXEMPT TEST_ONLY
Bug: 443322661

Change-Id: Ibe3a0224df3578400c0744bd547895e1debe87c3
parent df0a89e2
Loading
Loading
Loading
Loading
+5 −2
Original line number Original line Diff line number Diff line
@@ -22,8 +22,11 @@
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>


    <application android:debuggable="true"
    <!-- debuggable="true" is required to be able to generate a heap profile. -->
               >
    <!-- testOnly="true" is required to be able to access "@hide" APIs such as VMDebug. -->
    <application
        android:debuggable="true"
        android:testOnly="true">
        <activity android:name=".EmptyActivity"
        <activity android:name=".EmptyActivity"
                  android:label="_EmptyActivity"
                  android:label="_EmptyActivity"
                  android:enabled="true"
                  android:enabled="true"
+2 −5
Original line number Original line Diff line number Diff line
@@ -23,8 +23,6 @@ import android.os.Debug;
import android.os.SystemClock;
import android.os.SystemClock;
import android.util.Log;
import android.util.Log;


import dalvik.system.VMDebug;

import org.apache.harmony.dalvik.ddmc.DdmVmInternal;
import org.apache.harmony.dalvik.ddmc.DdmVmInternal;


import java.io.File;
import java.io.File;
@@ -45,7 +43,6 @@ public class EmptyActivity extends Activity {
    // Configure for a heap dump
    // Configure for a heap dump


    private static void configureForHeap() {
    private static void configureForHeap() {
        VMDebug.setAllocTrackerStackDepth(64);
        DdmVmInternal.setRecentAllocationsTrackingEnabled(true);
        DdmVmInternal.setRecentAllocationsTrackingEnabled(true);
    }
    }


@@ -96,7 +93,7 @@ public class EmptyActivity extends Activity {
            }
            }
        }
        }


        final String allocated = VMDebug.getRuntimeStat("art.gc.bytes-allocated");
        final long  allocated = android.os.Debug.getGlobalAllocSize();


        try {
        try {
            Debug.dumpHprofData(dumpPath + ".hprof");
            Debug.dumpHprofData(dumpPath + ".hprof");
@@ -114,7 +111,7 @@ public class EmptyActivity extends Activity {
            // report generators to sequence statistics files from multiple runs on the same
            // report generators to sequence statistics files from multiple runs on the same
            // build.
            // build.
            out.format("memory.testhelper.runtime %d\n", System.currentTimeMillis() / 1000);
            out.format("memory.testhelper.runtime %d\n", System.currentTimeMillis() / 1000);
            out.format("art.gc.bytes-allocated %s\n", allocated);
            out.format("art.gc.bytes-allocated %d\n", allocated);
            out.format("extra-size.length %d\n", (mExtraBytes != null) ? mExtraBytes.length : 0);
            out.format("extra-size.length %d\n", (mExtraBytes != null) ? mExtraBytes.length : 0);
            out.format("sentinel.string %s\n", mSentinelString);
            out.format("sentinel.string %s\n", mSentinelString);
        } catch (FileNotFoundException e) {
        } catch (FileNotFoundException e) {
+5 −0
Original line number Original line Diff line number Diff line
@@ -64,6 +64,9 @@ public class AppMemoryTest {
        try (var result = new ParcelFileDescriptor.AutoCloseInputStream(pfd)) {
        try (var result = new ParcelFileDescriptor.AutoCloseInputStream(pfd)) {
            byte[] response = new byte[100];
            byte[] response = new byte[100];
            int len = result.read(response);
            int len = result.read(response);
            if (len <= 0) {
                return "";
            }
            return new String(response, 0, len);
            return new String(response, 0, len);
        } catch (IOException e) {
        } catch (IOException e) {
            // Ignore the exception.
            // Ignore the exception.
@@ -88,6 +91,7 @@ public class AppMemoryTest {


    @Before
    @Before
    public void setUp() {
    public void setUp() {
        runShellCommandWithResult("setprop debug.allocTracker.stackDepth 64");
        final String apk = mRootPath + HELPER_APK;
        final String apk = mRootPath + HELPER_APK;
        File apkFile = new File(apk);
        File apkFile = new File(apk);
        assertTrue("apk not found", apkFile.exists());
        assertTrue("apk not found", apkFile.exists());
@@ -99,6 +103,7 @@ public class AppMemoryTest {


    @After
    @After
    public void tearDown() {
    public void tearDown() {
        runShellCommandWithResult("setprop debug.allocTracker.stackDepth 16");
        uninstallHelper();
        uninstallHelper();
    }
    }