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

Commit 83085bb3 authored by Andreas Gampe's avatar Andreas Gampe
Browse files

Frameworks: Add agent to ProfilerInfo

Add an agent option to ProfilerInfo. If set, on bindApplication
attempt to attach the given agent to the app before loading the
app itself.

Bug: 62445317
Test: m
Test: Device boots
Test: Manual profiling tests
Test: cts/hostsidetests/services/activityandwindowmanager/util/run-test CtsServicesHostTestCases android.server.cts.ActivityManagerAmProfileTests
Test: Manual agent test
Test: cts-tradefed run commandAndExit cts-dev --module CtsJvmtiAttachingHostTestCases
Change-Id: I1f0c4121e22351fd3a964dd0a915100a620d4f84
parent 2b073a0e
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -49,13 +49,19 @@ public class ProfilerInfo implements Parcelable {
     */
    public final boolean streamingOutput;

    /**
     * Denotes an agent (and its parameters) to attach for profiling.
     */
    public final String agent;

    public ProfilerInfo(String filename, ParcelFileDescriptor fd, int interval, boolean autoStop,
            boolean streaming) {
            boolean streaming, String agent) {
        profileFile = filename;
        profileFd = fd;
        samplingInterval = interval;
        autoStopProfiler = autoStop;
        streamingOutput = streaming;
        this.agent = agent;
    }

    public ProfilerInfo(ProfilerInfo in) {
@@ -64,6 +70,7 @@ public class ProfilerInfo implements Parcelable {
        samplingInterval = in.samplingInterval;
        autoStopProfiler = in.autoStopProfiler;
        streamingOutput = in.streamingOutput;
        agent = in.agent;
    }

    /**
@@ -101,6 +108,7 @@ public class ProfilerInfo implements Parcelable {
        out.writeInt(samplingInterval);
        out.writeInt(autoStopProfiler ? 1 : 0);
        out.writeInt(streamingOutput ? 1 : 0);
        out.writeString(agent);
    }

    public static final Parcelable.Creator<ProfilerInfo> CREATOR =
@@ -122,5 +130,6 @@ public class ProfilerInfo implements Parcelable {
        samplingInterval = in.readInt();
        autoStopProfiler = in.readInt() != 0;
        streamingOutput = in.readInt() != 0;
        agent = in.readString();
    }
}
+10 −1
Original line number Diff line number Diff line
@@ -6907,12 +6907,15 @@ public class ActivityManagerService extends IActivityManager.Stub
            }
            ProfilerInfo profilerInfo = null;
            String agent = null;
            if (mProfileApp != null && mProfileApp.equals(processName)) {
                mProfileProc = app;
                profilerInfo = (mProfilerInfo != null && mProfilerInfo.profileFile != null) ?
                        new ProfilerInfo(mProfilerInfo) : null;
                agent = profilerInfo.agent;
            } else if (app.instr != null && app.instr.mProfileFile != null) {
                profilerInfo = new ProfilerInfo(app.instr.mProfileFile, null, 0, false, false);
                profilerInfo = new ProfilerInfo(app.instr.mProfileFile, null, 0, false, false,
                        null);
            }
            boolean enableTrackAllocation = false;
@@ -6981,6 +6984,12 @@ public class ActivityManagerService extends IActivityManager.Stub
                }
            }
            // If we were asked to attach an agent on startup, do so now, before we're binding
            // application code.
            if (agent != null) {
                thread.attachAgent(agent);
            }
            checkTime(startTime, "attachApplicationLocked: immediately before bindApplication");
            mStackSupervisor.mActivityMetricsLogger.notifyBindApplication(app);
            if (app.instr != null) {
+14 −6
Original line number Diff line number Diff line
@@ -114,6 +114,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
    private int mSamplingInterval;
    private boolean mAutoStop;
    private boolean mStreaming;   // Streaming the profiling output to a file.
    private String mAgent;  // Agent to attach on startup.
    private int mDisplayId;
    private int mStackId;
    private int mTaskId;
@@ -292,6 +293,8 @@ final class ActivityManagerShellCommand extends ShellCommand {
                    mSamplingInterval = Integer.parseInt(getNextArgRequired());
                } else if (opt.equals("--streaming")) {
                    mStreaming = true;
                } else if (opt.equals("--attach-agent")) {
                    mAgent = getNextArgRequired();
                } else if (opt.equals("-R")) {
                    mRepeat = Integer.parseInt(getNextArgRequired());
                } else if (opt.equals("-S")) {
@@ -368,13 +371,16 @@ final class ActivityManagerShellCommand extends ShellCommand {

            ProfilerInfo profilerInfo = null;

            if (mProfileFile != null || mAgent != null) {
                ParcelFileDescriptor fd = null;
                if (mProfileFile != null) {
                ParcelFileDescriptor fd = openOutputFileForSystem(mProfileFile);
                    fd = openOutputFileForSystem(mProfileFile);
                    if (fd == null) {
                        return 1;
                    }
                }
                profilerInfo = new ProfilerInfo(mProfileFile, fd, mSamplingInterval, mAutoStop,
                                                mStreaming);
                        mStreaming, mAgent);
            }

            pw.println("Starting: " + intent);
@@ -747,7 +753,8 @@ final class ActivityManagerShellCommand extends ShellCommand {
            if (fd == null) {
                return -1;
            }
            profilerInfo = new ProfilerInfo(profileFile, fd, mSamplingInterval, false, mStreaming);
            profilerInfo = new ProfilerInfo(profileFile, fd, mSamplingInterval, false, mStreaming,
                    null);
        }

        try {
@@ -2490,6 +2497,7 @@ final class ActivityManagerShellCommand extends ShellCommand {
            pw.println("      --streaming: stream the profiling output to the specified file");
            pw.println("          (use with --start-profiler)");
            pw.println("      -P <FILE>: like above, but profiling stops when app goes idle");
            pw.println("      --attach-agent <agent>: attach the given agent before binding");
            pw.println("      -R: repeat the activity launch <COUNT> times.  Prior to each repeat,");
            pw.println("          the top activity will be finished.");
            pw.println("      -S: force stop the target app before starting the activity");