From e849eae9a5b2339dc164c25d442bb793375e9b76 Mon Sep 17 00:00:00 2001 From: Shai Barack Date: Wed, 12 Feb 2025 04:09:48 -0800 Subject: Periodically GC and finalize during Collators alloc test. Bug: 394961590 Flag: EXEMPT benchmarks (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:378383c2d6f6b29227ba0b8ace8a22a5d575918b) Merged-In: I826dee7014f8fd3eb6698b5ad0183e29adf10b75 Change-Id: I826dee7014f8fd3eb6698b5ad0183e29adf10b75 --- .../regression/ExpensiveObjectsPerfTest.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/apct-tests/perftests/core/src/android/libcore/regression/ExpensiveObjectsPerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/ExpensiveObjectsPerfTest.java index ecbfc7169945..10ec2bfcb49a 100644 --- a/apct-tests/perftests/core/src/android/libcore/regression/ExpensiveObjectsPerfTest.java +++ b/apct-tests/perftests/core/src/android/libcore/regression/ExpensiveObjectsPerfTest.java @@ -75,8 +75,19 @@ public class ExpensiveObjectsPerfTest { @Test(timeout = 900000) public void timeNewCollator() { BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + int i = 0; while (state.keepRunning()) { Collator.getInstance(Locale.US); + + if (++i % 1000 == 0) { + state.pauseTiming(); + // GC and finalize occasionally to avoid GC for alloc and/or + // blocking on finalization during benchmark time. + // See: b/394961590 + System.gc(); + System.runFinalization(); + state.resumeTiming(); + } } } @@ -84,8 +95,19 @@ public class ExpensiveObjectsPerfTest { public void timeClonedCollator() { Collator c = Collator.getInstance(Locale.US); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + int i = 0; while (state.keepRunning()) { c.clone(); + + if (++i % 1000 == 0) { + state.pauseTiming(); + // GC and finalize occasionally to avoid GC for alloc and/or + // blocking on finalization during benchmark time. + // See: b/394961590 + System.gc(); + System.runFinalization(); + state.resumeTiming(); + } } } -- cgit v1.2.3-59-g8ed1b