diff options
author | 2025-03-21 11:41:55 -0700 | |
---|---|---|
committer | 2025-03-21 11:41:55 -0700 | |
commit | 3f88505339cc7ba3c433211b86a2e85053974c86 (patch) | |
tree | f9e56110287033df4d4ec8c2ec3b88511ab27613 | |
parent | ff490d3619f4f9e648f2a6b0fda19c9dc351db8b (diff) | |
parent | e4d15d72e904359a7cc2a91eeb7b427919c709bd (diff) |
Merge "Move pendingJankStats check to JankUtils" into main
-rw-r--r-- | tests/AppJankTest/src/android/app/jank/tests/IntegrationTests.java | 29 | ||||
-rw-r--r-- | tests/AppJankTest/src/android/app/jank/tests/JankUtils.java | 23 |
2 files changed, 28 insertions, 24 deletions
diff --git a/tests/AppJankTest/src/android/app/jank/tests/IntegrationTests.java b/tests/AppJankTest/src/android/app/jank/tests/IntegrationTests.java index a08b650b4c2f..9c176cfe45e5 100644 --- a/tests/AppJankTest/src/android/app/jank/tests/IntegrationTests.java +++ b/tests/AppJankTest/src/android/app/jank/tests/IntegrationTests.java @@ -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(); @@ -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(); @@ -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(); diff --git a/tests/AppJankTest/src/android/app/jank/tests/JankUtils.java b/tests/AppJankTest/src/android/app/jank/tests/JankUtils.java index 7067b873d4b7..302cad11bbb9 100644 --- a/tests/AppJankTest/src/android/app/jank/tests/JankUtils.java +++ b/tests/AppJankTest/src/android/app/jank/tests/JankUtils.java @@ -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; @@ -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. + } + } + } } |