2

I am trying to calculate the memory used by a single process in android, for that i am stuck at this point.

ActivityManager am=(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
android.os.Debug.MemoryInfo[] mem=am.getProcessMemoryInfo(ProcessId);

From the above "MemoryInfo" what should i consider?

{mem.getTotalPss() or mem.getTotalPrivateDirty() or mem.getTotalSharedDirty()}

to get the amount of RAM used by the process.

Please help me with this. Thanks in advance.

Amokrane Chentir
  • 29,907
  • 37
  • 114
  • 158
srikanth
  • 239
  • 1
  • 5
  • 12

3 Answers3

4
  1. Short Answer: It's complicated and you probably don't want to do it.
  2. Long answer: see this question
Community
  • 1
  • 1
Brian O'Dell
  • 3,029
  • 1
  • 20
  • 23
1

mem.getTotalPss() gives you the total memory occupied by that process in Kb

1HaKr
  • 1,098
  • 1
  • 11
  • 18
0

Starting with marshmallow you have a few helper functions in MemoryInfo that you can query. it also can give you a list of parsed (and extra) info.

note that at least on s6 summary.graphics gives 0 always on everything. if a process is NOT a art/dalvik android process then it will simply give 0 on all the return strings. it will return them to this map though.

    int  pids[] =new int[1];
    pids[0]= pID;
    Debug.MemoryInfo [] mems1= am.getProcessMemoryInfo(pids);

    if(Build.VERSION.SDK_INT >= 23)
    if(mems1.length==1) {

        Debug.MemoryInfo meminfo=new Debug.MemoryInfo();

        Map<String, String> mems = mems1[0].getMemoryStats();

        for (Map.Entry<String, String> entry : mems.entrySet())
        {
            ret+=" k: "+entry.getKey()+":"+entry.getValue();
          //  addLineToSb(di, "m23: "+entry.getKey() + ":"+entry.getValue()+"kB");

        }


    }
Lassi Kinnunen
  • 448
  • 4
  • 10