Merge "Fix "am profile" when run on system_server."

This commit is contained in:
Jeff Sharkey
2011-09-16 15:11:06 -07:00
committed by Android (Google) Code Review

View File

@@ -153,6 +153,7 @@ public final class ActivityThread {
final HashMap<IBinder, Service> mServices final HashMap<IBinder, Service> mServices
= new HashMap<IBinder, Service>(); = new HashMap<IBinder, Service>();
AppBindData mBoundApplication; AppBindData mBoundApplication;
Profiler mProfiler;
Configuration mConfiguration; Configuration mConfiguration;
Configuration mCompatConfiguration; Configuration mCompatConfiguration;
Configuration mResConfiguration; Configuration mResConfiguration;
@@ -364,10 +365,6 @@ public final class ActivityThread {
ApplicationInfo appInfo; ApplicationInfo appInfo;
List<ProviderInfo> providers; List<ProviderInfo> providers;
ComponentName instrumentationName; ComponentName instrumentationName;
String profileFile;
ParcelFileDescriptor profileFd;
boolean autoStopProfiler;
boolean profiling;
Bundle instrumentationArgs; Bundle instrumentationArgs;
IInstrumentationWatcher instrumentationWatcher; IInstrumentationWatcher instrumentationWatcher;
int debugMode; int debugMode;
@@ -375,10 +372,23 @@ public final class ActivityThread {
boolean persistent; boolean persistent;
Configuration config; Configuration config;
CompatibilityInfo compatInfo; CompatibilityInfo compatInfo;
boolean handlingProfiling;
/** Initial values for {@link Profiler}. */
String initProfileFile;
ParcelFileDescriptor initProfileFd;
boolean initAutoStopProfiler;
public String toString() { public String toString() {
return "AppBindData{appInfo=" + appInfo + "}"; return "AppBindData{appInfo=" + appInfo + "}";
} }
}
static final class Profiler {
String profileFile;
ParcelFileDescriptor profileFd;
boolean autoStopProfiler;
boolean profiling;
boolean handlingProfiling;
public void setProfiler(String file, ParcelFileDescriptor fd) { public void setProfiler(String file, ParcelFileDescriptor fd) {
if (profiling) { if (profiling) {
if (fd != null) { if (fd != null) {
@@ -661,8 +671,6 @@ public final class ActivityThread {
data.appInfo = appInfo; data.appInfo = appInfo;
data.providers = providers; data.providers = providers;
data.instrumentationName = instrumentationName; data.instrumentationName = instrumentationName;
data.setProfiler(profileFile, profileFd);
data.autoStopProfiler = false;
data.instrumentationArgs = instrumentationArgs; data.instrumentationArgs = instrumentationArgs;
data.instrumentationWatcher = instrumentationWatcher; data.instrumentationWatcher = instrumentationWatcher;
data.debugMode = debugMode; data.debugMode = debugMode;
@@ -670,6 +678,9 @@ public final class ActivityThread {
data.persistent = persistent; data.persistent = persistent;
data.config = config; data.config = config;
data.compatInfo = compatInfo; data.compatInfo = compatInfo;
data.initProfileFile = profileFile;
data.initProfileFd = profileFd;
data.initAutoStopProfiler = false;
queueOrSendMessage(H.BIND_APPLICATION, data); queueOrSendMessage(H.BIND_APPLICATION, data);
} }
@@ -1293,8 +1304,8 @@ public final class ActivityThread {
public final boolean queueIdle() { public final boolean queueIdle() {
ActivityClientRecord a = mNewActivities; ActivityClientRecord a = mNewActivities;
boolean stopProfiling = false; boolean stopProfiling = false;
if (mBoundApplication != null && mBoundApplication.profileFd != null if (mBoundApplication != null && mProfiler.profileFd != null
&& mBoundApplication.autoStopProfiler) { && mProfiler.autoStopProfiler) {
stopProfiling = true; stopProfiling = true;
} }
if (a != null) { if (a != null) {
@@ -1320,7 +1331,7 @@ public final class ActivityThread {
} while (a != null); } while (a != null);
} }
if (stopProfiling) { if (stopProfiling) {
mBoundApplication.stopProfiling(); mProfiler.stopProfiling();
} }
ensureJitEnabled(); ensureJitEnabled();
return false; return false;
@@ -1635,12 +1646,12 @@ public final class ActivityThread {
} }
public boolean isProfiling() { public boolean isProfiling() {
return mBoundApplication != null && mBoundApplication.profileFile != null return mProfiler != null && mProfiler.profileFile != null
&& mBoundApplication.profileFd == null; && mProfiler.profileFd == null;
} }
public String getProfileFilePath() { public String getProfileFilePath() {
return mBoundApplication.profileFile; return mProfiler.profileFile;
} }
public Looper getLooper() { public Looper getLooper() {
@@ -1679,6 +1690,9 @@ public final class ActivityThread {
ContextImpl context = getSystemContext(); ContextImpl context = getSystemContext();
context.init(new LoadedApk(this, "android", context, info, context.init(new LoadedApk(this, "android", context, info,
CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO), null, this); CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO), null, this);
// give ourselves a default profiler
mProfiler = new Profiler();
} }
} }
@@ -1947,9 +1961,9 @@ public final class ActivityThread {
unscheduleGcIdler(); unscheduleGcIdler();
if (r.profileFd != null) { if (r.profileFd != null) {
mBoundApplication.setProfiler(r.profileFile, r.profileFd); mProfiler.setProfiler(r.profileFile, r.profileFd);
mBoundApplication.startProfiling(); mProfiler.startProfiling();
mBoundApplication.autoStopProfiler = r.autoStopProfiler; mProfiler.autoStopProfiler = r.autoStopProfiler;
} }
if (localLOGV) Slog.v( if (localLOGV) Slog.v(
@@ -3571,9 +3585,9 @@ public final class ActivityThread {
ViewDebug.startLooperProfiling(pcd.path, pcd.fd.getFileDescriptor()); ViewDebug.startLooperProfiling(pcd.path, pcd.fd.getFileDescriptor());
break; break;
default: default:
mBoundApplication.setProfiler(pcd.path, pcd.fd); mProfiler.setProfiler(pcd.path, pcd.fd);
mBoundApplication.autoStopProfiler = false; mProfiler.autoStopProfiler = false;
mBoundApplication.startProfiling(); mProfiler.startProfiling();
break; break;
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
@@ -3592,7 +3606,7 @@ public final class ActivityThread {
ViewDebug.stopLooperProfiling(); ViewDebug.stopLooperProfiling();
break; break;
default: default:
mBoundApplication.stopProfiling(); mProfiler.stopProfiling();
break; break;
} }
} }
@@ -3685,6 +3699,11 @@ public final class ActivityThread {
mConfiguration = new Configuration(data.config); mConfiguration = new Configuration(data.config);
mCompatConfiguration = new Configuration(data.config); mCompatConfiguration = new Configuration(data.config);
mProfiler = new Profiler();
mProfiler.profileFile = data.initProfileFile;
mProfiler.profileFd = data.initProfileFd;
mProfiler.autoStopProfiler = data.initAutoStopProfiler;
// send up app name; do this *before* waiting for debugger // send up app name; do this *before* waiting for debugger
Process.setArgV0(data.processName); Process.setArgV0(data.processName);
android.ddm.DdmHandleAppName.setAppName(data.processName); android.ddm.DdmHandleAppName.setAppName(data.processName);
@@ -3699,8 +3718,8 @@ public final class ActivityThread {
} }
} }
if (data.profileFd != null) { if (mProfiler.profileFd != null) {
data.startProfiling(); mProfiler.startProfiling();
} }
// If the app is Honeycomb MR1 or earlier, switch its AsyncTask // If the app is Honeycomb MR1 or earlier, switch its AsyncTask
@@ -3841,10 +3860,10 @@ public final class ActivityThread {
mInstrumentation.init(this, instrContext, appContext, mInstrumentation.init(this, instrContext, appContext,
new ComponentName(ii.packageName, ii.name), data.instrumentationWatcher); new ComponentName(ii.packageName, ii.name), data.instrumentationWatcher);
if (data.profileFile != null && !ii.handleProfiling if (mProfiler.profileFile != null && !ii.handleProfiling
&& data.profileFd == null) { && mProfiler.profileFd == null) {
data.handlingProfiling = true; mProfiler.handlingProfiling = true;
File file = new File(data.profileFile); File file = new File(mProfiler.profileFile);
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
} }
@@ -3896,8 +3915,8 @@ public final class ActivityThread {
/*package*/ final void finishInstrumentation(int resultCode, Bundle results) { /*package*/ final void finishInstrumentation(int resultCode, Bundle results) {
IActivityManager am = ActivityManagerNative.getDefault(); IActivityManager am = ActivityManagerNative.getDefault();
if (mBoundApplication.profileFile != null && mBoundApplication.handlingProfiling if (mProfiler.profileFile != null && mProfiler.handlingProfiling
&& mBoundApplication.profileFd == null) { && mProfiler.profileFd == null) {
Debug.stopMethodTracing(); Debug.stopMethodTracing();
} }
//Slog.i(TAG, "am: " + ActivityManagerNative.getDefault() //Slog.i(TAG, "am: " + ActivityManagerNative.getDefault()