diff options
Diffstat (limited to 'core/java/android/app')
-rw-r--r-- | core/java/android/app/ActivityManagerNative.java | 29 | ||||
-rw-r--r-- | core/java/android/app/ActivityThread.java | 24 | ||||
-rw-r--r-- | core/java/android/app/ApplicationThreadNative.java | 18 | ||||
-rw-r--r-- | core/java/android/app/IActivityManager.java | 5 | ||||
-rw-r--r-- | core/java/android/app/IApplicationThread.java | 2 |
5 files changed, 78 insertions, 0 deletions
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java index f11dbec..53e6f34 100644 --- a/core/java/android/app/ActivityManagerNative.java +++ b/core/java/android/app/ActivityManagerNative.java @@ -979,6 +979,17 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM return true; } + case PROFILE_CONTROL_TRANSACTION: { + data.enforceInterface(IActivityManager.descriptor); + String process = data.readString(); + boolean start = data.readInt() != 0; + String path = data.readString(); + boolean res = profileControl(process, start, path); + reply.writeNoException(); + reply.writeInt(res ? 1 : 0); + return true; + } + case PEEK_SERVICE_TRANSACTION: { data.enforceInterface(IActivityManager.descriptor); Intent service = Intent.CREATOR.createFromParcel(data); @@ -2131,5 +2142,23 @@ class ActivityManagerProxy implements IActivityManager data.recycle(); return res; } + + public boolean profileControl(String process, boolean start, + String path) throws RemoteException + { + Parcel data = Parcel.obtain(); + Parcel reply = Parcel.obtain(); + data.writeInterfaceToken(IActivityManager.descriptor); + data.writeString(process); + data.writeInt(start ? 1 : 0); + data.writeString(path); + mRemote.transact(PROFILE_CONTROL_TRANSACTION, data, reply, 0); + reply.readException(); + boolean res = reply.readInt() != 0; + reply.recycle(); + data.recycle(); + return res; + } + private IBinder mRemote; } diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index bf5616e..f49005e 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -1449,6 +1449,10 @@ public final class ActivityThread { } } + public void profilerControl(boolean start, String path) { + queueOrSendMessage(H.PROFILER_CONTROL, path, start ? 1 : 0); + } + @Override protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { long nativeMax = Debug.getNativeHeapSize() / 1024; @@ -1641,6 +1645,7 @@ public final class ActivityThread { public static final int LOW_MEMORY = 124; public static final int ACTIVITY_CONFIGURATION_CHANGED = 125; public static final int RELAUNCH_ACTIVITY = 126; + public static final int PROFILER_CONTROL = 127; String codeToString(int code) { if (localLOGV) { switch (code) { @@ -1671,6 +1676,7 @@ public final class ActivityThread { case LOW_MEMORY: return "LOW_MEMORY"; case ACTIVITY_CONFIGURATION_CHANGED: return "ACTIVITY_CONFIGURATION_CHANGED"; case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY"; + case PROFILER_CONTROL: return "PROFILER_CONTROL"; } } return "(unknown)"; @@ -1770,6 +1776,9 @@ public final class ActivityThread { case ACTIVITY_CONFIGURATION_CHANGED: handleActivityConfigurationChanged((IBinder)msg.obj); break; + case PROFILER_CONTROL: + handleProfilerControl(msg.arg1 != 0, (String)msg.obj); + break; } } } @@ -3432,6 +3441,21 @@ public final class ActivityThread { performConfigurationChanged(r.activity, mConfiguration); } + final void handleProfilerControl(boolean start, String path) { + if (start) { + File file = new File(path); + file.getParentFile().mkdirs(); + try { + Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); + } catch (RuntimeException e) { + Log.w(TAG, "Profiling failed on path " + path + + " -- can the process access this path?"); + } + } else { + Debug.stopMethodTracing(); + } + } + final void handleLowMemory() { ArrayList<ComponentCallbacks> callbacks = new ArrayList<ComponentCallbacks>(); diff --git a/core/java/android/app/ApplicationThreadNative.java b/core/java/android/app/ApplicationThreadNative.java index d2cf55a..bcc9302 100644 --- a/core/java/android/app/ApplicationThreadNative.java +++ b/core/java/android/app/ApplicationThreadNative.java @@ -322,6 +322,15 @@ public abstract class ApplicationThreadNative extends Binder requestPss(); return true; } + + case PROFILER_CONTROL_TRANSACTION: + { + data.enforceInterface(IApplicationThread.descriptor); + boolean start = data.readInt() != 0; + String path = data.readString(); + profilerControl(start, path); + return true; + } } return super.onTransact(code, data, reply, flags); @@ -654,5 +663,14 @@ class ApplicationThreadProxy implements IApplicationThread { data.recycle(); } + public void profilerControl(boolean start, String path) throws RemoteException { + Parcel data = Parcel.obtain(); + data.writeInterfaceToken(IApplicationThread.descriptor); + data.writeInt(start ? 1 : 0); + data.writeString(path); + mRemote.transact(PROFILER_CONTROL_TRANSACTION, data, null, + IBinder.FLAG_ONEWAY); + data.recycle(); + } } diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java index cd3701f..2ac6160 100644 --- a/core/java/android/app/IActivityManager.java +++ b/core/java/android/app/IActivityManager.java @@ -221,6 +221,10 @@ public interface IActivityManager extends IInterface { // Get device configuration public ConfigurationInfo getDeviceConfigurationInfo() throws RemoteException; + // Turn on/off profiling in a particular process. + public boolean profileControl(String process, boolean start, + String path) throws RemoteException; + /* * Private non-Binder interfaces */ @@ -365,4 +369,5 @@ public interface IActivityManager extends IInterface { int GET_RUNNING_APP_PROCESSES_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+82; int GET_DEVICE_CONFIGURATION_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+83; int PEEK_SERVICE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+84; + int PROFILE_CONTROL_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+85; } diff --git a/core/java/android/app/IApplicationThread.java b/core/java/android/app/IApplicationThread.java index 47476b5..9f3534b 100644 --- a/core/java/android/app/IApplicationThread.java +++ b/core/java/android/app/IApplicationThread.java @@ -86,6 +86,7 @@ public interface IApplicationThread extends IInterface { void scheduleLowMemory() throws RemoteException; void scheduleActivityConfigurationChanged(IBinder token) throws RemoteException; void requestPss() throws RemoteException; + void profilerControl(boolean start, String path) throws RemoteException; String descriptor = "android.app.IApplicationThread"; @@ -115,4 +116,5 @@ public interface IApplicationThread extends IInterface { int SCHEDULE_ACTIVITY_CONFIGURATION_CHANGED_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+24; int SCHEDULE_RELAUNCH_ACTIVITY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+25; int REQUEST_PSS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+26; + int PROFILER_CONTROL_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+27; } |