summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2009-09-17 10:24:05 -0700
committerDianne Hackborn <hackbod@google.com>2009-09-17 11:13:45 -0700
commit4f21c4cf077cfee5b35a56703618115614bc40f2 (patch)
tree4f3ef99f737c731521ab5f8e81fba2e18e8facba /core/java
parent7805933738de33b1961bd03553237a86d90792dd (diff)
downloadframeworks_base-4f21c4cf077cfee5b35a56703618115614bc40f2.zip
frameworks_base-4f21c4cf077cfee5b35a56703618115614bc40f2.tar.gz
frameworks_base-4f21c4cf077cfee5b35a56703618115614bc40f2.tar.bz2
Add API to retrieve memory used by running processes.
Change-Id: I9c1935c2ef3c78bd67ec4dfd811a1caaab4514c3
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/app/ActivityManager.java17
-rw-r--r--core/java/android/app/ActivityManagerNative.java14
-rw-r--r--core/java/android/app/IActivityManager.java2
-rw-r--r--core/java/android/os/Debug.java21
4 files changed, 46 insertions, 8 deletions
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index e96de07..be89ee6 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -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;
@@ -854,6 +855,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
* will be killed, all services it has running stopped, all activities
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java
index 4796e49..722c75c 100644
--- a/core/java/android/app/ActivityManagerNative.java
+++ b/core/java/android/app/ActivityManagerNative.java
@@ -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 {
diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java
index 8244645..7d9dd3a 100644
--- a/core/java/android/app/IActivityManager.java
+++ b/core/java/android/app/IActivityManager.java
@@ -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;
/*
diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java
index 5352cf6..b4f64b6 100644
--- a/core/java/android/os/Debug.java
+++ b/core/java/android/os/Debug.java
@@ -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;
}