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

Commit 6c5c8abc authored by Marcin Oczeretko's avatar Marcin Oczeretko
Browse files

Change PerfettoTrigger throttling to be per trigger name

This is to allow us to collect more representative traces even if one of
the triggers is invoked more frequently than other.

Increased the throttling to be 5min per trigger name

Bug: 213920740
Test: manual - flashed and checked logcat
Change-Id: I078c640cc1e72c4ce8641b047fc90eb13bc8f2a4
parent 72a7e8b3
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.internal.util;

import android.os.SystemClock;
import android.util.Log;
import android.util.SparseLongArray;

import java.io.IOException;

@@ -28,8 +29,9 @@ import java.io.IOException;
public class PerfettoTrigger {
    private static final String TAG = "PerfettoTrigger";
    private static final String TRIGGER_COMMAND = "/system/bin/trigger_perfetto";
    private static final long THROTTLE_MILLIS = 60000;
    private static volatile long sLastTriggerTime = -THROTTLE_MILLIS;
    private static final long THROTTLE_MILLIS = 300000;
    private static final SparseLongArray sLastInvocationPerTrigger = new SparseLongArray(100);
    private static final Object sLock = new Object();

    /**
     * @param triggerName The name of the trigger. Must match the value defined in the AOT
@@ -38,18 +40,23 @@ public class PerfettoTrigger {
    public static void trigger(String triggerName) {
        // Trace triggering has a non-negligible cost (fork+exec).
        // To mitigate potential excessive triggering by the API client we ignore calls that happen
        // too quickl after the most recent trigger.
        long sinceLastTrigger = SystemClock.elapsedRealtime() - sLastTriggerTime;
        // too quickly after the most recent trigger.
        synchronized (sLock) {
            long lastTrigger = sLastInvocationPerTrigger.get(triggerName.hashCode());
            long sinceLastTrigger = SystemClock.elapsedRealtime() - lastTrigger;
            if (sinceLastTrigger < THROTTLE_MILLIS) {
            Log.v(TAG, "Not triggering " + triggerName + " - not enough time since last trigger");
                Log.v(TAG, "Not triggering " + triggerName
                        + " - not enough time since last trigger");
                return;
            }

            sLastInvocationPerTrigger.put(triggerName.hashCode(), SystemClock.elapsedRealtime());
        }

        try {
            ProcessBuilder pb = new ProcessBuilder(TRIGGER_COMMAND, triggerName);
            Log.v(TAG, "Triggering " + String.join(" ", pb.command()));
            pb.start();
            sLastTriggerTime = SystemClock.elapsedRealtime();
        } catch (IOException e) {
            Log.w(TAG, "Failed to trigger " + triggerName, e);
        }