Merge changes I327b971f,Ie35e1fe7 into sc-dev

* changes:
  Update AOT trigger names to match the new convention
  Limit PerfettoTrigger to max 1 trigger per minute
This commit is contained in:
Marcin Oczeretko
2021-02-12 11:07:23 +00:00
committed by Android (Google) Code Review
3 changed files with 16 additions and 3 deletions

View File

@@ -499,7 +499,7 @@ public class InteractionJankMonitor {
}
public String getPerfettoTrigger() {
return String.format("interaction-jank-monitor-%d", mCujType);
return String.format("com.android.telemetry.interaction-jank-monitor-%d", mCujType);
}
public String getName() {

View File

@@ -219,7 +219,7 @@ public class LatencyTracker {
}
private static String getTraceTriggerNameForAction(@Action int action) {
return "latency-tracker-" + getNameOfAction(STATSD_ACTION[action]);
return "com.android.telemetry.latency-tracker-" + getNameOfAction(STATSD_ACTION[action]);
}
public static boolean isEnabled(Context ctx) {

View File

@@ -16,6 +16,7 @@
package com.android.internal.util;
import android.os.SystemClock;
import android.util.Log;
import java.io.IOException;
@@ -27,16 +28,28 @@ 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;
/**
* @param triggerName The name of the trigger. Must match the value defined in the AOT
* Perfetto config.
*/
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;
if (sinceLastTrigger < THROTTLE_MILLIS) {
Log.v(TAG, "Not triggering " + triggerName + " - not enough time since last trigger");
return;
}
try {
ProcessBuilder pb = new ProcessBuilder(TRIGGER_COMMAND, triggerName);
Log.v(TAG, "Triggering " + String.join(" ", pb.command()));
Process process = pb.start();
pb.start();
sLastTriggerTime = SystemClock.elapsedRealtime();
} catch (IOException e) {
Log.w(TAG, "Failed to trigger " + triggerName, e);
}