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

Commit cde4d019 authored by Yisroel Forta's avatar Yisroel Forta
Browse files

Pass profiling triggers

Send profiling triggers from frameworks to ProfilingService.
- Send cold start trigger from onReportFullyDrawn
- Update AppStartInfoTracker#onActivityReportFullyDrawn to return accessed object
- Send anr trigger from AnrHelper after anr recognized
- Add new jarjar rules to f/b/services so dependency isn't duplicated

Test: trigger each type, confirm they're sent to service
Bug: 373461116
Flag: android.os.profiling.system_triggered_profiling_new
Change-Id: I7c47c5ca4fa8f2527fd3f005e5878093482104c5
parent a8ef53cc
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -239,6 +239,7 @@ java_library_static {
        "aconfig_new_storage_flags_lib",
        "powerstats_flags_lib",
        "locksettings_flags_lib",
        "profiling_flags_lib",
    ],
    javac_shard_size: 50,
    javacflags: [
@@ -254,6 +255,13 @@ java_library_static {
            "FlaggedApi",
        ],
    },
    jarjar_rules: ":services-jarjar-rules",
    apex_available: ["//apex_available:platform"],
}

filegroup {
    name: "services-jarjar-rules",
    srcs: ["services-jarjar-rules.txt"],
}

java_genrule {
+14 −1
Original line number Diff line number Diff line
@@ -336,6 +336,8 @@ import android.os.PowerManager;
import android.os.PowerManager.ServiceType;
import android.os.PowerManagerInternal;
import android.os.Process;
import android.os.ProfilingServiceHelper;
import android.os.ProfilingTrigger;
import android.os.RemoteCallback;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
@@ -1088,7 +1090,18 @@ public class ActivityManagerService extends IActivityManager.Stub
        @Override
        public void onReportFullyDrawn(long id, long timestampNanos) {
            mProcessList.getAppStartInfoTracker().onActivityReportFullyDrawn(id, timestampNanos);
            ApplicationStartInfo startInfo = mProcessList.getAppStartInfoTracker()
                    .onActivityReportFullyDrawn(id, timestampNanos);
            if (android.os.profiling.Flags.systemTriggeredProfilingNew()
                    && startInfo != null
                    && startInfo.getStartType() == ApplicationStartInfo.START_TYPE_COLD
                    && startInfo.getPackageName() != null) {
                ProfilingServiceHelper.getInstance().onProfilingTriggerOccurred(
                        startInfo.getRealUid(),
                        startInfo.getPackageName(),
                        ProfilingTrigger.TRIGGER_TYPE_APP_COLD_START_ACTIVITY);
            }
        }
    };
+11 −1
Original line number Diff line number Diff line
@@ -20,7 +20,8 @@ import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;

import android.content.pm.ApplicationInfo;
import android.os.Process;
import android.os.ProfilingServiceHelper;
import android.os.ProfilingTrigger;
import android.os.SystemClock;
import android.os.Trace;
import android.util.ArraySet;
@@ -240,6 +241,15 @@ class AnrHelper {
                        || startTime < SELF_ONLY_AFTER_BOOT_MS;
                r.appNotResponding(onlyDumpSelf);
                final long endTime = SystemClock.uptimeMillis();

                if (android.os.profiling.Flags.systemTriggeredProfilingNew() && r.mAppInfo != null
                        && r.mAppInfo.packageName != null) {
                    ProfilingServiceHelper.getInstance().onProfilingTriggerOccurred(
                            r.mUid,
                            r.mAppInfo.packageName,
                            ProfilingTrigger.TRIGGER_TYPE_ANR);
                }

                Slog.d(TAG, "Completed ANR of " + r.mApp.processName + " in "
                        + (endTime - startTime) + "ms, latency " + reportLatency
                        + (onlyDumpSelf ? "ms (expired, only dump ANR app)" : "ms"));
+7 −4
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ApplicationStartInfo;
import android.app.Flags;
import android.app.IApplicationStartInfoCompleteListener;
@@ -419,23 +420,25 @@ public final class AppStartInfoTracker {
     * Should only be called for Activity launch sequences from an instance of
     * {@link ActivityMetricsLaunchObserver}.
     */
    void onActivityReportFullyDrawn(long id, long timestampNanos) {
    @Nullable
    ApplicationStartInfo onActivityReportFullyDrawn(long id, long timestampNanos) {
        synchronized (mLock) {
            if (!mEnabled) {
                return;
                return null;
            }
            int index = mInProgressRecords.indexOfKey(id);
            if (index < 0) {
                return;
                return null;
            }
            ApplicationStartInfo info = mInProgressRecords.valueAt(index);
            if (info == null) {
                mInProgressRecords.removeAt(index);
                return;
                return null;
            }
            info.addStartupTimestamp(ApplicationStartInfo.START_TIMESTAMP_FULLY_DRAWN,
                    timestampNanos);
            mInProgressRecords.removeAt(index);
            return info;
        }
    }

+2 −0
Original line number Diff line number Diff line
# For profiling flags
rule android.os.profiling.** android.internal.os.profiling.@1