ProfilerInfo.java revision ab8a63be6afc428a752828f9ea6423047cd27e42
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.app; 18 19import android.os.Parcel; 20import android.os.ParcelFileDescriptor; 21import android.os.Parcelable; 22import android.util.Slog; 23 24import java.io.IOException; 25 26/** 27 * System private API for passing profiler settings. 28 * 29 * {@hide} 30 */ 31public class ProfilerInfo implements Parcelable { 32 33 private static final String TAG = "ProfilerInfo"; 34 35 /* Name of profile output file. */ 36 public final String profileFile; 37 38 /* File descriptor for profile output file, can be null. */ 39 public ParcelFileDescriptor profileFd; 40 41 /* Indicates sample profiling when nonzero, interval in microseconds. */ 42 public final int samplingInterval; 43 44 /* Automatically stop the profiler when the app goes idle. */ 45 public final boolean autoStopProfiler; 46 47 /* 48 * Indicates whether to stream the profiling info to the out file continuously. 49 */ 50 public final boolean streamingOutput; 51 52 /** 53 * Denotes an agent (and its parameters) to attach for profiling. 54 */ 55 public final String agent; 56 57 /** 58 * Whether the {@link agent} should be attached early (before bind-application) or during 59 * bind-application. Agents attached prior to binding cannot be loaded from the app's APK 60 * directly and must be given as an absolute path (or available in the default LD_LIBRARY_PATH). 61 * Agents attached during bind-application will miss early setup (e.g., resource initialization 62 * and classloader generation), but are searched in the app's library search path. 63 */ 64 public final boolean attachAgentDuringBind; 65 66 public ProfilerInfo(String filename, ParcelFileDescriptor fd, int interval, boolean autoStop, 67 boolean streaming, String agent, boolean attachAgentDuringBind) { 68 profileFile = filename; 69 profileFd = fd; 70 samplingInterval = interval; 71 autoStopProfiler = autoStop; 72 streamingOutput = streaming; 73 this.agent = agent; 74 this.attachAgentDuringBind = attachAgentDuringBind; 75 } 76 77 public ProfilerInfo(ProfilerInfo in) { 78 profileFile = in.profileFile; 79 profileFd = in.profileFd; 80 samplingInterval = in.samplingInterval; 81 autoStopProfiler = in.autoStopProfiler; 82 streamingOutput = in.streamingOutput; 83 agent = in.agent; 84 attachAgentDuringBind = in.attachAgentDuringBind; 85 } 86 87 /** 88 * Close profileFd, if it is open. The field will be null after a call to this function. 89 */ 90 public void closeFd() { 91 if (profileFd != null) { 92 try { 93 profileFd.close(); 94 } catch (IOException e) { 95 Slog.w(TAG, "Failure closing profile fd", e); 96 } 97 profileFd = null; 98 } 99 } 100 101 @Override 102 public int describeContents() { 103 if (profileFd != null) { 104 return profileFd.describeContents(); 105 } else { 106 return 0; 107 } 108 } 109 110 @Override 111 public void writeToParcel(Parcel out, int flags) { 112 out.writeString(profileFile); 113 if (profileFd != null) { 114 out.writeInt(1); 115 profileFd.writeToParcel(out, flags); 116 } else { 117 out.writeInt(0); 118 } 119 out.writeInt(samplingInterval); 120 out.writeInt(autoStopProfiler ? 1 : 0); 121 out.writeInt(streamingOutput ? 1 : 0); 122 out.writeString(agent); 123 out.writeBoolean(attachAgentDuringBind); 124 } 125 126 public static final Parcelable.Creator<ProfilerInfo> CREATOR = 127 new Parcelable.Creator<ProfilerInfo>() { 128 @Override 129 public ProfilerInfo createFromParcel(Parcel in) { 130 return new ProfilerInfo(in); 131 } 132 133 @Override 134 public ProfilerInfo[] newArray(int size) { 135 return new ProfilerInfo[size]; 136 } 137 }; 138 139 private ProfilerInfo(Parcel in) { 140 profileFile = in.readString(); 141 profileFd = in.readInt() != 0 ? ParcelFileDescriptor.CREATOR.createFromParcel(in) : null; 142 samplingInterval = in.readInt(); 143 autoStopProfiler = in.readInt() != 0; 144 streamingOutput = in.readInt() != 0; 145 agent = in.readString(); 146 attachAgentDuringBind = in.readBoolean(); 147 } 148} 149