Loading tests/AppJankTest/src/android/app/jank/tests/IntegrationTests.java +5 −24 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ import java.util.HashMap; @RunWith(AndroidJUnit4.class) public class IntegrationTests { public static final int WAIT_FOR_TIMEOUT_MS = 5000; public static final int WAIT_FOR_PENDING_JANKSTATS_MS = 1000; @Rule public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); Loading Loading @@ -116,18 +117,8 @@ public class IntegrationTests { editText.reportAppJankStats(JankUtils.getAppJankStats()); // reportAppJankStats performs the work on a background thread, check periodically to see // if the work is complete. for (int i = 0; i < 10; i++) { try { Thread.sleep(100); if (jankTracker.getPendingJankStats().size() > 0) { break; } } catch (InterruptedException exception) { //do nothing and continue } } // wait until pending results are available. JankUtils.waitForResults(jankTracker, WAIT_FOR_PENDING_JANKSTATS_MS); pendingStats = jankTracker.getPendingJankStats(); Loading Loading @@ -247,18 +238,8 @@ public class IntegrationTests { int mismatchedAppUID = 25; editText.reportAppJankStats(JankUtils.getAppJankStats(mismatchedAppUID)); // reportAppJankStats performs the work on a background thread, check periodically to see // if the work is complete. for (int i = 0; i < 10; i++) { try { Thread.sleep(100); if (jankTracker.getPendingJankStats().size() > 0) { break; } } catch (InterruptedException exception) { //do nothing and continue } } // wait until pending results should be available. JankUtils.waitForResults(jankTracker, WAIT_FOR_PENDING_JANKSTATS_MS); pendingStats = jankTracker.getPendingJankStats(); Loading tests/AppJankTest/src/android/app/jank/tests/JankUtils.java +23 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.app.jank.tests; import android.app.jank.AppJankStats; import android.app.jank.JankTracker; import android.app.jank.RelativeFrameTimeHistogram; import android.os.Process; Loading Loading @@ -56,4 +57,26 @@ public class JankUtils { overrunHistogram.addRelativeFrameTimeMillis(25); return overrunHistogram; } /** * When JankStats are reported they are processed on a background thread. This method checks * every 100 ms up to the maxWaitTime to see if the pending stat count is greater than zero. * If the pending stat count is greater than zero it will return or keep trying until * maxWaitTime has elapsed. */ public static void waitForResults(JankTracker jankTracker, int maxWaitTimeMs) { int currentWaitTimeMs = 0; int threadSleepTimeMs = 100; while (currentWaitTimeMs < maxWaitTimeMs) { try { Thread.sleep(threadSleepTimeMs); if (!jankTracker.getPendingJankStats().isEmpty()) { return; } currentWaitTimeMs += threadSleepTimeMs; } catch (InterruptedException exception) { // do nothing and continue. } } } } Loading
tests/AppJankTest/src/android/app/jank/tests/IntegrationTests.java +5 −24 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ import java.util.HashMap; @RunWith(AndroidJUnit4.class) public class IntegrationTests { public static final int WAIT_FOR_TIMEOUT_MS = 5000; public static final int WAIT_FOR_PENDING_JANKSTATS_MS = 1000; @Rule public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); Loading Loading @@ -116,18 +117,8 @@ public class IntegrationTests { editText.reportAppJankStats(JankUtils.getAppJankStats()); // reportAppJankStats performs the work on a background thread, check periodically to see // if the work is complete. for (int i = 0; i < 10; i++) { try { Thread.sleep(100); if (jankTracker.getPendingJankStats().size() > 0) { break; } } catch (InterruptedException exception) { //do nothing and continue } } // wait until pending results are available. JankUtils.waitForResults(jankTracker, WAIT_FOR_PENDING_JANKSTATS_MS); pendingStats = jankTracker.getPendingJankStats(); Loading Loading @@ -247,18 +238,8 @@ public class IntegrationTests { int mismatchedAppUID = 25; editText.reportAppJankStats(JankUtils.getAppJankStats(mismatchedAppUID)); // reportAppJankStats performs the work on a background thread, check periodically to see // if the work is complete. for (int i = 0; i < 10; i++) { try { Thread.sleep(100); if (jankTracker.getPendingJankStats().size() > 0) { break; } } catch (InterruptedException exception) { //do nothing and continue } } // wait until pending results should be available. JankUtils.waitForResults(jankTracker, WAIT_FOR_PENDING_JANKSTATS_MS); pendingStats = jankTracker.getPendingJankStats(); Loading
tests/AppJankTest/src/android/app/jank/tests/JankUtils.java +23 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.app.jank.tests; import android.app.jank.AppJankStats; import android.app.jank.JankTracker; import android.app.jank.RelativeFrameTimeHistogram; import android.os.Process; Loading Loading @@ -56,4 +57,26 @@ public class JankUtils { overrunHistogram.addRelativeFrameTimeMillis(25); return overrunHistogram; } /** * When JankStats are reported they are processed on a background thread. This method checks * every 100 ms up to the maxWaitTime to see if the pending stat count is greater than zero. * If the pending stat count is greater than zero it will return or keep trying until * maxWaitTime has elapsed. */ public static void waitForResults(JankTracker jankTracker, int maxWaitTimeMs) { int currentWaitTimeMs = 0; int threadSleepTimeMs = 100; while (currentWaitTimeMs < maxWaitTimeMs) { try { Thread.sleep(threadSleepTimeMs); if (!jankTracker.getPendingJankStats().isEmpty()) { return; } currentWaitTimeMs += threadSleepTimeMs; } catch (InterruptedException exception) { // do nothing and continue. } } } }