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

Commit 500d40b6 authored by Zim's avatar Zim
Browse files

Fix check for whether a trace tag is enabled

With the introduction of libperfetto_tracing, we need to check both
perfetto track_events and atrace categories to determine if a trace
tag is enabled. Perfetto SDK doesn't expose a list (or bitmask) of
all enabled categories, but we can check if a specific category is
enabled.

Rewrote the internal impl for Trace#isTagEnabled to pass the tag into
native and return a boolean instead of getting all the enabled tags
from native and checking in Java.

Test: atest libtracing_perfetto_tests
Bug: 303199244
Change-Id: I4aa67bdcd86f15ec723955bb3619015fcb16063e
parent 7e37a4b0
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -125,15 +125,15 @@ public final class Trace {
    @UnsupportedAppUsage
    @CriticalNative
    @android.ravenwood.annotation.RavenwoodReplace
    private static native long nativeGetEnabledTags();
    private static native boolean nativeIsTagEnabled(long tag);
    @android.ravenwood.annotation.RavenwoodReplace
    private static native void nativeSetAppTracingAllowed(boolean allowed);
    @android.ravenwood.annotation.RavenwoodReplace
    private static native void nativeSetTracingEnabled(boolean allowed);

    private static long nativeGetEnabledTags$ravenwood() {
    private static boolean nativeIsTagEnabled$ravenwood(long traceTag) {
        // Tracing currently completely disabled under Ravenwood
        return 0;
        return false;
    }

    private static void nativeSetAppTracingAllowed$ravenwood(boolean allowed) {
@@ -181,8 +181,7 @@ public final class Trace {
    @UnsupportedAppUsage
    @SystemApi(client = MODULE_LIBRARIES)
    public static boolean isTagEnabled(long traceTag) {
        long tags = nativeGetEnabledTags();
        return (tags & traceTag) != 0;
        return nativeIsTagEnabled(traceTag);
    }

    /**
+3 −3
Original line number Diff line number Diff line
@@ -124,8 +124,8 @@ static void android_os_Trace_nativeInstantForTrack(JNIEnv* env, jclass,
    });
}

static jlong android_os_Trace_nativeGetEnabledTags(JNIEnv* env) {
    return tracing_perfetto::getEnabledCategories();
static jboolean android_os_Trace_nativeIsTagEnabled(JNIEnv* env, jlong tag) {
    return tracing_perfetto::isTagEnabled(tag);
}

static void android_os_Trace_nativeRegisterWithPerfetto(JNIEnv* env) {
@@ -157,7 +157,7 @@ static const JNINativeMethod gTraceMethods[] = {
        {"nativeRegisterWithPerfetto", "()V", (void*)android_os_Trace_nativeRegisterWithPerfetto},

        // ----------- @CriticalNative  ----------------
        {"nativeGetEnabledTags", "()J", (void*)android_os_Trace_nativeGetEnabledTags},
        {"nativeIsTagEnabled", "(J)Z", (void*)android_os_Trace_nativeIsTagEnabled},
};

int register_android_os_Trace(JNIEnv* env) {