| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.util; |
| 18 |
|
| 19 |
import android.os.SystemClock; |
| 20 |
import android.util.Log; |
| 21 |
import android.util.SparseLongArray; |
| 22 |
|
| 23 |
import java.io.IOException; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public class PerfettoTrigger { |
| 30 |
private static final String TAG = "PerfettoTrigger"; |
| 31 |
private static final String TRIGGER_COMMAND = "/system/bin/trigger_perfetto"; |
| 32 |
private static final long THROTTLE_MILLIS = 300000; |
| 33 |
private static final SparseLongArray sLastInvocationPerTrigger = new SparseLongArray(100); |
| 34 |
private static final Object sLock = new Object(); |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public static void trigger(String triggerName) { |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
synchronized (sLock) { |
| 45 |
long lastTrigger = sLastInvocationPerTrigger.get(triggerName.hashCode()); |
| 46 |
long sinceLastTrigger = SystemClock.elapsedRealtime() - lastTrigger; |
| 47 |
if (sinceLastTrigger < THROTTLE_MILLIS) { |
| 48 |
Log.v(TAG, "Not triggering " + triggerName |
| 49 |
+ " - not enough time since last trigger"); |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
sLastInvocationPerTrigger.put(triggerName.hashCode(), SystemClock.elapsedRealtime()); |
| 54 |
} |
| 55 |
|
| 56 |
try { |
| 57 |
ProcessBuilder pb = new ProcessBuilder(TRIGGER_COMMAND, triggerName); |
| 58 |
Log.v(TAG, "Triggering " + String.join(" ", pb.command())); |
| 59 |
pb.start(); |
| 60 |
} catch (IOException e) { |
| 61 |
Log.w(TAG, "Failed to trigger " + triggerName, e); |
| 62 |
} |
| 63 |
} |
| 64 |
} |