0

I was wondering how I could get the amount of RAM usage of a given application or a package name that is installed in the android device. I so far went on with a package manager and feeding it with the package name I want. However, there is no method that I could use to get it out. I don't know what to do after this. Please some one help me on getting the RAM amount that a particular application is using currently.

Dason
  • 60,663
  • 9
  • 131
  • 148
Imesh Chandrasiri
  • 5,558
  • 15
  • 60
  • 103

2 Answers2

0

You can use adb tools to get memory information that app consume

adb shell dumpsys meminfo

can take this output to textfile by adb shell dumpsys meminfo > meminfo.txt

Here previous good explanation of this in

How do I discover memory usage of my application in Android?

Community
  • 1
  • 1
UdayaLakmal
  • 4,035
  • 4
  • 29
  • 40
  • M sorry, bt the thing I want is not my own application memory usage. what I want is to get the memory usage of another application within my application. to be clear, m building an application to get the usage statistics all the installed applications. I came so far nd M stuck at the place where when I select a certain application and I want to show what the current memory usage of the selected app! :) – Imesh Chandrasiri Jul 08 '12 at 16:17
  • you can issue adb commands from your android application, try.. Runtime runtime = Runtime.getRuntime(); try { runtime.exec("adb shell dumpsys meminfo"); } catch (IOException e) { e.printStackTrace(); }.. then you can filter result by your required app package info. http://developer.android.com/reference/java/lang/Runtime.html#exec%28java.lang.String[],%20java.lang.String[]%29 – UdayaLakmal Jul 08 '12 at 16:26
0

this function help you :

public static void logHeap(Class<?> clazz) {
        Double allocated = new Double(Debug.getNativeHeapAllocatedSize())/new Double((1048576));        
        Double available = new Double(Debug.getNativeHeapSize()/1048576.0);
        Double free = new Double(Debug.getNativeHeapFreeSize()/1048576.0);
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);
        df.setMinimumFractionDigits(2);

        Log.d("memory-usage", "===================================================================================================");
        Log.d("memory-usage", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free) in [" + clazz.getName().replaceAll("com.myapp.android.","") + "]");
        Log.d("memory-usage", "debug.memory: allocated: " + df.format(new Double(Runtime.getRuntime().totalMemory()/1048576)) + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory()/1048576))+ "MB (" + df.format(new Double(Runtime.getRuntime().freeMemory()/1048576)) +"MB free)");

        System.gc();
        System.gc();
    }
throrin19
  • 17,796
  • 4
  • 32
  • 52