diff options
-rw-r--r-- | services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java | 49 | ||||
-rw-r--r-- | services/profcollect/src/com/android/server/profcollect/Utils.java | 52 |
2 files changed, 62 insertions, 39 deletions
diff --git a/services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java b/services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java index 8332b8b468c5..a4dfaa1a3801 100644 --- a/services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java +++ b/services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java @@ -275,26 +275,15 @@ public final class ProfcollectForwardingService extends SystemService { launchObserverRegistry.registerLaunchObserver(mAppLaunchObserver); } - private void traceOnAppStart(String packageName) { - if (mIProfcollect == null) { - return; - } - - if (Utils.withFrequency("applaunch_trace_freq", 2)) { - BackgroundThread.get().getThreadHandler().post(() -> { - try { - mIProfcollect.trace_system("applaunch"); - } catch (RemoteException e) { - Log.e(LOG_TAG, "Failed to initiate trace: " + e.getMessage()); - } - }); - } - } - private class AppLaunchObserver extends ActivityMetricsLaunchObserver { @Override public void onIntentStarted(Intent intent, long timestampNanos) { - traceOnAppStart(intent.getPackage()); + if (mIProfcollect == null) { + return; + } + if (Utils.withFrequency("applaunch_trace_freq", 2)) { + Utils.traceSystem(mIProfcollect, "applaunch"); + } } } @@ -316,13 +305,7 @@ public final class ProfcollectForwardingService extends SystemService { } if (Utils.withFrequency("dex2oat_trace_freq", 25)) { // Dex2oat could take a while before it starts. Add a short delay before start tracing. - BackgroundThread.get().getThreadHandler().postDelayed(() -> { - try { - mIProfcollect.trace_system("dex2oat"); - } catch (RemoteException e) { - Log.e(LOG_TAG, "Failed to initiate trace: " + e.getMessage()); - } - }, 1000); + Utils.traceSystem(mIProfcollect, "dex2oat", /* delayMs */ 1000); } } @@ -385,20 +368,10 @@ public final class ProfcollectForwardingService extends SystemService { return; } if (Utils.withFrequency("camera_trace_freq", 10)) { - final int traceDuration = 5000; - final String traceTag = "camera"; - BackgroundThread.get().getThreadHandler().post(() -> { - if (mIProfcollect == null) { - return; - } - try { - mIProfcollect.trace_process(traceTag, - "android.hardware.camera.provider", - traceDuration); - } catch (RemoteException e) { - Log.e(LOG_TAG, "Failed to initiate trace: " + e.getMessage()); - } - }); + Utils.traceProcess(mIProfcollect, + "camera", + "android.hardware.camera.provider", + /* durationMs */ 5000); } } }, null); diff --git a/services/profcollect/src/com/android/server/profcollect/Utils.java b/services/profcollect/src/com/android/server/profcollect/Utils.java index d5ef14c57b4c..850880256cfa 100644 --- a/services/profcollect/src/com/android/server/profcollect/Utils.java +++ b/services/profcollect/src/com/android/server/profcollect/Utils.java @@ -16,17 +16,67 @@ package com.android.server.profcollect; +import static com.android.server.profcollect.ProfcollectForwardingService.LOG_TAG; + +import android.os.RemoteException; import android.provider.DeviceConfig; +import android.util.Log; + +import com.android.internal.os.BackgroundThread; import java.util.concurrent.ThreadLocalRandom; public final class Utils { - public static boolean withFrequency(String configName, int defaultFrequency) { + public static boolean withFrequency(String configName, int defaultFrequency) { int threshold = DeviceConfig.getInt( DeviceConfig.NAMESPACE_PROFCOLLECT_NATIVE_BOOT, configName, defaultFrequency); int randomNum = ThreadLocalRandom.current().nextInt(100); return randomNum < threshold; } + public static boolean traceSystem(IProfCollectd mIProfcollect, String eventName) { + if (mIProfcollect == null) { + return false; + } + BackgroundThread.get().getThreadHandler().post(() -> { + try { + mIProfcollect.trace_system(eventName); + } catch (RemoteException e) { + Log.e(LOG_TAG, "Failed to initiate trace: " + e.getMessage()); + } + }); + return true; + } + + public static boolean traceSystem(IProfCollectd mIProfcollect, String eventName, int delayMs) { + if (mIProfcollect == null) { + return false; + } + BackgroundThread.get().getThreadHandler().postDelayed(() -> { + try { + mIProfcollect.trace_system(eventName); + } catch (RemoteException e) { + Log.e(LOG_TAG, "Failed to initiate trace: " + e.getMessage()); + } + }, delayMs); + return true; + } + + public static boolean traceProcess(IProfCollectd mIProfcollect, + String eventName, String processName, int durationMs) { + if (mIProfcollect == null) { + return false; + } + BackgroundThread.get().getThreadHandler().post(() -> { + try { + mIProfcollect.trace_process(eventName, + processName, + durationMs); + } catch (RemoteException e) { + Log.e(LOG_TAG, "Failed to initiate trace: " + e.getMessage()); + } + }); + return true; + } }
\ No newline at end of file |