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

Commit 89cf6d42 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "PerfettoTrigger: use SDK directly if available" into main

parents 1aae6420 55014087
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -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;

/**
@@ -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.
     */
@@ -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 {
@@ -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();
    }
}
+14 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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 {
@@ -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()));