| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app; |
| 18 |
|
| 19 |
import android.annotation.Nullable; |
| 20 |
import android.os.Parcel; |
| 21 |
import android.os.ParcelFileDescriptor; |
| 22 |
import android.os.Parcelable; |
| 23 |
import android.util.Slog; |
| 24 |
import android.util.proto.ProtoOutputStream; |
| 25 |
|
| 26 |
import java.io.IOException; |
| 27 |
import java.util.Objects; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public class ProfilerInfo implements Parcelable { |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public static final int CLOCK_TYPE_DEFAULT = 0x000; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public static final int CLOCK_TYPE_WALL = 0x010; |
| 44 |
public static final int CLOCK_TYPE_THREAD_CPU = 0x100; |
| 45 |
public static final int CLOCK_TYPE_DUAL = 0x110; |
| 46 |
|
| 47 |
private static final String TAG = "ProfilerInfo"; |
| 48 |
|
| 49 |
|
| 50 |
public final String profileFile; |
| 51 |
|
| 52 |
|
| 53 |
public ParcelFileDescriptor profileFd; |
| 54 |
|
| 55 |
|
| 56 |
public final int samplingInterval; |
| 57 |
|
| 58 |
|
| 59 |
public final boolean autoStopProfiler; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public final boolean streamingOutput; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public final String agent; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public final boolean attachAgentDuringBind; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public final int clockType; |
| 85 |
|
| 86 |
public ProfilerInfo(String filename, ParcelFileDescriptor fd, int interval, boolean autoStop, |
| 87 |
boolean streaming, String agent, boolean attachAgentDuringBind, int clockType) { |
| 88 |
profileFile = filename; |
| 89 |
profileFd = fd; |
| 90 |
samplingInterval = interval; |
| 91 |
autoStopProfiler = autoStop; |
| 92 |
streamingOutput = streaming; |
| 93 |
this.clockType = clockType; |
| 94 |
this.agent = agent; |
| 95 |
this.attachAgentDuringBind = attachAgentDuringBind; |
| 96 |
} |
| 97 |
|
| 98 |
public ProfilerInfo(ProfilerInfo in) { |
| 99 |
profileFile = in.profileFile; |
| 100 |
profileFd = in.profileFd; |
| 101 |
samplingInterval = in.samplingInterval; |
| 102 |
autoStopProfiler = in.autoStopProfiler; |
| 103 |
streamingOutput = in.streamingOutput; |
| 104 |
agent = in.agent; |
| 105 |
attachAgentDuringBind = in.attachAgentDuringBind; |
| 106 |
clockType = in.clockType; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
public static int getClockTypeFromString(String type) { |
| 116 |
if ("thread-cpu".equals(type)) { |
| 117 |
return CLOCK_TYPE_THREAD_CPU; |
| 118 |
} else if ("wall".equals(type)) { |
| 119 |
return CLOCK_TYPE_WALL; |
| 120 |
} else if ("dual".equals(type)) { |
| 121 |
return CLOCK_TYPE_DUAL; |
| 122 |
} else { |
| 123 |
return CLOCK_TYPE_DEFAULT; |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
public ProfilerInfo setAgent(String agent, boolean attachAgentDuringBind) { |
| 132 |
return new ProfilerInfo(this.profileFile, this.profileFd, this.samplingInterval, |
| 133 |
this.autoStopProfiler, this.streamingOutput, agent, attachAgentDuringBind, |
| 134 |
this.clockType); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
public void closeFd() { |
| 141 |
if (profileFd != null) { |
| 142 |
try { |
| 143 |
profileFd.close(); |
| 144 |
} catch (IOException e) { |
| 145 |
Slog.w(TAG, "Failure closing profile fd", e); |
| 146 |
} |
| 147 |
profileFd = null; |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
@Override |
| 152 |
public int describeContents() { |
| 153 |
if (profileFd != null) { |
| 154 |
return profileFd.describeContents(); |
| 155 |
} else { |
| 156 |
return 0; |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
@Override |
| 161 |
public void writeToParcel(Parcel out, int flags) { |
| 162 |
out.writeString(profileFile); |
| 163 |
if (profileFd != null) { |
| 164 |
out.writeInt(1); |
| 165 |
profileFd.writeToParcel(out, flags); |
| 166 |
} else { |
| 167 |
out.writeInt(0); |
| 168 |
} |
| 169 |
out.writeInt(samplingInterval); |
| 170 |
out.writeInt(autoStopProfiler ? 1 : 0); |
| 171 |
out.writeInt(streamingOutput ? 1 : 0); |
| 172 |
out.writeString(agent); |
| 173 |
out.writeBoolean(attachAgentDuringBind); |
| 174 |
out.writeInt(clockType); |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
public void dumpDebug(ProtoOutputStream proto, long fieldId) { |
| 179 |
final long token = proto.start(fieldId); |
| 180 |
proto.write(ProfilerInfoProto.PROFILE_FILE, profileFile); |
| 181 |
if (profileFd != null) { |
| 182 |
proto.write(ProfilerInfoProto.PROFILE_FD, profileFd.getFd()); |
| 183 |
} |
| 184 |
proto.write(ProfilerInfoProto.SAMPLING_INTERVAL, samplingInterval); |
| 185 |
proto.write(ProfilerInfoProto.AUTO_STOP_PROFILER, autoStopProfiler); |
| 186 |
proto.write(ProfilerInfoProto.STREAMING_OUTPUT, streamingOutput); |
| 187 |
proto.write(ProfilerInfoProto.AGENT, agent); |
| 188 |
proto.write(ProfilerInfoProto.CLOCK_TYPE, clockType); |
| 189 |
proto.end(token); |
| 190 |
} |
| 191 |
|
| 192 |
public static final @android.annotation.NonNull Parcelable.Creator<ProfilerInfo> CREATOR = |
| 193 |
new Parcelable.Creator<ProfilerInfo>() { |
| 194 |
@Override |
| 195 |
public ProfilerInfo createFromParcel(Parcel in) { |
| 196 |
return new ProfilerInfo(in); |
| 197 |
} |
| 198 |
|
| 199 |
@Override |
| 200 |
public ProfilerInfo[] newArray(int size) { |
| 201 |
return new ProfilerInfo[size]; |
| 202 |
} |
| 203 |
}; |
| 204 |
|
| 205 |
private ProfilerInfo(Parcel in) { |
| 206 |
profileFile = in.readString(); |
| 207 |
profileFd = in.readInt() != 0 ? ParcelFileDescriptor.CREATOR.createFromParcel(in) : null; |
| 208 |
samplingInterval = in.readInt(); |
| 209 |
autoStopProfiler = in.readInt() != 0; |
| 210 |
streamingOutput = in.readInt() != 0; |
| 211 |
agent = in.readString(); |
| 212 |
attachAgentDuringBind = in.readBoolean(); |
| 213 |
clockType = in.readInt(); |
| 214 |
} |
| 215 |
|
| 216 |
@Override |
| 217 |
public boolean equals(@Nullable Object o) { |
| 218 |
if (this == o) { |
| 219 |
return true; |
| 220 |
} |
| 221 |
if (o == null || getClass() != o.getClass()) { |
| 222 |
return false; |
| 223 |
} |
| 224 |
final ProfilerInfo other = (ProfilerInfo) o; |
| 225 |
|
| 226 |
return Objects.equals(profileFile, other.profileFile) |
| 227 |
&& autoStopProfiler == other.autoStopProfiler |
| 228 |
&& samplingInterval == other.samplingInterval |
| 229 |
&& streamingOutput == other.streamingOutput |
| 230 |
&& Objects.equals(agent, other.agent) |
| 231 |
&& clockType == other.clockType; |
| 232 |
} |
| 233 |
|
| 234 |
@Override |
| 235 |
public int hashCode() { |
| 236 |
int result = 17; |
| 237 |
result = 31 * result + Objects.hashCode(profileFile); |
| 238 |
result = 31 * result + samplingInterval; |
| 239 |
result = 31 * result + (autoStopProfiler ? 1 : 0); |
| 240 |
result = 31 * result + (streamingOutput ? 1 : 0); |
| 241 |
result = 31 * result + Objects.hashCode(agent); |
| 242 |
result = 31 * result + clockType; |
| 243 |
return result; |
| 244 |
} |
| 245 |
} |