Get the total amount of RAM that an Android application uses.

I want to collect some statistics from my Android phone.

When I launch my application, I want to know the following:

  • How much RAM the application uses.
  • How much free memory is on my phone.
  • How much RAM do I have on my phone?

What should I do to collect this statistics, maybe write some code or maybe you use some applications that provide such information or, possibly, something else. I use MAT, but it doesn’t help me, maybe I missed something.

The main reason I want to collect such statistics is that it can be applied, start killing other applications to free up more space, and if I can collect such information, I will understand everything.


Edited

For example, my application use library ( helper.jar ), which is 85 MB in size, I know that if the application uses .jar, it loads into the phone RAM, now, as I can see, my RAM is growing from 2 to 2 + 85 (size .jar).

If I type adb shell cat / proc / meminfo this command from ADB, I will see some memory information.

How can I do the same from JAVA code?


Best regards, ViTo Brothers.

+5
2

, , ActivityManager.getMemoryClass.

, , . . , " " .

16 ( G1) 48 . , . , 48 1 .

- logcat. -

GC_CONCURRENT freed 1109K, 12% free 10115K/11463K, paused 5ms+2ms

, 11 .

+2

this.it , .

private void getProcessInfo() {        PackageManager pm = this.getPackageManager();

    MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
        activityManager.getMemoryInfo(memoryInfo);


    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)
    {

        ModelProcessInfo item=new ModelProcessInfo();
        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(%d): " + pidMemoryInfo.getTotalPrivateDirty() + "\n");
            Log.i(TAG, " pidMemoryInfo.getTotalPss(): " + pidMemoryInfo.getTotalPss() + "\n");
           Log.i(TAG, " pidMemoryInfo.getTotalSharedDirty(): " + pidMemoryInfo.getTotalSharedDirty() + "\n");
            //pss->RAM used by your process

        }
       // activityManager.killBackgroundProcesses(pidMap.get(pids[0]));

    }

}
+1

All Articles