Loading services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java +11 −38 Original line number Diff line number Diff line Loading @@ -275,26 +275,15 @@ public final class ProfcollectForwardingService extends SystemService { launchObserverRegistry.registerLaunchObserver(mAppLaunchObserver); } private void traceOnAppStart(String packageName) { private class AppLaunchObserver extends ActivityMetricsLaunchObserver { @Override public void onIntentStarted(Intent intent, long timestampNanos) { 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()); Utils.traceSystem(mIProfcollect, "applaunch"); } }); } } private class AppLaunchObserver extends ActivityMetricsLaunchObserver { @Override public void onIntentStarted(Intent intent, long timestampNanos) { traceOnAppStart(intent.getPackage()); } } Loading @@ -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); } } Loading Loading @@ -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, Utils.traceProcess(mIProfcollect, "camera", "android.hardware.camera.provider", traceDuration); } catch (RemoteException e) { Log.e(LOG_TAG, "Failed to initiate trace: " + e.getMessage()); } }); /* durationMs */ 5000); } } }, null); Loading services/profcollect/src/com/android/server/profcollect/Utils.java +51 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,13 @@ 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; Loading @@ -29,4 +35,48 @@ public final class Utils { 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 Loading
services/profcollect/src/com/android/server/profcollect/ProfcollectForwardingService.java +11 −38 Original line number Diff line number Diff line Loading @@ -275,26 +275,15 @@ public final class ProfcollectForwardingService extends SystemService { launchObserverRegistry.registerLaunchObserver(mAppLaunchObserver); } private void traceOnAppStart(String packageName) { private class AppLaunchObserver extends ActivityMetricsLaunchObserver { @Override public void onIntentStarted(Intent intent, long timestampNanos) { 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()); Utils.traceSystem(mIProfcollect, "applaunch"); } }); } } private class AppLaunchObserver extends ActivityMetricsLaunchObserver { @Override public void onIntentStarted(Intent intent, long timestampNanos) { traceOnAppStart(intent.getPackage()); } } Loading @@ -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); } } Loading Loading @@ -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, Utils.traceProcess(mIProfcollect, "camera", "android.hardware.camera.provider", traceDuration); } catch (RemoteException e) { Log.e(LOG_TAG, "Failed to initiate trace: " + e.getMessage()); } }); /* durationMs */ 5000); } } }, null); Loading
services/profcollect/src/com/android/server/profcollect/Utils.java +51 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,13 @@ 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; Loading @@ -29,4 +35,48 @@ public final class Utils { 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