summaryrefslogtreecommitdiff
path: root/core/java/android/app/ProfilerInfo.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/app/ProfilerInfo.java')
-rw-r--r--core/java/android/app/ProfilerInfo.java44
1 files changed, 38 insertions, 6 deletions
diff --git a/core/java/android/app/ProfilerInfo.java b/core/java/android/app/ProfilerInfo.java
index f7a3d78af207..bcae22a38f9e 100644
--- a/core/java/android/app/ProfilerInfo.java
+++ b/core/java/android/app/ProfilerInfo.java
@@ -32,7 +32,8 @@ import java.util.Objects;
* {@hide}
*/
public class ProfilerInfo implements Parcelable {
-
+ // Version of the profiler output
+ public static final int OUTPUT_VERSION_DEFAULT = 1;
// CLOCK_TYPE_DEFAULT chooses the default used by ART. ART uses CLOCK_TYPE_DUAL by default (see
// kDefaultTraceClockSource in art/runtime/runtime_globals.h).
public static final int CLOCK_TYPE_DEFAULT = 0x000;
@@ -43,6 +44,9 @@ public class ProfilerInfo implements Parcelable {
public static final int CLOCK_TYPE_WALL = 0x010;
public static final int CLOCK_TYPE_THREAD_CPU = 0x100;
public static final int CLOCK_TYPE_DUAL = 0x110;
+ // The second and third bits of the flags field specify the trace format version. This should
+ // match with kTraceFormatVersionShift defined in art/runtime/trace.h.
+ public static final int TRACE_FORMAT_VERSION_SHIFT = 1;
private static final String TAG = "ProfilerInfo";
@@ -83,8 +87,14 @@ public class ProfilerInfo implements Parcelable {
*/
public final int clockType;
+ /**
+ * Indicates the version of profiler output.
+ */
+ public final int profilerOutputVersion;
+
public ProfilerInfo(String filename, ParcelFileDescriptor fd, int interval, boolean autoStop,
- boolean streaming, String agent, boolean attachAgentDuringBind, int clockType) {
+ boolean streaming, String agent, boolean attachAgentDuringBind, int clockType,
+ int profilerOutputVersion) {
profileFile = filename;
profileFd = fd;
samplingInterval = interval;
@@ -93,6 +103,7 @@ public class ProfilerInfo implements Parcelable {
this.clockType = clockType;
this.agent = agent;
this.attachAgentDuringBind = attachAgentDuringBind;
+ this.profilerOutputVersion = profilerOutputVersion;
}
public ProfilerInfo(ProfilerInfo in) {
@@ -104,6 +115,7 @@ public class ProfilerInfo implements Parcelable {
agent = in.agent;
attachAgentDuringBind = in.attachAgentDuringBind;
clockType = in.clockType;
+ profilerOutputVersion = in.profilerOutputVersion;
}
/**
@@ -125,13 +137,29 @@ public class ProfilerInfo implements Parcelable {
}
/**
+ * Get the flags that need to be passed to VMDebug.startMethodTracing to specify the desired
+ * output format.
+ */
+ public static int getFlagsForOutputVersion(int version) {
+ // Only two version 1 and version 2 are supported. Just use the default if we see an unknown
+ // version.
+ if (version != 1 || version != 2) {
+ version = OUTPUT_VERSION_DEFAULT;
+ }
+
+ // The encoded version in the flags starts from 0, where as the version that we read from
+ // user starts from 1. So, subtract one before encoding it in the flags.
+ return (version - 1) << TRACE_FORMAT_VERSION_SHIFT;
+ }
+
+ /**
* Return a new ProfilerInfo instance, with fields populated from this object,
* and {@link agent} and {@link attachAgentDuringBind} as given.
*/
public ProfilerInfo setAgent(String agent, boolean attachAgentDuringBind) {
return new ProfilerInfo(this.profileFile, this.profileFd, this.samplingInterval,
this.autoStopProfiler, this.streamingOutput, agent, attachAgentDuringBind,
- this.clockType);
+ this.clockType, this.profilerOutputVersion);
}
/**
@@ -172,6 +200,7 @@ public class ProfilerInfo implements Parcelable {
out.writeString(agent);
out.writeBoolean(attachAgentDuringBind);
out.writeInt(clockType);
+ out.writeInt(profilerOutputVersion);
}
/** @hide */
@@ -186,6 +215,7 @@ public class ProfilerInfo implements Parcelable {
proto.write(ProfilerInfoProto.STREAMING_OUTPUT, streamingOutput);
proto.write(ProfilerInfoProto.AGENT, agent);
proto.write(ProfilerInfoProto.CLOCK_TYPE, clockType);
+ proto.write(ProfilerInfoProto.PROFILER_OUTPUT_VERSION, profilerOutputVersion);
proto.end(token);
}
@@ -211,6 +241,7 @@ public class ProfilerInfo implements Parcelable {
agent = in.readString();
attachAgentDuringBind = in.readBoolean();
clockType = in.readInt();
+ profilerOutputVersion = in.readInt();
}
@Override
@@ -226,9 +257,9 @@ public class ProfilerInfo implements Parcelable {
return Objects.equals(profileFile, other.profileFile)
&& autoStopProfiler == other.autoStopProfiler
&& samplingInterval == other.samplingInterval
- && streamingOutput == other.streamingOutput
- && Objects.equals(agent, other.agent)
- && clockType == other.clockType;
+ && streamingOutput == other.streamingOutput && Objects.equals(agent, other.agent)
+ && clockType == other.clockType
+ && profilerOutputVersion == other.profilerOutputVersion;
}
@Override
@@ -240,6 +271,7 @@ public class ProfilerInfo implements Parcelable {
result = 31 * result + (streamingOutput ? 1 : 0);
result = 31 * result + Objects.hashCode(agent);
result = 31 * result + clockType;
+ result = 31 * result + profilerOutputVersion;
return result;
}
}