Loading core/java/android/os/PerfettoTrace.java +15 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import dalvik.annotation.optimization.FastNative; import libcore.util.NativeAllocationRegistry; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; /** Loading Loading @@ -51,6 +52,8 @@ public final class PerfettoTrace { public static final boolean IS_USE_SDK_TRACING_API_V3 = IS_FLAG_ENABLED && android.os.Flags.perfettoSdkTracingV3(); private static final AtomicBoolean sAttemptedSystemRegistration = new AtomicBoolean(false); /** * For fetching the next flow event id in a process. */ Loading Loading @@ -380,6 +383,9 @@ public final class PerfettoTrace { /** Registers the process with Perfetto. */ @android.ravenwood.annotation.RavenwoodReplace public static void register(boolean isBackendInProcess) { if (!isBackendInProcess) { sAttemptedSystemRegistration.set(true); } if (IS_USE_SDK_TRACING_API_V3) { com.android.internal.dev.perfetto.sdk.PerfettoTrace.register(isBackendInProcess); } else { Loading @@ -406,4 +412,13 @@ public final class PerfettoTrace { public static void registerCategories$ravenwood() { // Tracing currently completely disabled under Ravenwood } /** * Returns whether the calling process attempted to register with the system backend of perfetto * by calling {@code register(false)}. A true return does not mean that the registration is * already completed, as that is an asynchronous operation. */ public static boolean getAttempedSystemRegistration() { return sAttemptedSystemRegistration.get(); } } core/java/com/android/internal/util/PerfettoTrigger.java +14 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.internal.util; import android.os.PerfettoTrace; import android.os.SystemClock; import android.util.Log; import android.util.SparseLongArray; Loading @@ -23,7 +24,13 @@ import android.util.SparseLongArray; import java.io.IOException; /** * A trigger implementation with perfetto backend. * Sends a named trigger to the central perfetto tracing service, which may activate or stop * preconfigured tracing. * * <p>The historical codepath is to fork-exec a system binary that performs the task. However, for * processes that are now registering with perfetto through the {@code PerfettoTrace} SDK, they can * use the SDK for sending the trigger. * * @hide */ public class PerfettoTrigger { Loading Loading @@ -53,6 +60,12 @@ public class PerfettoTrigger { sLastInvocationPerTrigger.put(triggerName.hashCode(), SystemClock.elapsedRealtime()); } // If we are registering with the SDK, use it directly. if (PerfettoTrace.getAttempedSystemRegistration()) { PerfettoTrace.activateTrigger(triggerName, 0); return; } try { ProcessBuilder pb = new ProcessBuilder(TRIGGER_COMMAND, triggerName); Log.v(TAG, "Triggering " + String.join(" ", pb.command())); Loading Loading
core/java/android/os/PerfettoTrace.java +15 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import dalvik.annotation.optimization.FastNative; import libcore.util.NativeAllocationRegistry; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; /** Loading Loading @@ -51,6 +52,8 @@ public final class PerfettoTrace { public static final boolean IS_USE_SDK_TRACING_API_V3 = IS_FLAG_ENABLED && android.os.Flags.perfettoSdkTracingV3(); private static final AtomicBoolean sAttemptedSystemRegistration = new AtomicBoolean(false); /** * For fetching the next flow event id in a process. */ Loading Loading @@ -380,6 +383,9 @@ public final class PerfettoTrace { /** Registers the process with Perfetto. */ @android.ravenwood.annotation.RavenwoodReplace public static void register(boolean isBackendInProcess) { if (!isBackendInProcess) { sAttemptedSystemRegistration.set(true); } if (IS_USE_SDK_TRACING_API_V3) { com.android.internal.dev.perfetto.sdk.PerfettoTrace.register(isBackendInProcess); } else { Loading @@ -406,4 +412,13 @@ public final class PerfettoTrace { public static void registerCategories$ravenwood() { // Tracing currently completely disabled under Ravenwood } /** * Returns whether the calling process attempted to register with the system backend of perfetto * by calling {@code register(false)}. A true return does not mean that the registration is * already completed, as that is an asynchronous operation. */ public static boolean getAttempedSystemRegistration() { return sAttemptedSystemRegistration.get(); } }
core/java/com/android/internal/util/PerfettoTrigger.java +14 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.internal.util; import android.os.PerfettoTrace; import android.os.SystemClock; import android.util.Log; import android.util.SparseLongArray; Loading @@ -23,7 +24,13 @@ import android.util.SparseLongArray; import java.io.IOException; /** * A trigger implementation with perfetto backend. * Sends a named trigger to the central perfetto tracing service, which may activate or stop * preconfigured tracing. * * <p>The historical codepath is to fork-exec a system binary that performs the task. However, for * processes that are now registering with perfetto through the {@code PerfettoTrace} SDK, they can * use the SDK for sending the trigger. * * @hide */ public class PerfettoTrigger { Loading Loading @@ -53,6 +60,12 @@ public class PerfettoTrigger { sLastInvocationPerTrigger.put(triggerName.hashCode(), SystemClock.elapsedRealtime()); } // If we are registering with the SDK, use it directly. if (PerfettoTrace.getAttempedSystemRegistration()) { PerfettoTrace.activateTrigger(triggerName, 0); return; } try { ProcessBuilder pb = new ProcessBuilder(TRIGGER_COMMAND, triggerName); Log.v(TAG, "Triggering " + String.join(" ", pb.command())); Loading