am 3955bccd: am 4ac137ca: Merge change 25526 into eclair

Merge commit '3955bccd2d89573a065e16f3c0172f10f22fe7df'

* commit '3955bccd2d89573a065e16f3c0172f10f22fe7df':
  Add API to retrieve memory used by running processes.
This commit is contained in:
Dianne Hackborn
2009-09-17 12:27:16 -07:00
committed by Android Git Automerger
6 changed files with 98 additions and 23 deletions

View File

@@ -17563,6 +17563,19 @@
<parameter name="outInfo" type="android.app.ActivityManager.MemoryInfo">
</parameter>
</method>
<method name="getProcessMemoryInfo"
return="android.os.Debug.MemoryInfo[]"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="pids" type="int[]">
</parameter>
</method>
<method name="getProcessesInErrorState"
return="java.util.List&lt;android.app.ActivityManager.ProcessErrorStateInfo&gt;"
abstract="false"
@@ -101301,6 +101314,39 @@
visibility="public"
>
</method>
<method name="getTotalPrivateDirty"
return="int"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getTotalPss"
return="int"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="getTotalSharedDirty"
return="int"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="readFromParcel"
return="void"
abstract="false"

View File

@@ -22,6 +22,7 @@ import android.content.Intent;
import android.content.pm.ConfigurationInfo;
import android.content.pm.IPackageDataObserver;
import android.graphics.Bitmap;
import android.os.Debug;
import android.os.RemoteException;
import android.os.Handler;
import android.os.Parcel;
@@ -853,6 +854,22 @@ public class ActivityManager {
}
}
/**
* Return information about the memory usage of one or more processes.
*
* @param pids The pids of the processes whose memory usage is to be
* retrieved.
* @return Returns an array of memory information, one for each
* requested pid.
*/
public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) {
try {
return ActivityManagerNative.getDefault().getProcessMemoryInfo(pids);
} catch (RemoteException e) {
return null;
}
}
/**
* Have the system perform a force stop of everything associated with
* the given application package. All processes that share its uid

View File

@@ -1137,11 +1137,10 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
case GET_PROCESS_MEMORY_INFO_TRANSACTION: {
data.enforceInterface(IActivityManager.descriptor);
int pid = data.readInt();
Debug.MemoryInfo mi = new Debug.MemoryInfo();
getProcessMemoryInfo(pid, mi);
int[] pids = data.createIntArray();
Debug.MemoryInfo[] res = getProcessMemoryInfo(pids);
reply.writeNoException();
mi.writeToParcel(reply, 0);
reply.writeTypedArray(res, Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
return true;
}
@@ -2504,17 +2503,18 @@ class ActivityManagerProxy implements IActivityManager
reply.recycle();
}
public void getProcessMemoryInfo(int pid, Debug.MemoryInfo outInfo)
public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids)
throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeInterfaceToken(IActivityManager.descriptor);
data.writeInt(pid);
data.writeIntArray(pids);
mRemote.transact(GET_PROCESS_MEMORY_INFO_TRANSACTION, data, reply, 0);
reply.readException();
outInfo.readFromParcel(reply);
Debug.MemoryInfo[] res = reply.createTypedArray(Debug.MemoryInfo.CREATOR);
data.recycle();
reply.recycle();
return res;
}
public void killApplicationProcess(String processName, int uid) throws RemoteException {

View File

@@ -281,7 +281,7 @@ public interface IActivityManager extends IInterface {
public void closeSystemDialogs(String reason) throws RemoteException;
public void getProcessMemoryInfo(int pid, Debug.MemoryInfo outInfo)
public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids)
throws RemoteException;
/*

View File

@@ -129,6 +129,27 @@ public final class Debug
public MemoryInfo() {
}
/**
* Return total PSS memory usage in kB.
*/
public int getTotalPss() {
return dalvikPss + nativePss + otherPss;
}
/**
* Return total private dirty memory usage in kB.
*/
public int getTotalPrivateDirty() {
return dalvikPrivateDirty + nativePrivateDirty + otherPrivateDirty;
}
/**
* Return total shared dirty memory usage in kB.
*/
public int getTotalSharedDirty() {
return dalvikSharedDirty + nativeSharedDirty + otherSharedDirty;
}
public int describeContents() {
return 0;
}

View File

@@ -4921,23 +4921,14 @@ public final class ActivityManagerService extends ActivityManagerNative implemen
Binder.restoreCallingIdentity(origId);
}
public void getProcessMemoryInfo(int pid, Debug.MemoryInfo mi)
public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids)
throws RemoteException {
ProcessRecord proc;
synchronized (mPidsSelfLocked) {
proc = mPidsSelfLocked.get(pid);
Debug.MemoryInfo[] infos = new Debug.MemoryInfo[pids.length];
for (int i=pids.length-1; i>=0; i--) {
infos[i] = new Debug.MemoryInfo();
Debug.getMemoryInfo(pids[i], infos[i]);
}
if (proc == null) {
throw new RemoteException();
}
IApplicationThread thread = proc.thread;
if (thread == null) {
throw new RemoteException();
}
thread.getMemoryInfo(mi);
return infos;
}
public void killApplicationProcess(String processName, int uid) {