これを使用して、プロセスによって取得されたメモリを取得しています。助けてください。インストールされている他のすべてのアプリケーションによって取得されたメモリを表示し、グラフで表示したい
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityManager activityManager = (ActivityManager) this
.getSystemService(ACTIVITY_SERVICE);
MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
Log.i("TAG", " memoryInfo.availMem " + memoryInfo.availMem + "\n");
Log.i("TAG", " memoryInfo.lowMemory " + memoryInfo.lowMemory + "\n");
Log.i("TAG", " memoryInfo.threshold " + memoryInfo.threshold + "\n");
List<RunningAppProcessInfo> runningAppProcesses = activityManager
.getRunningAppProcesses();
Map<Integer, String> pidMap = new TreeMap<Integer, String>();
for (RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) {
pidMap.put(runningAppProcessInfo.pid,
runningAppProcessInfo.processName);
}
Collection<Integer> keys = pidMap.keySet();
for (int key : keys) {
int pids[] = new int[1];
pids[0] = key;
android.os.Debug.MemoryInfo[] memoryInfoArray = activityManager
.getProcessMemoryInfo(pids);
for (android.os.Debug.MemoryInfo pidMemoryInfo : memoryInfoArray) {
Log.i("TAG", String.format("** MEMINFO in pid %d [%s] **\n",
pids[0], pidMap.get(pids[0])));
Log.i("TAG", " pidMemoryInfo.getTotalPrivateDirty(): "
+ pidMemoryInfo.getTotalPrivateDirty() + "\n");
Log.i("TAG",
" pidMemoryInfo.getTotalPss(): "
+ pidMemoryInfo.getTotalPss() + "\n");
Log.i("TAG", " pidMemoryInfo.getTotalSharedDirty(): "
+ pidMemoryInfo.getTotalSharedDirty() + "\n");
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}