Loading core/java/com/android/internal/os/LongArrayMultiStateCounter.java +6 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.internal.os; import android.annotation.CheckResult; import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcelable; Loading Loading @@ -196,7 +197,8 @@ public final class LongArrayMultiStateCounter implements Parcelable { /** * Populates the array with the accumulated counts for the specified state. */ public void getCounts(long[] counts, int state) { @CheckResult public boolean getCounts(long[] counts, int state) { if (state < 0 || state >= mStateCount) { throw new IllegalArgumentException( "State: " + state + ", outside the range: [0-" + mStateCount + "]"); Loading @@ -205,7 +207,7 @@ public final class LongArrayMultiStateCounter implements Parcelable { throw new IllegalArgumentException( "Invalid array length: " + counts.length + ", expected: " + mLength); } native_getCounts(mNativeObject, counts, state); return native_getCounts(mNativeObject, counts, state); } @Override Loading Loading @@ -282,7 +284,8 @@ public final class LongArrayMultiStateCounter implements Parcelable { @FastNative @RavenwoodRedirect private static native void native_getCounts(long nativeObject, long[] counts, int state); @CheckResult private static native boolean native_getCounts(long nativeObject, long[] counts, int state); @FastNative @RavenwoodRedirect Loading core/java/com/android/internal/os/LongArrayMultiStateCounter_ravenwood.java +16 −4 Original line number Diff line number Diff line Loading @@ -168,8 +168,20 @@ class LongArrayMultiStateCounter_ravenwood { } } public void getValues(long[] values, int state) { System.arraycopy(mStates[state].mCounter, 0, values, 0, mArrayLength); public boolean getValues(long[] values, int state) { long[] counts = mStates[state].mCounter; boolean allZeros = true; for (int i = 0; i < counts.length; i++) { if (counts[i] != 0) { allZeros = false; break; } } if (allZeros) { return false; } System.arraycopy(counts, 0, values, 0, mArrayLength); return true; } public void reset() { Loading Loading @@ -316,8 +328,8 @@ class LongArrayMultiStateCounter_ravenwood { getInstance(instanceId).addCounts(counts); } public static void native_getCounts(long instanceId, long[] counts, int state) { getInstance(instanceId).getValues(counts, state); public static boolean native_getCounts(long instanceId, long[] counts, int state) { return getInstance(instanceId).getValues(counts, state); } public static void native_reset(long instanceId) { Loading core/jni/com_android_internal_os_LongArrayMultiStateCounter.cpp +17 −8 Original line number Diff line number Diff line Loading @@ -116,17 +116,26 @@ static void native_reset(jlong nativePtr) { counter->reset(); } static void native_getCounts(JNIEnv *env, jclass, jlong nativePtr, jlongArray values, jint state) { static bool native_getCounts(JNIEnv *env, jclass, jlong nativePtr, jlongArray values, jint state) { auto *counter = reinterpret_cast<LongArrayMultiStateCounter *>(nativePtr); ScopedLongArrayRW scopedArray(env, values); auto *data = counter->getCount(state).data(); auto size = env->GetArrayLength(values); auto *outData = scopedArray.get(); if (data == nullptr) { memset(outData, 0, size * sizeof(uint64_t)); } else { memcpy(outData, data, size * sizeof(uint64_t)); return false; } auto size = env->GetArrayLength(values); bool allZeros = true; for (int i = 0; i < size; i++) { if (data[i]) { allZeros = false; break; } } if (allZeros) { return false; } ScopedLongArrayRW scopedArray(env, values); memcpy(scopedArray.get(), data, size * sizeof(uint64_t)); return true; } static jobject native_toString(JNIEnv *env, jclass, jlong nativePtr) { Loading Loading @@ -255,7 +264,7 @@ static const JNINativeMethod g_LongArrayMultiStateCounter_methods[] = { // @CriticalNative {"native_reset", "(J)V", (void *)native_reset}, // @FastNative {"native_getCounts", "(J[JI)V", (void *)native_getCounts}, {"native_getCounts", "(J[JI)Z", (void *)native_getCounts}, // @FastNative {"native_toString", "(J)Ljava/lang/String;", (void *)native_toString}, // @FastNative Loading core/tests/coretests/src/com/android/internal/os/KernelSingleUidTimeReaderTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import android.annotation.SuppressLint; import android.platform.test.annotations.IgnoreUnderRavenwood; import android.platform.test.ravenwood.RavenwoodRule; import android.util.SparseArray; Loading Loading @@ -287,6 +288,7 @@ public class KernelSingleUidTimeReaderTest { 0, lastUidCpuTimes.size()); } @SuppressLint("CheckResult") @Test public void testAddDeltaFromBpf() { LongArrayMultiStateCounter counter = new LongArrayMultiStateCounter(2, 5); Loading core/tests/coretests/src/com/android/internal/os/LongArrayMultiStateCounterTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; import android.annotation.SuppressLint; import android.os.BadParcelableException; import android.os.Parcel; import android.platform.test.ravenwood.RavenwoodRule; Loading Loading @@ -176,6 +177,7 @@ public class LongArrayMultiStateCounterTest { assertCounts(newCounter, 0, new long[]{116, 232, 364, 528}); } @SuppressLint("CheckResult") private void assertCounts(LongArrayMultiStateCounter counter, int state, long[] expected) { long[] counts = new long[expected.length]; counter.getCounts(counts, state); Loading Loading
core/java/com/android/internal/os/LongArrayMultiStateCounter.java +6 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.internal.os; import android.annotation.CheckResult; import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcelable; Loading Loading @@ -196,7 +197,8 @@ public final class LongArrayMultiStateCounter implements Parcelable { /** * Populates the array with the accumulated counts for the specified state. */ public void getCounts(long[] counts, int state) { @CheckResult public boolean getCounts(long[] counts, int state) { if (state < 0 || state >= mStateCount) { throw new IllegalArgumentException( "State: " + state + ", outside the range: [0-" + mStateCount + "]"); Loading @@ -205,7 +207,7 @@ public final class LongArrayMultiStateCounter implements Parcelable { throw new IllegalArgumentException( "Invalid array length: " + counts.length + ", expected: " + mLength); } native_getCounts(mNativeObject, counts, state); return native_getCounts(mNativeObject, counts, state); } @Override Loading Loading @@ -282,7 +284,8 @@ public final class LongArrayMultiStateCounter implements Parcelable { @FastNative @RavenwoodRedirect private static native void native_getCounts(long nativeObject, long[] counts, int state); @CheckResult private static native boolean native_getCounts(long nativeObject, long[] counts, int state); @FastNative @RavenwoodRedirect Loading
core/java/com/android/internal/os/LongArrayMultiStateCounter_ravenwood.java +16 −4 Original line number Diff line number Diff line Loading @@ -168,8 +168,20 @@ class LongArrayMultiStateCounter_ravenwood { } } public void getValues(long[] values, int state) { System.arraycopy(mStates[state].mCounter, 0, values, 0, mArrayLength); public boolean getValues(long[] values, int state) { long[] counts = mStates[state].mCounter; boolean allZeros = true; for (int i = 0; i < counts.length; i++) { if (counts[i] != 0) { allZeros = false; break; } } if (allZeros) { return false; } System.arraycopy(counts, 0, values, 0, mArrayLength); return true; } public void reset() { Loading Loading @@ -316,8 +328,8 @@ class LongArrayMultiStateCounter_ravenwood { getInstance(instanceId).addCounts(counts); } public static void native_getCounts(long instanceId, long[] counts, int state) { getInstance(instanceId).getValues(counts, state); public static boolean native_getCounts(long instanceId, long[] counts, int state) { return getInstance(instanceId).getValues(counts, state); } public static void native_reset(long instanceId) { Loading
core/jni/com_android_internal_os_LongArrayMultiStateCounter.cpp +17 −8 Original line number Diff line number Diff line Loading @@ -116,17 +116,26 @@ static void native_reset(jlong nativePtr) { counter->reset(); } static void native_getCounts(JNIEnv *env, jclass, jlong nativePtr, jlongArray values, jint state) { static bool native_getCounts(JNIEnv *env, jclass, jlong nativePtr, jlongArray values, jint state) { auto *counter = reinterpret_cast<LongArrayMultiStateCounter *>(nativePtr); ScopedLongArrayRW scopedArray(env, values); auto *data = counter->getCount(state).data(); auto size = env->GetArrayLength(values); auto *outData = scopedArray.get(); if (data == nullptr) { memset(outData, 0, size * sizeof(uint64_t)); } else { memcpy(outData, data, size * sizeof(uint64_t)); return false; } auto size = env->GetArrayLength(values); bool allZeros = true; for (int i = 0; i < size; i++) { if (data[i]) { allZeros = false; break; } } if (allZeros) { return false; } ScopedLongArrayRW scopedArray(env, values); memcpy(scopedArray.get(), data, size * sizeof(uint64_t)); return true; } static jobject native_toString(JNIEnv *env, jclass, jlong nativePtr) { Loading Loading @@ -255,7 +264,7 @@ static const JNINativeMethod g_LongArrayMultiStateCounter_methods[] = { // @CriticalNative {"native_reset", "(J)V", (void *)native_reset}, // @FastNative {"native_getCounts", "(J[JI)V", (void *)native_getCounts}, {"native_getCounts", "(J[JI)Z", (void *)native_getCounts}, // @FastNative {"native_toString", "(J)Ljava/lang/String;", (void *)native_toString}, // @FastNative Loading
core/tests/coretests/src/com/android/internal/os/KernelSingleUidTimeReaderTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import android.annotation.SuppressLint; import android.platform.test.annotations.IgnoreUnderRavenwood; import android.platform.test.ravenwood.RavenwoodRule; import android.util.SparseArray; Loading Loading @@ -287,6 +288,7 @@ public class KernelSingleUidTimeReaderTest { 0, lastUidCpuTimes.size()); } @SuppressLint("CheckResult") @Test public void testAddDeltaFromBpf() { LongArrayMultiStateCounter counter = new LongArrayMultiStateCounter(2, 5); Loading
core/tests/coretests/src/com/android/internal/os/LongArrayMultiStateCounterTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertThrows; import android.annotation.SuppressLint; import android.os.BadParcelableException; import android.os.Parcel; import android.platform.test.ravenwood.RavenwoodRule; Loading Loading @@ -176,6 +177,7 @@ public class LongArrayMultiStateCounterTest { assertCounts(newCounter, 0, new long[]{116, 232, 364, 528}); } @SuppressLint("CheckResult") private void assertCounts(LongArrayMultiStateCounter counter, int state, long[] expected) { long[] counts = new long[expected.length]; counter.getCounts(counts, state); Loading