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

Commit f280c6ab authored by Rafal Slawik's avatar Rafal Slawik
Browse files

Check if CPU time tracking is expected to work

Register the puller for CpuTimePerClusterFreq only if CPU time tracking
is supported. This avoid passing all zero times around and recording
"no data" state.

Depends on https://r.android.com/1566193

Bug: 174245730
Test: cmd stats pull-source 10095
Test: atest CpuStatsTests
Change-Id: Ifb3da84711b111eabc4af7a166dec794278b4a02
parent 173704e5
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -24,10 +24,7 @@ public final class KernelCpuTotalBpfMapReader {
    }

    /** Returns whether total CPU time is measured. */
    public static boolean isSupported() {
        // TODO(b/174245730): Implement this check.
        return true;
    }
    public static native boolean isSupported();

    /** Reads total CPU time from bpf map. */
    public static native boolean read(Callback callback);
+5 −0
Original line number Diff line number Diff line
@@ -20,6 +20,10 @@

namespace android {

static jboolean KernelCpuTotalBpfMapReader_isSupported(JNIEnv *, jobject) {
    return android::bpf::isTrackingUidTimesSupported() ? JNI_TRUE : JNI_FALSE;
}

static jboolean KernelCpuTotalBpfMapReader_read(JNIEnv *env, jobject, jobject callback) {
    jclass callbackClass = env->GetObjectClass(callback);
    jmethodID callbackMethod = env->GetMethodID(callbackClass, "accept", "(IIJ)V");
@@ -47,6 +51,7 @@ static jboolean KernelCpuTotalBpfMapReader_read(JNIEnv *env, jobject, jobject ca
static const JNINativeMethod methods[] = {
        {"read", "(Lcom/android/internal/os/KernelCpuTotalBpfMapReader$Callback;)Z",
         (void *)KernelCpuTotalBpfMapReader_read},
        {"isSupported", "()Z", (void *)KernelCpuTotalBpfMapReader_isSupported},
};

int register_com_android_internal_os_KernelCpuTotalBpfMapReader(JNIEnv *env) {